/*********************************************************************/
#pragma runopts(plist(os))
#include <stdlib.h>
#include <stdio.h>
EXEC SQL INCLUDE SQLCA;
EXEC SQL INCLUDE SQLDA;
int main(int argc,char *argv??(??))
{
EXEC SQL BEGIN DECLARE SECTION;
struct sqlda testda,*fulda;
struct {short len;
char s??(120??);
}statement;
EXEC SQL END DECLARE SECTION;
char s??(40??),s1??(40??),result??(240??);
int i,j,l;
strcpy(result,"\0");
*(int *) argv??(3??) = 0;
if(argc==5)
{
strcpy(statement.s,argv??(1??));
statement.len=strlen(statement.s);
strcpy(result,"\n");
EXEC SQL PREPARE STATEMENT FROM :statement;
if (sqlca.sqlcode != 0)
{
sprintf(argv??(2??),"ERROR - SQL code returned non-zero for "
"prepare STATEMENT, received %d\n",sqlca.sqlcode);
*(int *) argv??(3??) = sqlca.sqlcode;
return(-1);
}
testda.sqln=0;
EXEC SQL DESCRIBE STATEMENT INTO :testda;
if (sqlca.sqlcode != 0)
{
sprintf(argv??(2??),"ERROR - SQL code returned non-zero for "
"describe STATEMENT, received %d\n",sqlca.sqlcode);
*(int *) argv??(3??) = sqlca.sqlcode;
return(-1);
}
*(int *) argv??(4??) = testda.sqld;
if(testda.sqld>0)
{
fulda=(struct sqlda*)malloc(SQLDASIZE(testda.sqld));
fulda->sqln=testda.sqld;
EXEC SQL DESCRIBE STATEMENT INTO :*fulda;
if (sqlca.sqlcode != 0)
{
sprintf(argv??(2??),"ERROR - SQL code returned non-zero for "
"describe STATEMENT, received %d\n",sqlca.sqlcode);
*(int *) argv??(3??) = sqlca.sqlcode;
return(-1);
}
for(i=0;i<fulda->sqld;i++)
{
for(j=0;j<fulda->sqlvar??(i??).sqlname.length;j++)
{
sprintf(s,"%c",fulda->sqlvar??(i??).sqlname.data??(j??));
strcat(result,s);
}
if(fulda->sqlvar??(i??).sqllen>fulda->sqlvar??(i??).sqlname.length)
for(j=0;j<fulda->sqlvar??(i??).sqllenfulda->sqlvar??(i??).sqlname.length;j++)strcat(result," ");
strcat(result," ");
}
strcat(result,"\n");
for(i=0;i<fulda->sqld;i++)
{
if(fulda->sqlvar??(i??).sqllen>fulda->sqlvar??(i??).sqlname.length)
l=fulda->sqlvar??(i??).sqllen;
else l=fulda->sqlvar??(i??).sqlname.length;
for(j=0;j<l;j++)strcat(result,"=");
strcat(result," ");
}
strcat(result,"\n");
for(i=0;i<fulda->sqld;i++)
{
fulda->sqlvar??(i??).sqldata=
(unsigned char*)malloc(fulda->sqlvar??(i??).sqllen+1);
fulda->sqlvar??(i??).sqlind=(short*)malloc(sizeof(short));
}
EXEC SQL DECLARE CUR1 CURSOR FOR STATEMENT;
if (sqlca.sqlcode != 0)
{
sprintf(argv??(2??),"ERROR - SQL code returned non-zero for "
"declare CUR1, received %d\n",sqlca.sqlcode);
*(int *) argv??(3??) = sqlca.sqlcode;
return(-1);
}
EXEC SQL OPEN CUR1;
if (sqlca.sqlcode != 0)
{
sprintf(argv??(2??),"ERROR - SQL code returned non-zero for "
"open CUR1, received %d\n",sqlca.sqlcode);
*(int *) argv??(3??) = sqlca.sqlcode;
return(-1);
}
EXEC SQL WHENEVER NOT FOUND GO TO CLOSE_CUR1;
while(1)
{
EXEC SQL FETCH CUR1 USING DESCRIPTOR :*fulda;
if (sqlca.sqlcode != 0)
{
sprintf(argv??(2??),"ERROR - SQL code returned non-zero for "
"fetch CUR1, received %d\n",sqlca.sqlcode);
*(int *) argv??(3??) = sqlca.sqlcode;
return(-1);
}
for(i=0;i<fulda->sqld;i++)
{
if(fulda->sqlvar??(i??).sqllen>fulda->sqlvar??(i??).sqlname.length)
l=fulda->sqlvar??(i??).sqllen;
else l=fulda->sqlvar??(i??).sqlname.length;
strcpy(s,"%-");sprintf(s1,"%d",l);strcat(s,s1);
switch (fulda->sqlvar??(i??).sqltype)
{
case 384:
case 388:
case 392:
case 452:
{
strcat(s,"s ");
sprintf(s1,s,fulda->sqlvar??(i??).sqldata);
strcat(result,s1);
break;
}
case 385:
case 389:
case 393:
case 453:
{
if(*fulda->sqlvar??(i??).sqlind<0)
{
for(j=0;j<l;j++)strcat(result,"_");
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.