PostgreSQL Source Code  git master
sql-func.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for sql-func.c:

Go to the source code of this file.

Macros

#define ECPGdebug(X, Y)   ECPGdebug((X)+100,(Y))
 

Functions

int main ()
 

Macro Definition Documentation

◆ ECPGdebug

#define ECPGdebug (   X,
 
)    ECPGdebug((X)+100,(Y))

Definition at line 7 of file sql-func.c.

Function Documentation

◆ main()

int main ( void  )

Definition at line 25 of file sql-func.c.

25  {
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 
51 if (sqlca.sqlwarn[0] == 'W') sqlprint();
52 #line 17 "func.pgc"
53 
54 if (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 
60 if (sqlca.sqlwarn[0] == 'W') sqlprint();
61 #line 18 "func.pgc"
62 
63 if (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 
74 if (sqlca.sqlwarn[0] == 'W') sqlprint();
75 #line 26 "func.pgc"
76 
77 if (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 
84 if (sqlca.sqlwarn[0] == 'W') sqlprint();
85 #line 32 "func.pgc"
86 
87 if (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 
94 if (sqlca.sqlwarn[0] == 'W') sqlprint();
95 #line 34 "func.pgc"
96 
97 if (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 
103 if (sqlca.sqlwarn[0] == 'W') sqlprint();
104 #line 35 "func.pgc"
105 
106 if (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 
114 if (sqlca.sqlwarn[0] == 'W') sqlprint();
115 #line 36 "func.pgc"
116 
117 if (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 
125 if (sqlca.sqlwarn[0] == 'W') sqlprint();
126 #line 39 "func.pgc"
127 
128 if (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 
134 if (sqlca.sqlwarn[0] == 'W') sqlprint();
135 #line 40 "func.pgc"
136 
137 if (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 
143 if (sqlca.sqlwarn[0] == 'W') sqlprint();
144 #line 41 "func.pgc"
145 
146 if (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 
152 if (sqlca.sqlwarn[0] == 'W') sqlprint();
153 #line 42 "func.pgc"
154 
155 if (sqlca.sqlcode < 0) sqlprint();}
156 #line 42 "func.pgc"
157 
158 
159  { ECPGdisconnect(__LINE__, "ALL");
160 #line 44 "func.pgc"
161 
162 if (sqlca.sqlwarn[0] == 'W') sqlprint();
163 #line 44 "func.pgc"
164 
165 if (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:673
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:2277
#define printf(...)
Definition: port.h:244
#define ECPGdebug(X, Y)
Definition: sql-func.c:7
#define sqlca
Definition: sqlca.h:59
Definition: c.h:687

References ECPGconnect(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGsetcommit(), ECPGst_normal, ECPGt_char, ECPGt_EOIT, ECPGt_EORT, ECPGt_NO_INDICATOR, printf, sqlca, and sqlprint().