Dynamic SQL Application

zhaozj2021-02-16  35

Dynamic SQL Application

Wang Guanghong

The flexibility of dynamic SQL is well known, and I will introduce a dynamic SQL for application Descriptor:

$ short b_num; $ char * command;

$ Char SQL [1024]; $ 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; // In description area allocation space, And set the maximum number of items

$ get descriptor 'browsdesdesc': b_count = count; // Get the query field number if (sqlcode) {sqlerrhandle (sqlcode, select); goto exit0;}

$ fetch browse using sql descriptor 'browsdesc'; if (sqlcode) {structure (RetPacket.Data, "SELECT Error |"); sqlerrhandle (Sqlcode, SELECT); goto exit0;}

For (j = 1; j <= b_count; j ) {$ get descriptor 'browsdesd' value $ j // Current Field number $ prec = precision, / * Money, Decimal * / $ scale = scale, / * Money, Decimal * / $ Type = type; if (sqlcode) {SQLERRHANDLE (SQLCODE, SELECT); goto exit0;} switch (type) {copy sqlflofloat: 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); // output result} // for

转载请注明原文地址:https://www.9cbs.com/read-24419.html

New Post(0)