aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/test/test1.pgc
blob: c485a487fce68b5d2efe39d3721f25aa7765540a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>

exec sql whenever sqlerror sqlprint;

exec sql include sqlca;

int
main ()
{
exec sql begin declare section;
        int amount[5];
        char name[5][8];
exec sql end declare section;
	char msg[128], command[128];
        FILE *dbgs;
        int i,j;

	if ((dbgs = fopen("log", "w")) != NULL)
                ECPGdebug(1, dbgs);

	strcpy(msg, "connect");
	exec sql connect to mm;

	strcpy(msg, "create");
	exec sql create table test(name char(8), amount int);

	strcpy(msg, "execute insert 1");
        sprintf(command, "insert into test(name, amount) values ('foobar', 1)");
        exec sql execute immediate :command;

        strcpy(msg, "excute insert 2");
        sprintf(command, "insert into test(name, amount) select name, amount+1 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");
        exec sql execute immediate :command;
        
	printf("Inserted %d tuples via execute immediate\n", sqlca.sqlerrd[2]);

	strcpy(msg, "commit");
	exec sql commit;

        strcpy(msg, "select");
        exec sql select name, amount into :name, :amount 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]);
        
	strcpy(msg, "drop");
	exec sql drop table test;

	strcpy(msg, "commit");
	exec sql commit;

	strcpy(msg, "disconnect"); 
        exec sql disconnect;
        
	if (dbgs != NULL)
                fclose(dbgs);

	return (0);
}