"FROM PIOPLE");
selstr.len=::strlen(selstr.s);
EXEC SQL PREPARE SENTENCE2 FROM :selstr;
if (sqlca.sqlcode != 0)
{
::printf("ERROR - SQL code returned non-zero for "
"prepare SENTENCE2, received %d\n",sqlca.sqlcode);
return;
}
EXEC SQL DECLARE CUR1 CURSOR
FOR SENTENCE2;
if (sqlca.sqlcode != 0)
{
::printf("ERROR - SQL code returned non-zero for "
"declare cursor CUR1, received %d\n",sqlca.sqlcode);
return;
}
EXEC SQL OPEN CUR1;
EXEC SQL WHENEVER NOT FOUND GO TO CLOSE_CUR1;
if (sqlca.sqlcode != 0)
{
::printf("ERROR - SQL code returned non-zero for "
"open CUR1, received %d\n",sqlca.sqlcode);
return;
}
::printf("\nFirstname Lastname Address "
"Phone Datetime Salary Ident");
::printf("\n========= =========== ============ "
"======= ====================== ====== =====\n");
while(1)
{
EXEC SQL FETCH CUR1
INTO
:firstname,:lastname,:address,:phone,:datetime,:salary,:identifier;
if (sqlca.sqlcode != 0)
{
::printf("ERROR - SQL code returned non-zero for "
"fetch CUR1, received %d\n",sqlca.sqlcode);
return;
}
::printf("%-9s %-11s %-12s %-7s %-22s %-6d %-5d\n"
"",firstname,lastname,address,phone,datetime,salary,identifier);
}
EXEC SQL WHENEVER NOT FOUND CONTINUE;
CLOSE_CUR1:
EXEC SQL CLOSE CUR1;
if (sqlca.sqlcode != 0)
{
::printf("ERROR - SQL code returned non-zero for "
"close CUR1, received %d\n",sqlca.sqlcode);
return;
}
}
void WORK::print_column(void)
{int i;
EXEC SQL BEGIN DECLARE SECTION;
struct {short len;
char s??(100??);
}whestr;
char result??(13??);
EXEC SQL END DECLARE SECTION;
::printf("\nPrint?\n1.Firstname\n2.Lastname\n3.Address\n");
::gets(s); i=::atoi(s);
switch (i)
{case 1: {::printf("\nFirstname\n=========\n");
::strcpy(whestr.s,"SELECT FIRSTNAME FROM PIOPLE "
"WHERE SALARY > 1000");break;
}
case 2: {::printf("\nLastname\n===========\n");
::strcpy(whestr.s,"SELECT LASTNAME FROM PIOPLE "
"WHERE SALARY > 1000");break;
}
case 3: {::printf("\nAddress\n============\n");
::strcpy(whestr.s,"SELECT ADDRESS FROM PIOPLE "
"WHERE SALARY > 1000");break;
}
default: return;
}
whestr.len=::strlen(whestr.s);
EXEC SQL PREPARE SENTENCE3 FROM :whestr;
if (sqlca.sqlcode != 0)
{
::printf("ERROR - SQL code returned non-zero for "
"prepare SENTENCE3, received %d\n",sqlca.sqlcode);
return;
}
EXEC SQL DECLARE CUR2 CURSOR
FOR SENTENCE3 ;
if (sqlca.sqlcode != 0)
{
::printf("ERROR - SQL code returned non-zero for "
"declare cursor CUR2, received %d\n",sqlca.sqlcode);
return;
}
EXEC SQL OPEN CUR2;
EXEC SQL WHENEVER NOT FOUND GO TO CLOSE_CUR2;
if (sqlca.sqlcode != 0)
{
::printf("ERROR - SQL code returned non-zero for "
"open CUR2, received %d\n",sqlca.sqlcode);
return;
}
while(1)
{
EXEC SQL FETCH CUR2 INTO :result;
if (sqlca.sqlcode != 0)
{
::printf("ERROR - SQL code returned non-zero for "
"fetch CUR2, received %d\n",sqlca.sqlcode);
return;
}
::printf("%-12s\n",result);
}
EXEC SQL WHENEVER NOT FOUND CONTINUE;
CLOSE_CUR2:
EXEC SQL CLOSE CUR2;
if (sqlca.sqlcode != 0)
{
::printf("ERROR - SQL code returned non-zero for "
"close CUR2, received %d\n",sqlca.sqlcode);
return;
}
}
WORK::~WORK()
{
EXEC SQL DROP TABLE PIOPLE;
if (sqlca.sqlcode != 0)
{
::printf("ERROR - SQL code returned non-zero for "
"drop of PIOPLE received %d??\n",sqlca.sqlcode);
::exit(-1);
}
EXEC SQL COMMIT;
}
int main(void)
{
WORK a;
for(int i;;)
{printf("\n\n1: add\n");
printf("2: print\n");
printf("3: print column with salary > 1000\n");
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.