{
::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::update(void)
{int i;
EXEC SQL DECLARE CUR2 CURSOR
FOR SELECT
FIRSTNAME,LASTNAME,ADDRESS,PHONE,DATETIME,SALARY,IDENTIFIER
FROM PIOPLE
FOR UPDATE OF ADDRESS,DATETIME,SALARY;
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
:firstname,:lastname,:address,:phone,:datetime,:salary,:identifier;
if (sqlca.sqlcode != 0)
{
::printf("ERROR - SQL code returned non-zero for "
"fetch CUR2, received %d\n",sqlca.sqlcode);
return;
}
::printf("\nFirstname Lastname Address "
"Phone Datetime Salary Ident");
::printf("\n========= =========== ============ "
"======= ====================== ====== =====\n");
::printf("%-9s %-11s %-12s %-7s %-22s %-6d %-5d\n"
"",firstname,lastname,address,phone,datetime,salary,identifier);
::printf("\n\nUpdate for:");
::printf("\n1. Address\n2. Datetime\n3. Salary\n? ");
::gets(s); i=::atoi(s);
switch (i)
{case 1: ::printf("Address? "); ::gets(address);break;
case 2: ::printf("Datetime? "); ::gets(datetime);break;
case 3: ::printf("Salary? "); ::gets(s);salary=::atoi(s);break;
}
EXEC SQL UPDATE PIOPLE
SET ADDRESS = :address,DATETIME = :datetime,SALARY = :salary
WHERE CURRENT OF CUR2;
if (sqlca.sqlcode != 0)
{
::printf("ERROR - SQL code returned non-zero for "
"update where current of CUR2, received %d\n",sqlca.sqlcode);
return;
}
}
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: update\n");
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.update();
break;
}
default: return(0);
}
}
}
/*****************************************************/
/* S004 */
/* Пример использования функции столбца */
/*****************************************************/
#include <stdlib.h>
#include <stdio.h>
EXEC SQL INCLUDE SQLCA;
char s??(30??);
class WORK
{
private:
EXEC SQL BEGIN DECLARE SECTION;
char firstname??(10??);
char lastname??(12??);
char address??(13??);
char phone??(8??);
char datetime??(23??);
long int salary;
short int identifier;
EXEC SQL END DECLARE SECTION;
public:
WORK();
~WORK();
void print(void);
void add(void);
void AVG_salary(void);
};
WORK::WORK()
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.