Application of descriptor in dynamic SQL

Source: Internet
Author: User
Tags goto sprintf
Dynamic

Application of descriptor in
dynamic SQL





Wang Guanghong




The flexibility of
dynamic SQL is well known, and I am here to introduce a dynamic SQL that applies descriptor:





$short B_num;


$char *command;





$char sql[1024];


$short Flag;


$date date;


$long number, B_count, J;


$long Prec;


$long type;


$long Scale;


$double money;








sprintf (SQL, "SELECT * from table");





$prepare qid from $Sql;


if (SQLCODE) return-1;


$declare BROWSE scroll cursor for qid;


if (SQLCODE) return-2;


$allocate descriptor ' browsdesc ' with max:b_num; Allocate space in the description area and set the maximum number of items








$get Descriptor ' browsdesc ': b_count=count;//get the number of fields to query


if (SQLCODE) {


Sqlerrhandle (SQLCODE, SELECT);


Goto EXIT0;


  }





$fetch BROWSE Using SQL descriptor ' BROWSDESC ';


if (SQLCODE) {


strcpy (Retpacket.data, "select error|");


Sqlerrhandle (SQLCODE, SELECT);


Goto EXIT0;


  }





for (j=1;j<=b_count;j++) {


$get Descriptor ' browsdesc ' value $j//Current field serial number


$prec =precision,/*money, decimal*/


$scale =scale,/*money, decimal*/


$type =type;


if (SQLCODE) {


Sqlerrhandle (SQLCODE, SELECT);


Goto EXIT0;


   }


switch (type) {


Case Sqlfloat:


Case Sqlsmfloat:


Case SqlDecimal:


Case SqlMoney:


if (PREC)


sprintf (FMT, "%s%d.%df\0", "%", prec+1, scale);


Else


strcpy (FMT, "%f");


$get Descriptor ' browsdesc ' value $j


$money =data;


sprintf (result, FMT, money);





if (sqlcode==dataisnull) result[0]=0;


break;


Default:


$get Descriptor ' browsdesc ' value $j


$result =data;


}//switch





if (sqlcode==dataisnull) sqlcode=0;





if (SQLCODE) {


Sqlerrhandle (SQLCODE, SELECT);


Goto EXIT0;


   }





output (result);//Outputs





}//for








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.