免费注册 查看新帖 |

Chinaunix

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

如何在纯c中嵌入SQL查询 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-03-31 00:40 |只看该作者 |倒序浏览
我知道可以通过 exec
来嵌入 SQL 的查询
但是不知道 对应的C的头文件是什么?
在这里向各位讨教了

论坛徽章:
0
2 [报告]
发表于 2005-03-31 01:05 |只看该作者

如何在纯c中嵌入SQL查询

See Oracle's Pro*c...I forgot it....

论坛徽章:
0
3 [报告]
发表于 2005-03-31 01:08 |只看该作者

如何在纯c中嵌入SQL查询

is  #include<oci.h>; ?

论坛徽章:
0
4 [报告]
发表于 2005-03-31 01:14 |只看该作者

如何在纯c中嵌入SQL查询

[quote]原帖由 "snowolf_37"]is  #include<oci.h>; ?[/quote 发表:


NO
Give you a Eg.

/*
* filename:model.pc
* author:K.Ro
* inc:Hitachi,Tokyo
* create time:2005.3.24
* update time:
* desc:it is a model file for write pro*c programe for oracle+tuxedo
*/
#include <stdio.h>;
#include <string.h>;
#include <stdlib.h>;
#include <sqlda.h>;
#include <sqlcpr.h>;
#include <atmi.h>;
#include <fml.h>;
#include <userlog.h>;

/* set pro*c operation */
exec sql include sqlca;
exec sql include oraca;
exec oracle option (oraca=yes);

/* Define constants for VARCHAR lengths. */
#define UNAME_LEN 20
#define PWD_LEN 40

/* Declare variables. No declare section is
needed if MODE=ORACLE. */
VARCHAR username[UNAME_LEN]; /* VARCHAR is an Oracle-supplied struct */
varchar password[PWD_LEN]; /* varchar can be in lower case also. */

/* Declare error handling function. */
void sql_error(msg)
char *msg;
{
char err_msg[128];
size_t buf_len, msg_len;

EXEC SQL WHENEVER SQLERROR CONTINUE;

printf("\n%s\n", msg);
buf_len = sizeof (err_msg);
sqlglm(err_msg, &buf_len, &msg_len);
printf("%.*s\n", msg_len, err_msg);

EXEC SQL ROLLBACK RELEASE;
exit(EXIT_FAILURE);
}

void main()
{

/* Connect to ORACLE--
* Copy the username into the VARCHAR.
*/
strncpy((char *) username.arr, "sgac_dec", UNAME_LEN);

/* Set the length component of the VARCHAR. */
username.len =
(unsigned short) strlen((char *) username.arr);

/* Copy the password. */
strncpy((char *) password.arr, "dbwork", PWD_LEN);
password.len =
(unsigned short) strlen((char *) password.arr);

/* Register sql_error() as the error handler. */
EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--\n";

/* Connect to ORACLE. Program will call sql_error()
* if an error occurs when connecting to the default database.
*/
EXEC SQL CONNECT :username IDENTIFIED BY :password;

printf("\nConnected to ORACLE as user: %s\n", username.arr);

/* Disconnect from ORACLE. */
EXEC SQL ROLLBACK WORK RELEASE;
exit(EXIT_SUCCESS);
}

论坛徽章:
0
5 [报告]
发表于 2005-03-31 09:54 |只看该作者

如何在纯c中嵌入SQL查询

原帖由 "snowolf_37" 发表:
我知道可以通过 exec
来嵌入 SQL 的查询
但是不知道 对应的C的头文件是什么?
在这里向各位讨教了


不同的数据库的头文件是不一样的

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
6 [报告]
发表于 2005-03-31 12:07 |只看该作者

如何在纯c中嵌入SQL查询

不同的数据库用到的预编译器是不一样的
嵌C的基本语法差不多是标准的(但对SQLDA的处理各不相同),但嵌C的实现各不相同,不过都要先预编译成.c(里面再调各自的函数库,实现数据库访问),再链成可执行
用什么数据库就用什么预编译工具吧!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP