我有一些使用以下构造的遗留Pro*C代码
这种模式可以在在线论坛上找到,但在Oracle文档中却找不到
特别是,谷歌在甲骨文网站上找不到任何关于"sqhsts"的文档。
这种模式有记录吗
它被认为是一种良好的编程实践吗?
/* cud (compilation unit data) array */
static const short sqlcud0[] =
{10,4130,832,0,0,
5,0,0,1,0,0,27,23,0,0,4,4,0,1,0,1,97,0,0,1,97,0,0,1,97,0,0,1,10,0,0,
36,0,0,2,30,0,4,25,0,0,1,0,0,1,0,2,97,0,0,
};
/* EXEC SQL CONNECT :user IDENTIFIED BY :pwd USING :url; */
{
struct sqlexd sqlstm;
sqlstm.sqlvsn = 10;
sqlstm.arrsiz = 4;
sqlstm.sqladtp = &sqladt;
sqlstm.sqltdsp = &sqltds;
sqlstm.iters = (unsigned int )10;
sqlstm.offset = (unsigned int )5;
sqlstm.cud = sqlcud0;
sqlstm.sqlest = (unsigned char *)&sqlca;
sqlstm.sqlety = (unsigned short)256;
sqlstm.occurs = (unsigned int )0;
sqlstm.sqhstv[0] = ( void *)user;
sqlstm.sqhstl[0] = (unsigned int )0;
sqlstm.sqhsts[0] = ( int )0;
sqlstm.sqindv[0] = ( void *)0;
sqlstm.sqinds[0] = ( int )0;
sqlstm.sqharm[0] = (unsigned int )0;
sqlstm.sqadto[0] = (unsigned short )0;
sqlstm.sqtdso[0] = (unsigned short )0;
sqlstm.sqhstv[1] = ( void *)pwd;
sqlstm.sqhstl[1] = (unsigned int )0;
sqlstm.sqhsts[1] = ( int )0;
sqlstm.sqindv[1] = ( void *)0;
sqlstm.sqinds[1] = ( int )0;
sqlstm.sqharm[1] = (unsigned int )0;
sqlstm.sqadto[1] = (unsigned short )0;
sqlstm.sqtdso[1] = (unsigned short )0;
sqlstm.sqhstv[2] = ( void *)url;
(代码从这里复制,但与我的类似)
Pro*C通过等语句创建低级C
EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL END DECLARE SECTION;
它为您声明的每个数据项创建类似OCI的描述符。使用这些绑定变量嵌入sql的其他语句(EXEC SQL ...;
)然后使用声明部分中的编码转换为一系列较低级别的调用。Pro*C已经过时了。25年前,我参与了Pro*C的第一个测试版。。。不推荐使用。
当由启用了警告的现代编译器编译时,Pro*C预编译生成的代码并不总是完美的。它也不意味着可读性。如果你想学习OCI编程,你可以了解正在发生的事情。也不建议你这样做,除非你想做一些特殊的任务。
任务示例:OCI用于为Oracle创建外部C/C++库。它几乎可以让你在细粒度上处理你想在oracle中做的任何事情。从这里开始:
http://www.oracle.com/technetwork/database/features/oci/index.html