版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
·Pro*C/C++基2.1编程指导方Pro*C/C++的程序设计规范。一.SQLSQLCpc(;“/*………*/”二.使用常O(ox三.定义部CEXECSQLBEGINDECLARESECTIONEXECSQLENDDECLARESECTION宿主变量:宿主变量(hostvariable)就是在嵌入式SQL语句中主语言说明的程序变SQL。每一个宿主变量都可定义一个指示器变量,主要用于处理空值(NULL)指示器变量的说明基本同一般SQL变量一样,但必须定义成2字节的整型,如SHORT、INT。在SQL语句中时,其前也应加“”(冒号),而且必须附在其相关联的宿主变量之后,在C1分隔C/C++中成对的单引号)作为单字符分隔号,双引号作为字符串的分隔号)例:EXECSQLCREATETABLE“TEMP”(COLA五.文件长六.函数原七.SQL语句长八.宿主变量SQL所在的应用程序就是宿主啦。2.1与普通的C/C++程序不同,Pro*C/C++程序需要数据库,对数据库进行查询,插入,更PCC/C++的头文件之外还要Pro*C/C++头文件,常用头文件如下:scaf(,pint(,gets)abot(,eit)srcpy(,stcmp()Sqlda.h:SQLDAOracleSQL(SQL语句只有在运行阶段sqlglm(。个函数,SQL,SQLSQLslq_errorEXECSQLWHENEVERSQLERRORDOsql_error();EXECSQLWHENEVERNOTFOUNDEXECSQLCOMMITRELEASE;示例程序:PC源文件(开发人员写的(51#include<sqlca.h>SQLCAcharusername[20],password[20],server[20]; externsqlglm(char*,int*,int*); voidconnect();voidsql();voidsql_error();voidmain(){EXECSQLWHENEVERSQLERRORDOsql_error();EXECSQLWHENEVERNOTFOUNDDOsql_error();SQLEXECSQLCOMMITRELEASE;}voidconnect(){EXECSQLCONNECT:usernameIDENTIFIEDBY:password}voidsql_error(){charsize_tbuf_len,msg_len;if(msg_len>buf_len)msg_len=buf_len;}voidintcharcname[12],cdepartment[12],coutpucolum[12],ccylinder[12] INTO:cname,:cdepartment,:ctopspeed,:choursepower,:cger,:coutpucolum,:ccylinderFROMcarTableWHERECTOPSPEED=:speed; }/*ResultSetsInterface*/#ifndefSQL_CRSR#defineSQL_CRSRstruct{unsignedint void*ptr1;void*ptr2;unsignedintmagic;typedefstructsql_cursorsql_cursor;typedefstructsql_cursor#endif/*SQL_CRSR/*ThreadSafety*/typedefvoid*sql_context;typedefvoid*/*Objectsupport*/structsqltvn{unsignedchar*tvnvsn;unsignedshorttvnvsnl;unsignedchar*tvnnm;unsignedshorttvnnml;unsignedchar*tvnsnm;unsignedshorttypedefstructsqltvnstruct{unsignedintadtvsn;unsignedshortadtmode;unsignedshortadtnum;sqltvnadttvn[1];typedefstructsqladtsstaticstructsqladtssqladt={/*BindingtoPL/SQLRecords*/structsqss{unsignedinttdsvsn;unsignedshorttdsnum;unsignedchar*tdsval[1];typedefstructsqsssqss;staticstructsqsssqs={/*Filename&PackageName*/structsqlcxp{unsignedshortcharstaticconststructsqlcxpsqlfpn{staticunsignedintsqlctx staticstructsqlexd{unsignedint unsignedint unsignedint unsignedint unsignedshortselerr;unsignedshortsqlety;unsigned constshort*cud;unsignedchar*sqlest;constchar*stmt;sqladtssqss*sqvoid**sqphsv;unsignedint void**sqpind; unsignedint unsignedint unsignedshort*sqpadto;unsignedshort*sqptdso;unsignedint unsignedint unsignedint unsignedint unsignedint unsignedint unsignedint void*sqhstv[8];unsignedint void*sqindv[8]; unsignedint unsignedint unsignedshortsqadto[8];unsignedshort}sqlstm=/*SQLLIBPrototypesexternvoidsqlcxt(void**,unsignedintstructsqlexd*,conststructsqlcxp*);externvoidsqlcx2t(void**,unsignedint*,structsqlexd*,conststructsqlcxp*);externvoidsqlbuft(void**,char*);externvoidsqlgs2t(void**,charexternvoidsqlorat(void**,unsignedint*,void/*FormsInterfacestaticconstintIAPSUCC=0;staticconstintIAPFAIL=1403;staticconstintIAPFTL=535;externvoidsqliem(unsignedchar*,signedinttypedefstruct{unsignedshortlen;unsignedchararr[1];}VARCHAR;typedefstruct{unsignedshortlen;unsignedchararr[1];}/*cud(compilationunitdata)array*/staticconstshortsqlcud0[]=#include<sqlca.h>SQLCAcharusername[20],password[20],server[20]; externsqlglm(char*,int*,int*); voidconnect();voidsql();voidsql_error();voidmain(){/*EXECSQLWHENEVERSQLERRORDOsql_error();/*EXECSQLWHENEVERNOTFOUNDDOsql_error();SQL/*EXECSQLCOMMITRELEASE;{structsqlexdsqlstm;sqlstm.sqlvsn=12;sqlstm.arrsiz=0;sqlstm.sqladtp=&sqladt;sqlstm.sqsp=&sqs;sqlstm.iters=(unsignedint)1;sqlstm.offset=(unsignedint)5;sqlstm.cud=sqlcud0;sqlstm.sqlest=(unsignedcharsqlstm.sqlety=(unsignedshort)4352;sqlstm.occurs=(unsignedint)0;sqlcxt((void**)0,&sqlctx,&sqlstm,&sqlfpn);if(sqlca.sqlcode<0)sql_error();}}voidconnect(){/*EXECSQLCONNECT:usernameIDENTIFIEDBY:passwordUSING:server;{structsqlexdsqlstm;sqlstm.sqlvsn=12;sqlstm.arrsiz=4;sqlstm.sqladtp=&sqladt;sqlstm.sqsp=&sqsqlstm.iters=(unsignedint)10;sqlstm.offset=(unsignedint)20;sqlstm.cud=sqlcud0;sqlstm.sqlest=(unsignedchar*)&sqlca;sqlstm.sqlety=(unsignedshort)4352;sqlstm.occurs=(unsignedint)0;sqlstm.sqhstv[0]=( void*)username;sqlstm.sqhstl[0]=(unsignedint)20;sqlstm.sqhsts[0]=( int)20;sqlstm.sqindv[0]= voidsqlstm.sqinds[0]=( int)0;sqlstm.sqharm[0]=(unsignedint)0;sqlstm.sqadto[0]=(unsignedshort)0;sqlstm.sqtdso[0]=(unsignedshort)0;sqlstm.sqhstv[1]=( void*)password;sqlstm.sqhstl[1]=(unsignedint)20;sqlstm.sqhsts[1]=( int)20;sqlstm.sqindv[1]= voidsqlstm.sqinds[1]=( int)0;sqlstm.sqharm[1]=(unsignedintsqlstm.sqadto[1]=(unsignedshort)0;sqlstm.sqtdso[1]=(unsignedshort)0;sqlstm.sqhstv[2]=( void*)server;sqlstm.sqhstl[2]=(unsignedint)20;sqlstm.sqhsts[2]=( int)20;sqlstm.sqindv[2]= voidsqlstm.sqinds[2]=( int)0;sqlstm.sqharm[2]=(unsignedint)0;sqlstm.sqadto[2]=(unsignedshort)0;sqlstm.sqtdso[2]=(unsignedshort)0;sqlstm.sqphsv=sqlstm.sqhstv;sqlstm.sqphsl=sqlstm.sqhstl;sqlstm.sqphss=sqlstm.sqhsts;sqlstm.sqpind=sqlstm.sqindv;sqlstm.sqpins=sqlstm.sqinds;sqlstm.sqparm=sqlstm.sqharm;sqlstm.sqparc=sqlstm.sqharc;sqlstm.sqpadto=sqlstm.sqadto;sqlstm.sqptdso=sqlstm.sqtdso;sqlstm.sqlcmax=(unsignedint)100;sqlstm.sqlcmin=(unsignedint)2;sqlstm.sqlcincr=(unsignedint)1;sqlstm.sqlctimeout=(unsignedintowait=(unsignedint)0;sqlcxt((void**)0,&sqlctx,&sqlstm,&sqlfpn);if(sqlca.sqlcode<0)sql_error();}}voidsql_error(){charmsg[200];size_tbuf_len,msg_len;if(msg_len>buf_len)msg_len=buf_len;}voidintcharcname[12],cdepartment[12],coutpucolum[12],ccylinder[12] INTO:cname,:cdepartment,:ctopspeed,:choursepower,:cger,:coutpucolum,:ccylinderFROMcarTableWHERECTOPSPEED=:speed;*/{structsqlexdsqlstm;sqlstm.sqlvsn=12;sqlstm.arrsiz=8;sqlstm.sqladtp=&sqladt;sqlstm.sqsp=&sqsqlstm.stmt="select*into:b0,:b1,:b2,:b3,:b4,:b5,:b6fromcarTablewhe\reCTOPSPEED=:b7";sqlstm.iters=(unsignedint)1;sqlstm.offset=(unsignedint)51;sqlstm.selerr=(unsignedshort)1;sqlstm.cud=sqlcud0;sqlstm.sqlest=(unsignedchar*)&sqlca;sqlstm.sqlety=(unsignedshort)4352;sqlstm.occurs=(unsignedint)0;sqlstm.sqhstv[0]=( void*)cname;sqlstm.sqhstl[0]=(unsignedint)12;sqlstm.sqhsts[0]=( int)0;sqlstm.sqindv[0]= voidsqlstm.sqinds[0]=( int)0;sqlstm.sqharm[0]=(unsignedint)0;sqlstm.sqadto[0]=(unsignedshort)0;sqlstm.sqtdso[0]=(unsignedshort)0;sqlstm.sqhstv[1]=( void*)cdepartment;sqlstm.sqhstl[1]=(unsignedint)12;sqlstm.sqhsts[1]=( int)0;sqlstm.sqindv[1]= voidsqlstm.sqinds[1]=( int)0;sqlstm.sqharm[1]=(unsignedint)0;sqlstm.sqadto[1]=(unsignedshort)0;sqlstm.sqtdso[1]=(unsignedshort)0;sqlstm.sqhstv[2]=( void*)&ctopspeed;sqlstm.sqhstl[2]=(unsignedint)sizeof(int);sqlstm.sqhsts[2]=( int)0;sqlstm.sqindv[2]= voidsqlstm.sqinds[2]=( int)0;sqlstm.sqharm[2]=(unsignedintsqlstm.sqadto[2]=(unsignedshort)0;sqlstm.sqtdso[2]=(unsignedshort)0;sqlstm.sqhstv[3]=( void*)&choursepower;sqlstm.sqhstl[3]=(unsignedint)sizeof(int);sqlstm.sqhsts[3]=( int)0;sqlstm.sqindv[3]= voidsqlstm.sqinds[3]=( int)0;sqlstm.sqharm[3]=(unsignedint)0;sqlstm.sqadto[3]=(unsignedshort)0;sqlstm.sqtdso[3]=(unsignedshort)0;sqlstm.sqhstv[4]=( void*)&cger;sqlstm.sqhstl[4]=(unsignedint)sizeof(int);sqlstm.sqhsts[4]=( int)0;sqlstm.sqindv[4]= voidsqlstm.sqinds[4]=( int)0;sqlstm.sqharm[4]=(unsignedint)0;sqlstm.sqadto[4]=(unsignedshort)0;sqlstm.sqtdso[4]=(unsignedshort)0;sqlstm.sqhstv[5]=( void*)coutpucolum;sqlstm.sqhstl[5]=(unsignedint)12;sqlstm.sqhsts[5]=( int)0;sqlstm.sqindv[5]= voidsqlstm.sqinds[5]=( int)0;sqlstm.sqharm[5]=(unsignedint)0;sqlstm.sqadto[5]=(unsignedshort)0;sqlstm.sqtdso[5]=(unsignedshort)0;sqlstm.sqhstv[6]=( void*)ccylinder;sqlstm.sqhstl[6]=(unsignedint)12;sqlstm.sqhsts[6]=( int)0;sqlstm.sqindv[6]= voidsqlstm.sqinds[6]=( int)0;sqlstm.sqharm[6]=(un
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年区域医疗服务承包协议
- 2024医药产品研发与销售代理合同
- 2024年企业知识产权管理与运用合同
- 2024员工福利外包服务合同
- 2024年度游戏委托开发与运营合同
- 2024年度新能源汽车电池制造与回收合同
- 2024城市配送车辆购置担保合同
- 2024年产定做加工协议
- 2024年品牌授权使用合同(服装业)
- (2024版)甲方因故停工乙方要求赔偿的合同范本
- 2023年中级经济师考试真题及答案
- SB/T 10895-2012鲜蛋包装与标识
- GB/T 9115-2010对焊钢制管法兰
- GB/T 2423.3-2006电工电子产品环境试验第2部分:试验方法试验Cab:恒定湿热试验
- GB/T 23221-2008烤烟栽培技术规程
- GB/T 16900-2008图形符号表示规则总则
- 城市绿地系统规划 第9章 工业绿地规划
- 辽宁省辽南协作校2022-2023学年高二上学期期末考试语文答案 Word版含解析
- 中职英语统考复习讲课教案
- 决策心理学第一讲课件
- 高中化学趣味化学知识竞赛课件
评论
0/150
提交评论