printf("OTHER NUMBER: exit\n? ");
gets(s);i=atoi(s);
switch (i)
{
case 1:
{
a.add();
break;
}
case 2:
{
a.print();
break;
}
case 3:
{
a.print_column();
break;
}
default: return(0);
}
}
}
/********************************************************************/
/* S006 */
/* Пример использования динамического SQL для выполнения Varying-List */
/* SELECT запроса с помощью SQL Descriptor Area (SQLDA) */
/* Только для типов: date, time, timestamp, fixed-length, */
/* character string, large integer, small integer */
/********************************************************************/
#include <stdlib.h>
#include <stdio.h>
EXEC SQL INCLUDE SQLCA;
EXEC SQL INCLUDE SQLDA;
int main(void)
{
EXEC SQL BEGIN DECLARE SECTION;
struct sqlda testda,*fulda;
struct {short len;
char s??(40??);
}statement;
EXEC SQL END DECLARE SECTION;
char s??(30??),s1??(30??);
int i,j,l;
printf("\n\nWhich table would you like to display?\n");
gets(s);
strcpy(statement.s,"SELECT * FROM ");
strcat(statement.s,s);
statement.len=strlen(statement.s);
printf("\n");
EXEC SQL PREPARE STATEMENT FROM :statement;
if (sqlca.sqlcode != 0)
{
printf("ERROR - SQL code returned non-zero for "
"prepare STATEMENT, received %d\n",sqlca.sqlcode);
return(-1);
}
testda.sqln=0;
EXEC SQL DESCRIBE STATEMENT INTO :testda;
if (sqlca.sqlcode != 0)
{
printf("ERROR - SQL code returned non-zero for "
"describe STATEMENT, received %d\n",sqlca.sqlcode);
return(-1);
}
fulda=(struct sqlda*)malloc(SQLDASIZE(testda.sqld));
fulda->sqln=testda.sqld;
EXEC SQL DESCRIBE STATEMENT INTO :*fulda;
if (sqlca.sqlcode != 0)
{
printf("ERROR - SQL code returned non-zero for "
"describe STATEMENT, received %d\n",sqlca.sqlcode);
return(-1);
}
for(i=0;i<fulda->sqld;i++)
{
for(j=0;j<fulda->sqlvar??(i??).sqlname.length;j++)
printf("%c",fulda->sqlvar??(i??).sqlname.data??(j??));
if(fulda->sqlvar??(i??).sqllen>fulda->sqlvar??(i??).sqlname.length)
for(j=0;j<fulda->sqlvar??(i??).sqllenfulda->sqlvar??(i??).sqlname.length;j++)printf(" ");
printf(" ");
}
printf("\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++)printf("=");
printf(" ");
}
printf("\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)
{
printf("ERROR - SQL code returned non-zero for "
"declare CUR1, received %d\n",sqlca.sqlcode);
return(-1);
}
EXEC SQL OPEN CUR1;
if (sqlca.sqlcode != 0)
{
printf("ERROR - SQL code returned non-zero for "
"open CUR1, received %d\n",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)
{
printf("ERROR - SQL code returned non-zero for "
"fetch CUR1, received %d\n",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;
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.