"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("OTHER NUMBER: exit\n? ");
gets(s);i=atoi(s);
switch (i)
{
case 1:
{
a.add();
break;
}
case 2:
{
a.print();
break;
}
default: return(0);
}
}
}
/*********************************************************/
/* S003 */
/* Пример использования оператора UPDATE для изменения */
/* строки в позиции курсора */
/*********************************************************/
#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 update(void);
};
WORK::WORK()
{
EXEC SQL CREATE TABLE PIOPLE
(FIRSTNAME VARCHAR(9) NOT NULL,
LASTNAME CHAR(11) NOT NULL,
ADDRESS VARCHAR(12) NOT NULL,
PHONE CHAR(7) NOT NULL UNIQUE,
DATETIME TIMESTAMP DEFAULT,
SALARY INTEGER NOT NULL,
IDENTIFIER SMALLINT NOT NULL,
CONSTRAINT CHECK_PHONE
CHECK(PHONE BETWEEN '210____' AND '299____'));
if (sqlca.sqlcode != 0)
{
::printf("ERROR - SQL code returned non-zero for "
"creation of PIOPLE, received %d\n",sqlca.sqlcode);
::exit(-1);
}
EXEC SQL CREATE UNIQUE INDEX PHONEX
ON PIOPLE(PHONE);
if (sqlca.sqlcode != 0)
{
::printf("ERROR - SQL code returned non-zero for "
"create unique index, received %d\n",sqlca.sqlcode);
::exit(-1);
}
EXEC SQL ALTER TABLE PIOPLE
PRIMARY KEY(PHONE);
if (sqlca.sqlcode != 0)
{
::printf("ERROR - SQL code returned non-zero for "
"alter table PIOPLE, received %d\n",sqlca.sqlcode);
::exit(-1);
}
}
void WORK::add(void)
{
::printf("\nFirstname? "); ::gets(firstname);
::printf("Lastname? "); ::gets(lastname);
::printf("Address? "); ::gets(address);
::printf("Phone? "); ::gets(phone);
::printf("Salary? "); ::gets(s); salary=::atoi(s);
::printf("Identifier? "); ::gets(s); identifier=::atoi(s);
EXEC SQL INSERT INTO PIOPLE
(FIRSTNAME,LASTNAME,ADDRESS,PHONE,SALARY,IDENTIFIER)
VALUES
(:firstname,:lastname,:address,:phone,:salary,:identifier);
if (sqlca.sqlcode != 0)
{
::printf("ERROR - SQL code returned non-zero for "
"insert into PIOPLE, received %d\n",sqlca.sqlcode);
return;
}
}
void WORK::print(void)
{
EXEC SQL DECLARE CUR1 CURSOR
FOR SELECT
FIRSTNAME,LASTNAME,ADDRESS,PHONE,DATETIME,SALARY,IDENTIFIER
FROM PIOPLE;
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)
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.