使用C接口访问Sybase ASE,有多种方式。见到itpub论坛上有人问起,索性做一个简单的demo。发现,使用SQL/C比Open Client接口更直观,比较适合喜欢偷懒的coder.下边介绍详细过程.
1. 数据库环境
数据库iihero, 有用户spring/spring1, 使用sa用户登录,执行如下脚本(test_proc.sql),目的是创建一个示例表及数据,并为它创建一个存储过程,给后边的程序用.
最后它有一段验证过程.结果显然是3了.
2. 看我们的程序.
就是通过嵌入式SQL访问这个存储过程test_proc,并返回结果(example.cp), 内容如下:
3. 编译和链接
Sybase ASE中的SQL/C编程,需要进行预编译,编译,链接三个步骤.
首先要从命令行里进入vc6的dos环境, 就是进入控制台窗口,运行VC98/bin下边的VCVARS32.bat文件.
确保你的LIB变量有%SYBASE%/%SYBASE_OCS%/lib这个路径.
a. 预编译: (预编译命令是cpre)
E:/MyDocument/MYBOOKS/ASE/code/esqlc>cpre -CMSVC -m -O example.c example.cp
Precompilation Successful. No Errors or Warnings found.
Statistical Report:
Program name: cpre
Options specified: /m
Input file name: example.cp
Listing file name:
Target file name: example.c
ISQL file name:
Tag ID specified:
Compiler used: MSVC
Open Client version: CS_VERSION_150
Number of information messages: 11
Number of warning messages: 0
Number of error messages: 0
Number of SQL statements parsed: 11
Number of host variables declared: 6
Number of SQL cursors declared: 0
Number of dynamic SQL statements: 0
Number of stored Procedures generated: 1
Connection(s) information:
User id:
Server:
Database:
b. 编译: (它还需要%SYBASE%/%SYBASE_OCS%/include/sybesql.c编译成obj文件)
因此使用如下命令,编译两个.c文件:
E:/MyDocument/MYBOOKS/ASE/code/esqlc>cl /DDEBUG=1 /D_DEBUG=1 /DNET_DEBUG=1 /Od /
Z7 /MD /nologo /DWIN32 -Id:/sybase/OCS-15_0/include d:/sybase/OCS-15_0/include/s
ybesql.c example.c /c
sybesql.c
example.c
Generating Code...
c. 链接:
E:/MyDocument/MYBOOKS/ASE/code/esqlc>link example.obj sybesql.obj /out:example.e
xe libsybct.lib libsybcs.lib MSVCRT.lib
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
3. 最后结果:
E:/MyDocument/MYBOOKS/ASE/code/esqlc>example.exe
Begin test!
num_t123=3
End test!
上述过程只是简单的演示一下一个简单的存储过程在SYBASE ESQL/C中的使用. 有兴趣可以一试.
至于编译器,VC6, VC7/8/9,都应该支持.
之所以使用命令行,是因为不想依赖于集成开发环境.
<script type="text/javascript"><!--
google_ad_client = "ca-pub-7104628658411459";
/* wide1 */
google_ad_slot = "8564482570";
google_ad_width = 728;
google_ad_height = 90;
//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
分享到:
相关推荐
Sybase ASE15.0.2 Linux 32bit x86版(10之9) Sybase ASE15.0.2 Linux 32bit x86版(10之9) Sybase ASE15.0.2 Linux 32bit x86版(10之9) Sybase ASE15.0.2 Linux 32bit x86版(10之9) 使用7zip解压
Sybase ASE15.0.2 Linux 32bit x86版(10之5) Sybase ASE15.0.2 Linux 32bit x86版(10之5) Sybase ASE15.0.2 Linux 32bit x86版(10之5) Sybase ASE15.0.2 Linux 32bit x86版(10之5) 使用7-zip解压
Sybase ASE15.0.2 Linux 32bit x86版(10之7) Sybase ASE15.0.2 Linux 32bit x86版(10之7) Sybase ASE15.0.2 Linux 32bit x86版(10之7) 使用7-zip打开。这是第7部分
Sybase ASE15.0.2 Linux 32bit x86版(10之3) Sybase ASE15.0.2 Linux 32bit x86版(10之3) Sybase ASE15.0.2 Linux 32bit x86版(10之3) 使用7-zip解压
Sybase ASE15.0.2 Linux 32bit x86版(10之6) Sybase ASE15.0.2 Linux 32bit x86版(10之6) Sybase ASE15.0.2 Linux 32bit x86版(10之6) 使用7-zip解压
Sybase ASE15.0.2 Linux 32bit x86版(10之8) Sybase ASE15.0.2 Linux 32bit x86版(10之8) Sybase ASE15.0.2 Linux 32bit x86版(10之8) 使用7-zip解压
Sybase ASE15.0.2 Linux 32bit x86版(10之2) Sybase ASE15.0.2 Linux 32bit x86版(10之2) Sybase ASE15.0.2 Linux 32bit x86版(10之2) 使用7-zip解压,总共10个文件包。
Sybase ASE15.0.2 Linux 32bit x86版(10之10) Sybase ASE15.0.2 Linux 32bit x86版(10之10) Sybase ASE15.0.2 Linux 32bit x86版(10之10) 使用7-zip解压得到最终的tgz文件。 下载时一定要耐心。
Sybase ASE15.0.2 Linux 32bit x86版(10之4) Sybase ASE15.0.2 Linux 32bit x86版(10之4) Sybase ASE15.0.2 Linux 32bit x86版(10之4) 使用7-zip解压
ASE15.0.2 自定义函数用法,在各种环境中使用
Sybase ASE15.0.2 Linux 32bit x86版(10之1) 总共分10部分,这是第一部分。将这10个文件放到相同目录下边,使用7-zip解压即可。最后得到的tgz文件置于linux下tar zxf ase1502_linx86_32.tgz
sybase ASE 16 ODBC for WIN10/11 32/64驱动
SybaseASE15.0 中的JAVA.pdf SybaseASE15.0 分布式事务管理.pdf SybaseASE15.0 参考手册-表.pdf SybaseASE15.0 参考手册_命令.pdf SybaseASE15.0 参考手册_构件块.pdf SybaseASE15.0 参考手册_过程.pdf SybaseASE...
Sybase ASE 12.5.4 ODBC驱动包, 4.0.x 版本 将zip解到d:\\sybasease目录下边,然后注册下边的内容: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers] ...
Sybase ASE 15.5 Transact-SQL 用户指南
Sybase ASE 参考手册,中文版全四卷:第一卷 构建块;第二卷 命令;第三卷 过程;第四卷 表格。
Sybase ASE ODBC Driver 驱动
sybase ase参考手册:配置参数.pdf
sybase ASE12.5.3补丁(3/4),SYBASE ASE 12.5.3 数据库补丁,需要在12.5.2的基础上安装,共4个压缩包,需要全部下载后解压按章
在window下安装使用Sybase ASE 12.5在window下安装使用Sybase ASE 12.5