PostgreSQL Source Code git master
sql-func.c
Go to the documentation of this file.
1/* Processed by ecpg (regression mode) */
2/* These include files are added by the preprocessor */
3#include <ecpglib.h>
4#include <ecpgerrno.h>
5#include <sqlca.h>
6/* End of automatic include section */
7#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
8
9#line 1 "func.pgc"
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13
14
15#line 1 "regression.h"
16
17
18
19
20
21
22#line 5 "func.pgc"
23
24
25int main() {
26
27#line 8 "func.pgc"
28 char text [ 25 ] ;
29
30#line 8 "func.pgc"
31
32
33 ECPGdebug(1, stderr);
34 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0); }
35#line 11 "func.pgc"
36
37
38 { ECPGsetcommit(__LINE__, "on", NULL);}
39#line 13 "func.pgc"
40
41 /* exec sql whenever sql_warning sqlprint ; */
42#line 14 "func.pgc"
43
44 /* exec sql whenever sqlerror sqlprint ; */
45#line 15 "func.pgc"
46
47
48 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table My_Table ( Item1 int , Item2 text )", ECPGt_EOIT, ECPGt_EORT);
49#line 17 "func.pgc"
50
51if (sqlca.sqlwarn[0] == 'W') sqlprint();
52#line 17 "func.pgc"
53
54if (sqlca.sqlcode < 0) sqlprint();}
55#line 17 "func.pgc"
56
57 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table Log ( name text , w text )", ECPGt_EOIT, ECPGt_EORT);
58#line 18 "func.pgc"
59
60if (sqlca.sqlwarn[0] == 'W') sqlprint();
61#line 18 "func.pgc"
62
63if (sqlca.sqlcode < 0) sqlprint();}
64#line 18 "func.pgc"
65
66
67 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create function My_Table_Check ( ) returns trigger as $test$\
68 BEGIN\
69 INSERT INTO Log VALUES(TG_NAME, TG_WHEN);\
70 RETURN NEW;\
71 END; $test$ language plpgsql", ECPGt_EOIT, ECPGt_EORT);
72#line 26 "func.pgc"
73
74if (sqlca.sqlwarn[0] == 'W') sqlprint();
75#line 26 "func.pgc"
76
77if (sqlca.sqlcode < 0) sqlprint();}
78#line 26 "func.pgc"
79
80
81 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create trigger My_Table_Check_Trigger before insert on My_Table for each row execute procedure My_Table_Check ( )", ECPGt_EOIT, ECPGt_EORT);
82#line 32 "func.pgc"
83
84if (sqlca.sqlwarn[0] == 'W') sqlprint();
85#line 32 "func.pgc"
86
87if (sqlca.sqlcode < 0) sqlprint();}
88#line 32 "func.pgc"
89
90
91 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into My_Table values ( 1234 , 'Some random text' )", ECPGt_EOIT, ECPGt_EORT);
92#line 34 "func.pgc"
93
94if (sqlca.sqlwarn[0] == 'W') sqlprint();
95#line 34 "func.pgc"
96
97if (sqlca.sqlcode < 0) sqlprint();}
98#line 34 "func.pgc"
99
100 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into My_Table values ( 5678 , 'The Quick Brown' )", ECPGt_EOIT, ECPGt_EORT);
101#line 35 "func.pgc"
102
103if (sqlca.sqlwarn[0] == 'W') sqlprint();
104#line 35 "func.pgc"
105
106if (sqlca.sqlcode < 0) sqlprint();}
107#line 35 "func.pgc"
108
109 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select name from Log limit 1", ECPGt_EOIT,
110 ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char),
111 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
112#line 36 "func.pgc"
113
114if (sqlca.sqlwarn[0] == 'W') sqlprint();
115#line 36 "func.pgc"
116
117if (sqlca.sqlcode < 0) sqlprint();}
118#line 36 "func.pgc"
119
120 printf("Trigger %s fired.\n", text);
121
122 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop trigger My_Table_Check_Trigger on My_Table", ECPGt_EOIT, ECPGt_EORT);
123#line 39 "func.pgc"
124
125if (sqlca.sqlwarn[0] == 'W') sqlprint();
126#line 39 "func.pgc"
127
128if (sqlca.sqlcode < 0) sqlprint();}
129#line 39 "func.pgc"
130
131 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop function My_Table_Check ( )", ECPGt_EOIT, ECPGt_EORT);
132#line 40 "func.pgc"
133
134if (sqlca.sqlwarn[0] == 'W') sqlprint();
135#line 40 "func.pgc"
136
137if (sqlca.sqlcode < 0) sqlprint();}
138#line 40 "func.pgc"
139
140 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table Log", ECPGt_EOIT, ECPGt_EORT);
141#line 41 "func.pgc"
142
143if (sqlca.sqlwarn[0] == 'W') sqlprint();
144#line 41 "func.pgc"
145
146if (sqlca.sqlcode < 0) sqlprint();}
147#line 41 "func.pgc"
148
149 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table My_Table", ECPGt_EOIT, ECPGt_EORT);
150#line 42 "func.pgc"
151
152if (sqlca.sqlwarn[0] == 'W') sqlprint();
153#line 42 "func.pgc"
154
155if (sqlca.sqlcode < 0) sqlprint();}
156#line 42 "func.pgc"
157
158
159 { ECPGdisconnect(__LINE__, "ALL");
160#line 44 "func.pgc"
161
162if (sqlca.sqlwarn[0] == 'W') sqlprint();
163#line 44 "func.pgc"
164
165if (sqlca.sqlcode < 0) sqlprint();}
166#line 44 "func.pgc"
167
168
169 return 0;
170}
bool ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
Definition: connect.c:153
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:676
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition: connect.c:255
@ ECPGst_normal
Definition: ecpgtype.h:97
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_EORT
Definition: ecpgtype.h:63
@ ECPGt_char
Definition: ecpgtype.h:43
void sqlprint(void)
Definition: error.c:334
bool ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query,...)
Definition: execute.c:2275
#define printf(...)
Definition: port.h:245
#define ECPGdebug(X, Y)
Definition: sql-func.c:7
int main()
Definition: sql-func.c:25
#define sqlca
Definition: sqlca.h:59
Definition: c.h:658