免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4961 | 回复: 4
打印 上一主题 下一主题

DB2 嵌入SQL 编译问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-08-10 17:42 |只看该作者 |倒序浏览
连接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.

论坛徽章:
0
2 [报告]
发表于 2010-08-10 22:16 |只看该作者
需要先执行下
db2 connect to PAYMENTS
然后在预编译、编译……

论坛徽章:
0
3 [报告]
发表于 2010-08-10 22:41 |只看该作者
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

论坛徽章:
0
4 [报告]
发表于 2010-08-10 23:05 |只看该作者
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

论坛徽章:
0
5 [报告]
发表于 2010-08-10 23:24 |只看该作者
# $DB2DIR的include目录下为何只有一个asn.h

原因是在安装db2的时候,可能选用了typical模式,则不会安装这些头文件。使用custom 模式,并在select features to install中选中SDK
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP