summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/sql/code100.pgc
blob: d9a5e52444a791c9fe73a553c1938192337ce1bc (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
exec sql include sqlca;
#include <stdio.h>

exec sql include ../regression;


int main()
{  exec sql begin declare section;
   int index;
   exec sql end declare section;


   ECPGdebug(1,stderr);

   exec sql connect to REGRESSDB1;
   if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);

   exec sql create table test (
        "index" numeric(3) primary key,
        "payload" int4 NOT NULL);
   if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
   exec sql commit work;
   if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);

   for (index=0;index<10;++index)
   {  exec sql insert into test
                (payload, index)
                values (0, :index);
      if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
   }
   exec sql commit work;
   if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);

   exec sql update test
	set payload=payload+1 where index=-1;
   if (sqlca.sqlcode!=100) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);

   exec sql delete from test where index=-1;
   if (sqlca.sqlcode!=100) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);

   exec sql insert into test (select * from test where index=-1);
   if (sqlca.sqlcode!=100) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);

   exec sql drop table test;
   if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
   exec sql commit work;
   if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);

   exec sql disconnect;
   if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
   return 0;
}