Database proc Programming VI

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.