#define_crt_secure_no_warnings#include<stdio.h>#include<stdlib.h>#include<string.h>#include"sqlca.h"//indicator variable: Used to describe the host variable//indicator variable as input: value 1, indicating that the host variable is null//indicates that the variable does output: value 1, which indicates that the returned variable is null//syntax Format: host variable [indicator] indicates variable where indicator keyword can be added without//eg::name1 Indicator:name_indEXEC SQL BEGIN DECLARE section; Char*serverid="Scott/[email protected]"; intida1[Ten]; intidb1[Ten]; varchar name1[Ten][ -]; Shortname_ind[Ten];//defines the indicator variable, which must be a short host typeEXEC SQL END DECLARE section;//error handling Upgrade functionvoidSqlerr () {intret=0; Charstn[ -]; //the actual length of the Sqlfc:sql statementsize_t sqlfc,stmlen= -; EXEC SQL whenever SQLERROR CONTINUE; RET=sqlgls (stn,&stmlen,&SQLFC); if(ret!=0) {printf ("Sqlgls () failed! Err Code:%d\r\n", ret); return ; } printf ("The SQL statement that was faulted is:%.*s\r\n", STMLEN,STN); printf ("Err reason:%.*s\r\n", SQLCA.SQLERRM.SQLERRML,SQLCA.SQLERRM.SQLERRMC); EXEC SQL ROLLBACK work RELEASE;}voidMain () {EXEC SQL whenever SQLERROR do Sqlerr (); EXEC SQL Connect:serverid; printf ("Connect ok!\r\n"); EXEC SQL whenever not FOUND CONTINUE; EXEC SQLSelectIda,idb,name Into:ida1,:idb1,:name1:name_ind fromT2; //Sqlca.sqlerrd[2] Gets the number of records queried by the SQL statement intcount=sqlca.sqlerrd[2]; //Terminal Print Data intI=0; for(i=0; i<count;i++) { if(name_ind[i]==-1) {printf ("Article %d: ida1=%d,idb1=%d,name1=%s\r\n", I,ida1[i],idb1[i],"Null value"); }Else{printf ("Article %d: ida1=%d,idb1=%d,name1=%s\r\n", I,ida1[i],idb1[i],name1[i].arr); } } //Submit DisconnectEXEC SQL COMMIT RELEASE; System ("Pause");}
Database proc Programming VI