`
iihero
  • 浏览: 262376 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Sybase ASE15.0.2中使用嵌入式SQL/C编程

阅读更多

使用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,都应该支持.

之所以使用命令行,是因为不想依赖于集成开发环境.

分享到:
评论

相关推荐

    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) 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) Sybase ASE15.0.2 Linux 32bit x86版(10之5) 使用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) Sybase ASE15.0.2 Linux 32bit x86版(10之2) 使用7-zip解压,总共10个文件包。

    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) 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) 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) 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) Sybase ASE15.0.2 Linux 32bit x86版(10之8) 使用7-zip解压

    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) 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) Sybase ASE15.0.2 Linux 32bit x86版(10之4) 使用7-zip解压

    Sybase ASE15.0.2 Linux 32bit x86版(10之1)

    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驱动

    - 数据库开发:开发人员可以使用支持ODBC的任何编程语言(如C++、VB.NET、Python等)来编写应用程序,直接访问Sybase ASE 16数据库。 - 报表工具:BI工具如Tableau、Excel等可通过ODBC连接到ASE 16,进行数据提取、...

    Sybase ASE 15.0简体中文技术参考手册.7z

    SybaseASE15.0 中的JAVA.pdf SybaseASE15.0 分布式事务管理.pdf SybaseASE15.0 参考手册-表.pdf SybaseASE15.0 参考手册_命令.pdf SybaseASE15.0 参考手册_构件块.pdf SybaseASE15.0 参考手册_过程.pdf SybaseASE...

    Sybase ASE ODBC Driver 下载

    Sybase ASE ODBC驱动程序是基于Windows平台的,它为各种编程语言(如C++、VB、Python等)提供了一个统一的接口,使得开发人员可以轻松地访问和操作Sybase ASE数据库。该驱动程序支持SQL语句执行、事务处理、结果集...

    Sybase ASE参考手册(中文版,全4卷)

    这本中文版的Sybase ASE参考手册包含了全面的技术信息,旨在帮助用户深入理解和有效地使用这个强大的数据库系统。 **第一卷:构建块** 这一卷主要介绍了Sybase ASE的基础架构和核心组成部分,包括: 1. **数据...

    Sybase ASE 15.5 Transact-SQL 用户指南(中文)

    - **版本信息**:文档为Sybase ASE 15.5版本的Transact-SQL用户指南,文档ID为DC32970-01-1550-01,最后修订日期为2009年11月,版权归属Sybase, Inc.。 - **适用范围**:适用于Sybase ASE 15.5及后续版本,除非有...

    Sybase ASE 12.5.4 ODBC驱动包

    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 for linux 12.5安装

    Sybase ASE for Linux 12.5 安装指南 本文档旨在指导用户如何在 RedHat AS 5 上安装 Sybase ASE for Linux 12.5。 installation process covers the creation of a Sybase directory, setting up the user and ...

    Sybase ASE12.5附带的Sybase Central完整免安装版

    **Sybase ASE12.5** 是Sybase公司推出的一款高度可扩展的企业级数据库管理系统,全称为Adaptive Server Enterprise。这个版本在1990年代末期发布,它以其高效性能、高可用性和数据安全性而受到业界的认可。ASE12.5在...

Global site tag (gtag.js) - Google Analytics