1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-05 07:21:24 +03:00
See Changes file...
This commit is contained in:
Marc G. Fournier
1999-02-20 07:01:08 +00:00
parent 3eb22085b5
commit bf6636baa6
20 changed files with 1491 additions and 434 deletions

View File

@ -4,16 +4,25 @@ exec sql whenever sqlerror sqlprint;
exec sql include sqlca;
exec sql define AMOUNT 5;
exec sql define AMOUNT 8;
exec sql type intarray is int[AMOUNT];
exec sql type string is char(6);
typedef int intarray[AMOUNT];
int
main ()
{
exec sql begin declare section;
int amount[AMOUNT];
char name[AMOUNT][8];
intarray amount;
int increment=100;
char name[AMOUNT][6];
char letter[AMOUNT][1];
char command[128];
exec sql end declare section;
char msg[128], command[128];
exec sql var name is string(AMOUNT);
char msg[128];
FILE *dbgs;
int i,j;
@ -24,30 +33,40 @@ exec sql end declare section;
exec sql connect to mm;
strcpy(msg, "create");
exec sql create table test(name char(8), amount int);
exec sql create table test(name char(6), amount int, letter char(1));
strcpy(msg, "commit");
exec sql commit;
strcpy(msg, "execute insert 1");
sprintf(command, "insert into test(name, amount) values ('foobar', 1)");
sprintf(command, "insert into test(name, amount, letter) values ('foobar', 1, 'f')");
exec sql execute immediate :command;
strcpy(msg, "excute insert 2");
sprintf(command, "insert into test(name, amount) select name, amount+1 from test");
strcpy(msg, "execute insert 2");
sprintf(command, "insert into test(name, amount, letter) select name, amount+1, letter from test");
exec sql execute immediate :command;
strcpy(msg, "excute insert 3");
sprintf(command, "insert into test(name, amount) select name, amount+10 from test");
strcpy(msg, "execute insert 3");
sprintf(command, "insert into test(name, amount, letter) select name, amount+10, letter from test");
exec sql execute immediate :command;
printf("Inserted %d tuples via execute immediate\n", sqlca.sqlerrd[2]);
strcpy(msg, "execute insert 4");
sprintf(command, "insert into test(name, amount, letter) select name, amount+;;, letter from test");
exec sql prepare I from :command;
exec sql execute I using :increment;
printf("Inserted %d tuples via prepared execute\n", sqlca.sqlerrd[2]);
strcpy(msg, "commit");
exec sql commit;
strcpy(msg, "select");
exec sql select name, amount into :name, :amount from test;
exec sql select name, amount, letter into :name, :amount, :letter from test;
for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
printf("name[%d]=%8.8s, amount[%d]=%d\n", i, name[i], i, amount[i]);
printf("name[%d]=%6.6s\tamount[%d]=%d\tletter[%d]=%c\n", i, name[i], i, amount[i],i, letter[i][0]);
strcpy(msg, "drop");
exec sql drop table test;

View File

@ -2,26 +2,31 @@
exec sql include header_test;
exec sql type c is char reference;
typedef char* c;
int
main ()
{
typedef struct { long born; short age; } birthinfo;
exec sql type birthinfo is struct { long born; short age; };
exec sql begin declare section;
struct personal_struct { varchar name[8];
struct birth_struct { long born;
short age;
} birth;
birthinfo birth;
} personal;
struct personal_indicator { short ind_name;
struct birth_indicator { short ind_born;
int ind_age;
} ind_birth;
struct personal_indicator { int ind_name;
birthinfo ind_birth;
} ind_personal;
long ind_married;
int ind_married;
char married[9];
c testname="Petra";
char *query="select name, born, age, married from meskes where name = :var1";
exec sql end declare section;
exec sql declare cur cursor for
select name, born, age, married from meskes;
exec sql var ind_married is long;
exec sql declare cur cursor for
select name, born, age, married from meskes;
char msg[128], command[128];
FILE *dbgs;
@ -36,11 +41,11 @@ exec sql declare cur cursor for
exec sql create table meskes(name char(8), born integer, age smallint, married char(8));
strcpy(msg, "insert");
exec sql insert into meskes(name, born, age, married) values ('Petra', 19661202, 32, '19900404');
exec sql insert into meskes(name, married) values ('Petra', '19900404');
exec sql insert into meskes(name, born, age, married) values ('Michael', 19660117, 33, '19900404');
exec sql insert into meskes(name, born, age) values ('Carsten', 19910103, 7);
exec sql insert into meskes(name, born, age) values ('Marc', 19930907, 4);
exec sql insert into meskes(name, born, age) values ('Chris', 19970923, 0);
exec sql insert into meskes(name, born, age) values ('Carsten', 19910103, 8);
exec sql insert into meskes(name, born, age) values ('Marc', 19930907, 5);
exec sql insert into meskes(name, born, age) values ('Chris', 19970923, 1);
strcpy(msg, "commit");
exec sql commit;
@ -53,12 +58,44 @@ exec sql declare cur cursor for
while (1) {
strcpy(msg, "fetch");
exec sql fetch in cur into :personal:ind_personal, :married:ind_married;
printf ("%8.8s was born %d (age = %d) %s%s\n", personal.name.arr, personal.birth.born, personal.birth.age, ind_married ? "" : "and married ", ind_married ? "" : married);
printf("%8.8s", personal.name.arr);
if (!ind_personal.ind_birth.born)
printf(", born %d", personal.birth.born);
if (!ind_personal.ind_birth.age)
printf(", age = %d", personal.birth.age);
if (!ind_married)
printf(", married %s", married);
putchar('\n');
}
strcpy(msg, "close");
exec sql close cur;
/* and now the same query with prepare */
exec sql prepare MM from :query;
exec sql declare prep cursor for MM;
strcpy(msg, "open");
exec sql open prep using :testname;
exec sql whenever not found do break;
while (1) {
strcpy(msg, "fetch");
exec sql fetch in prep into :personal:ind_personal, :married:ind_married;
printf("%8.8s", personal.name.arr);
if (!ind_personal.ind_birth.born)
printf(", born %d", personal.birth.born);
if (!ind_personal.ind_birth.age)
printf(", age = %d", personal.birth.age);
if (!ind_married)
printf(", married %s", married);
putchar('\n');
}
strcpy(msg, "close");
exec sql close prep;
strcpy(msg, "drop");
exec sql drop table meskes;