+ -
当前位置:首页 → 问答吧 → DB2 嵌入SQL 编译问题

DB2 嵌入SQL 编译问题

时间:2010-08-10

来源:互联网

连接PAYMENTS数据库,查询用户为DOLORES的薪水是多少
程序如下:
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include "util.h"
  5. #include<sqlca.h>
  6. EXEC SQL INCLUDE SQLCA;
  7. main()
  8. {
  9.   EXEC SQL BEGIN DECLARE SECTION;
  10.   float salary;
  11.   EXEC SQL END DECLARE SECTION;
  12.   EXEC SQL CONNECT TO PAYMENTS;
  13.   EXEC SQL SELECT SALARY INTO :salary
  14.      FROM employee
  15.      WHERE name='DOLORES';
  16.   printf("salary=%f\n",salary);
  17. EXEC SQL CONNECT RESET;
  18. return 0;
  19. }
复制代码
预编译出错:
              db2 prep employee.sqc bindfile

LINE    MESSAGES FOR employee.sqc
------  --------------------------------------------------------------------
        SQL0060W  The "C" precompiler is in progress.
        SQL1024N  A database connection does not exist.   //怎么会没有连接PAYMENTS数据库呢?
                  SQLSTATE=08003
        SQL0095N  No bind file was created because of previous
                  errors.
        SQL0091W  Precompilation or binding was ended with "2"
                  errors and "0" warnings.

作者: addictlinux   发布时间: 2010-08-10

需要先执行下
db2 connect to PAYMENTS
然后在预编译、编译……

作者: logicBaby   发布时间: 2010-08-10

step1: db2 connect to PAYMENTS

step2: db2 prep employee.sqc bindfile  (employee.bnd  employee.c)

step3: db2 bind employee.bnd

step4: gcc employee.c -L$HOME/sqllib/lib -ldb2 -o employee ( runs error)

the error message :
  employee.c:20:21: error: sqladef.h: No such file or directory
employee.c:22: error: variable ‘sqla_rtinfo’ has initializer but incomplete type
employee.c:23: error: extra brace group at end of initializer
employee.c:23: error: (near initialization for ‘sqla_rtinfo’)
employee.c:23: warning: excess elements in struct initializer
employee.c:23: warning: (near initialization for ‘sqla_rtinfo’)
employee.c:23: error: ‘wchar_t’ undeclared here (not in a function)
employee.c:23: warning: excess elements in struct initializer
employee.c:23: warning: (near initialization for ‘sqla_rtinfo’)
employee.c:23: warning: excess elements in struct initializer
employee.c:23: warning: (near initialization for ‘sqla_rtinfo’)
employee.c:23: error: extra brace group at end of initializer
employee.c:23: error: (near initialization for ‘sqla_rtinfo’)
employee.c:23: warning: excess elements in struct initializer
employee.c:23: warning: (near initialization for ‘sqla_rtinfo’)
employee.c:26: error: ‘SQL_IS_LITERAL’ undeclared here (not in a function)
employee.c:27: error: ‘SQL_IS_INPUT_HVAR’ undeclared here (not in a function)
employee.sqc:4:18: error: util.h: No such file or directory
employee.sqc:5:18: error: sqlca.h: No such file or directory
employee.sqc: In function ‘main’:
employee.sqc:14: error: array type has incomplete element type
employee.sqc:17: error: array type has incomplete element type

作者: addictlinux   发布时间: 2010-08-10

ls -l  /home/db2inst1/sqllib/include/
-r--r--r-- 1 bin bin 5695 Nov 16  2009 asn.h

just only file asn.h  !!!
NO OTHER FILES

my DB2 DATABASE : DB2-Express-C9.7.1

作者: addictlinux   发布时间: 2010-08-10

# $DB2DIR的include目录下为何只有一个asn.h

原因是在安装db2的时候,可能选用了typical模式,则不会安装这些头文件。使用custom 模式,并在select features to install中选中SDK

作者: addictlinux   发布时间: 2010-08-10