Header And Logo

PostgreSQL
| The world's most advanced open source database.

sql-func.c

Go to the documentation of this file.
00001 /* Processed by ecpg (regression mode) */
00002 /* These include files are added by the preprocessor */
00003 #include <ecpglib.h>
00004 #include <ecpgerrno.h>
00005 #include <sqlca.h>
00006 /* End of automatic include section */
00007 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
00008 
00009 #line 1 "func.pgc"
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <string.h>
00013 
00014 
00015 #line 1 "regression.h"
00016 
00017 
00018 
00019 
00020 
00021 
00022 #line 5 "func.pgc"
00023 
00024 
00025 int main() {
00026   
00027 #line 8 "func.pgc"
00028  char text [ 25 ] ;
00029 
00030 #line 8 "func.pgc"
00031 
00032 
00033   ECPGdebug(1, stderr);
00034   { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
00035 #line 11 "func.pgc"
00036 
00037 
00038   { ECPGsetcommit(__LINE__, "on", NULL);}
00039 #line 13 "func.pgc"
00040 
00041   /* exec sql whenever sql_warning  sqlprint ; */
00042 #line 14 "func.pgc"
00043 
00044   /* exec sql whenever sqlerror  sqlprint ; */
00045 #line 15 "func.pgc"
00046 
00047 
00048   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table My_Table ( Item1 int , Item2 text )", ECPGt_EOIT, ECPGt_EORT);
00049 #line 17 "func.pgc"
00050 
00051 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00052 #line 17 "func.pgc"
00053 
00054 if (sqlca.sqlcode < 0) sqlprint();}
00055 #line 17 "func.pgc"
00056 
00057   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table Log ( name text , w text )", ECPGt_EOIT, ECPGt_EORT);
00058 #line 18 "func.pgc"
00059 
00060 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00061 #line 18 "func.pgc"
00062 
00063 if (sqlca.sqlcode < 0) sqlprint();}
00064 #line 18 "func.pgc"
00065 
00066 
00067   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create function My_Table_Check ( ) returns trigger as $test$\
00068     BEGIN\
00069     INSERT INTO Log VALUES(TG_NAME, TG_WHEN);\
00070     RETURN NEW;\
00071     END; $test$ language plpgsql", ECPGt_EOIT, ECPGt_EORT);
00072 #line 26 "func.pgc"
00073 
00074 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00075 #line 26 "func.pgc"
00076 
00077 if (sqlca.sqlcode < 0) sqlprint();}
00078 #line 26 "func.pgc"
00079 
00080 
00081   { 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);
00082 #line 32 "func.pgc"
00083 
00084 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00085 #line 32 "func.pgc"
00086 
00087 if (sqlca.sqlcode < 0) sqlprint();}
00088 #line 32 "func.pgc"
00089 
00090 
00091   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into My_Table values ( 1234 , 'Some random text' )", ECPGt_EOIT, ECPGt_EORT);
00092 #line 34 "func.pgc"
00093 
00094 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00095 #line 34 "func.pgc"
00096 
00097 if (sqlca.sqlcode < 0) sqlprint();}
00098 #line 34 "func.pgc"
00099 
00100   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into My_Table values ( 5678 , 'The Quick Brown' )", ECPGt_EOIT, ECPGt_EORT);
00101 #line 35 "func.pgc"
00102 
00103 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00104 #line 35 "func.pgc"
00105 
00106 if (sqlca.sqlcode < 0) sqlprint();}
00107 #line 35 "func.pgc"
00108 
00109   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select name from Log limit 1", ECPGt_EOIT, 
00110     ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char), 
00111     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00112 #line 36 "func.pgc"
00113 
00114 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00115 #line 36 "func.pgc"
00116 
00117 if (sqlca.sqlcode < 0) sqlprint();}
00118 #line 36 "func.pgc"
00119 
00120   printf("Trigger %s fired.\n", text);
00121 
00122   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop trigger My_Table_Check_Trigger on My_Table", ECPGt_EOIT, ECPGt_EORT);
00123 #line 39 "func.pgc"
00124 
00125 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00126 #line 39 "func.pgc"
00127 
00128 if (sqlca.sqlcode < 0) sqlprint();}
00129 #line 39 "func.pgc"
00130 
00131   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop function My_Table_Check ( )", ECPGt_EOIT, ECPGt_EORT);
00132 #line 40 "func.pgc"
00133 
00134 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00135 #line 40 "func.pgc"
00136 
00137 if (sqlca.sqlcode < 0) sqlprint();}
00138 #line 40 "func.pgc"
00139 
00140   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table Log", ECPGt_EOIT, ECPGt_EORT);
00141 #line 41 "func.pgc"
00142 
00143 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00144 #line 41 "func.pgc"
00145 
00146 if (sqlca.sqlcode < 0) sqlprint();}
00147 #line 41 "func.pgc"
00148 
00149   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table My_Table", ECPGt_EOIT, ECPGt_EORT);
00150 #line 42 "func.pgc"
00151 
00152 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00153 #line 42 "func.pgc"
00154 
00155 if (sqlca.sqlcode < 0) sqlprint();}
00156 #line 42 "func.pgc"
00157 
00158 
00159   { ECPGdisconnect(__LINE__, "ALL");
00160 #line 44 "func.pgc"
00161 
00162 if (sqlca.sqlwarn[0] == 'W') sqlprint();
00163 #line 44 "func.pgc"
00164 
00165 if (sqlca.sqlcode < 0) sqlprint();}
00166 #line 44 "func.pgc"
00167 
00168 
00169   return 0;
00170 }