gpt4 book ai didi

sql 包不执行 printf

转载 作者:行者123 更新时间:2023-11-30 17:49:53 25 4
gpt4 key购买 nike

我有以下代码。当我执行 db2 prep file1 时它工作正常但它最后并没有打印出再见当我尝试使用 C 编译器将其作为 ./file1 运行时,它无法识别 EXEC我在 db2 上执行此操作

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sqlutil.h>
#include <sqlenv.h>
#include <sql.h>
#include <sqlcodes.h>


EXEC SQL INCLUDE SQLCA;

EXEC SQL BEGIN DECLARE SECTION;
short sage;
short sid;
char sname[16];
EXEC SQL END DECLARE SECTION ;

#define CHECK_SQL( code, text_string, eExit)
{
if( rc ==0)
printf("rc was 0\n");
if(sqlca.sqlcode != 0)
printf("just checked sqlca.sqlcode %s \n", sqlca.sqlcode);
if(sqlca.sqlcode ==0)
printf("well sqlcode is 0\n");
}


int main(int argc, char *argv[])
{
if (argc>1)
printf("we have an input\n");
else {
printf("please print something\n");
exit(0);
}

EXEC SQL CONNECT TO NAME;
CHECK_SQL(0, "Connect failed", EXIT);

printf("bye\n");
}

我知道,当我执行 db2 prep 文件时,它会创建一个 file.C,然后我需要单独编译该文件。但其中有很多链接错误。我检查了 db2 网站,它说我需要在包含的文件之间创建一个 dll。请帮忙。

最佳答案

为 DB2 开发嵌入式 SQL 应用程序的正确顺序是:

  • 预处理(您提到的准备)。这会将嵌入式 SQL 转换为 CLI 调用。之后您将拥有两个文件:一个 C 源文件和一个绑定(bind) (.bnd) 文件。
  • 照常编译并链接 C 源代码。显然,与其他 C 程序一样,您将需要所有依赖的头文件和库。这将创建一个可执行文件。
  • 将包(.bnd 文件)绑定(bind)到数据库。
  • 运行可执行文件。

如果您花时间阅读我向您推荐的手​​册 in your other question,您就会知道这一切。 。

关于sql 包不执行 printf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17599911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com