PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sql-dynalloc2.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 "dynalloc2.pgc"
10#include <stdio.h>
11
12#line 1 "sqlca.h"
13#ifndef POSTGRES_SQLCA_H
14#define POSTGRES_SQLCA_H
15
16#ifndef PGDLLIMPORT
17#if defined(WIN32) || defined(__CYGWIN__)
18#define PGDLLIMPORT __declspec (dllimport)
19#else
20#define PGDLLIMPORT
21#endif /* __CYGWIN__ */
22#endif /* PGDLLIMPORT */
23
24#define SQLERRMC_LEN 150
25
26#ifdef __cplusplus
27extern "C"
28{
29#endif
30
31struct sqlca_t
32{
33 char sqlcaid[8];
34 long sqlabc;
35 long sqlcode;
36 struct
37 {
38 int sqlerrml;
41 char sqlerrp[8];
42 long sqlerrd[6];
43 /* Element 0: empty */
44 /* 1: OID of processed tuple if applicable */
45 /* 2: number of rows processed */
46 /* after an INSERT, UPDATE or */
47 /* DELETE statement */
48 /* 3: empty */
49 /* 4: empty */
50 /* 5: empty */
51 char sqlwarn[8];
52 /* Element 0: set to 'W' if at least one other is 'W' */
53 /* 1: if 'W' at least one character string */
54 /* value was truncated when it was */
55 /* stored into a host variable. */
56
57 /*
58 * 2: if 'W' a (hopefully) non-fatal notice occurred
59 */ /* 3: empty */
60 /* 4: empty */
61 /* 5: empty */
62 /* 6: empty */
63 /* 7: empty */
64
65 char sqlstate[5];
66};
67
68struct sqlca_t *ECPGget_sqlca(void);
69
70#ifndef POSTGRES_ECPG_INTERNAL
71#define sqlca (*ECPGget_sqlca())
72#endif
73
74#ifdef __cplusplus
75}
76#endif
77
78#endif
79
80#line 2 "dynalloc2.pgc"
81
82#include <stdlib.h>
83
84#line 1 "regression.h"
85
86
87
88
89
90
91#line 4 "dynalloc2.pgc"
92
93
94int main(void)
95{
96 /* exec sql begin declare section */
97
98
99
100
101
102
103#line 9 "dynalloc2.pgc"
104 int * ip1 = 0 ;
105
106#line 10 "dynalloc2.pgc"
107 char ** cp2 = 0 ;
108
109#line 11 "dynalloc2.pgc"
110 int * ipointer1 = 0 ;
111
112#line 12 "dynalloc2.pgc"
113 int * ipointer2 = 0 ;
114
115#line 13 "dynalloc2.pgc"
116 int colnum ;
117/* exec sql end declare section */
118#line 14 "dynalloc2.pgc"
119
120 int i;
121
122 ECPGdebug(1, stderr);
123
124 /* exec sql whenever sqlerror do sqlprint ( ) ; */
125#line 19 "dynalloc2.pgc"
126
127 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
128#line 20 "dynalloc2.pgc"
129
130if (sqlca.sqlcode < 0) sqlprint ( );}
131#line 20 "dynalloc2.pgc"
132
133
134 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "set datestyle to postgres", ECPGt_EOIT, ECPGt_EORT);
135#line 22 "dynalloc2.pgc"
136
137if (sqlca.sqlcode < 0) sqlprint ( );}
138#line 22 "dynalloc2.pgc"
139
140
141 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( a int , b text )", ECPGt_EOIT, ECPGt_EORT);
142#line 24 "dynalloc2.pgc"
143
144if (sqlca.sqlcode < 0) sqlprint ( );}
145#line 24 "dynalloc2.pgc"
146
147 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( 1 , 'one' )", ECPGt_EOIT, ECPGt_EORT);
148#line 25 "dynalloc2.pgc"
149
150if (sqlca.sqlcode < 0) sqlprint ( );}
151#line 25 "dynalloc2.pgc"
152
153 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( 2 , 'two' )", ECPGt_EOIT, ECPGt_EORT);
154#line 26 "dynalloc2.pgc"
155
156if (sqlca.sqlcode < 0) sqlprint ( );}
157#line 26 "dynalloc2.pgc"
158
159 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( null , 'three' )", ECPGt_EOIT, ECPGt_EORT);
160#line 27 "dynalloc2.pgc"
161
162if (sqlca.sqlcode < 0) sqlprint ( );}
163#line 27 "dynalloc2.pgc"
164
165 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( 4 , 'four' )", ECPGt_EOIT, ECPGt_EORT);
166#line 28 "dynalloc2.pgc"
167
168if (sqlca.sqlcode < 0) sqlprint ( );}
169#line 28 "dynalloc2.pgc"
170
171 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( 5 , null )", ECPGt_EOIT, ECPGt_EORT);
172#line 29 "dynalloc2.pgc"
173
174if (sqlca.sqlcode < 0) sqlprint ( );}
175#line 29 "dynalloc2.pgc"
176
177 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test values ( null , null )", ECPGt_EOIT, ECPGt_EORT);
178#line 30 "dynalloc2.pgc"
179
180if (sqlca.sqlcode < 0) sqlprint ( );}
181#line 30 "dynalloc2.pgc"
182
183
184 ECPGallocate_desc(__LINE__, "mydesc");
185#line 32 "dynalloc2.pgc"
186
187if (sqlca.sqlcode < 0) sqlprint ( );
188#line 32 "dynalloc2.pgc"
189
190 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from test", ECPGt_EOIT,
191 ECPGt_descriptor, "mydesc", 1L, 1L, 1L,
192 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
193#line 33 "dynalloc2.pgc"
194
195if (sqlca.sqlcode < 0) sqlprint ( );}
196#line 33 "dynalloc2.pgc"
197
198 { ECPGget_desc_header(__LINE__, "mydesc", &(colnum));
199
200#line 34 "dynalloc2.pgc"
201
202if (sqlca.sqlcode < 0) sqlprint ( );}
203#line 34 "dynalloc2.pgc"
204
205 { ECPGget_desc(__LINE__, "mydesc", 1,ECPGd_indicator,
206 ECPGt_int,&(ipointer1),(long)1,(long)0,sizeof(int), ECPGd_data,
207 ECPGt_int,&(ip1),(long)1,(long)0,sizeof(int), ECPGd_EODT);
208
209#line 35 "dynalloc2.pgc"
210
211if (sqlca.sqlcode < 0) sqlprint ( );}
212#line 35 "dynalloc2.pgc"
213
214 { ECPGget_desc(__LINE__, "mydesc", 2,ECPGd_indicator,
215 ECPGt_int,&(ipointer2),(long)1,(long)0,sizeof(int), ECPGd_data,
216 ECPGt_char,&(cp2),(long)0,(long)0,(1)*sizeof(char), ECPGd_EODT);
217
218#line 36 "dynalloc2.pgc"
219
220if (sqlca.sqlcode < 0) sqlprint ( );}
221#line 36 "dynalloc2.pgc"
222
223
224 printf("Result (%d columns):\n", colnum);
225 for (i=0;i < sqlca.sqlerrd[2];++i)
226 {
227 if (ipointer1[i]) printf("NULL, ");
228 else printf("%d, ",ip1[i]);
229
230 if (ipointer2[i]) printf("NULL, ");
231 else printf("'%s', ",cp2[i]);
232 printf("\n");
233 }
235 printf("\n");
236
237 ECPGdeallocate_desc(__LINE__, "mydesc");
238#line 51 "dynalloc2.pgc"
239
240if (sqlca.sqlcode < 0) sqlprint ( );
241#line 51 "dynalloc2.pgc"
242
243 { ECPGtrans(__LINE__, NULL, "rollback");
244#line 52 "dynalloc2.pgc"
245
246if (sqlca.sqlcode < 0) sqlprint ( );}
247#line 52 "dynalloc2.pgc"
248
249 { ECPGdisconnect(__LINE__, "CURRENT");
250#line 53 "dynalloc2.pgc"
251
252if (sqlca.sqlcode < 0) sqlprint ( );}
253#line 53 "dynalloc2.pgc"
254
255 return 0;
256}
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
bool ECPGdeallocate_desc(int line, const char *name)
Definition: descriptor.c:748
bool ECPGget_desc(int lineno, const char *desc_name, int index,...)
Definition: descriptor.c:234
bool ECPGallocate_desc(int line, const char *name)
Definition: descriptor.c:792
bool ECPGget_desc_header(int lineno, const char *desc_name, int *count)
Definition: descriptor.c:84
@ ECPGst_normal
Definition: ecpgtype.h:97
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_int
Definition: ecpgtype.h:44
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_EORT
Definition: ecpgtype.h:63
@ ECPGt_descriptor
Definition: ecpgtype.h:59
@ ECPGt_char
Definition: ecpgtype.h:43
@ ECPGd_indicator
Definition: ecpgtype.h:77
@ ECPGd_EODT
Definition: ecpgtype.h:88
@ ECPGd_data
Definition: ecpgtype.h:74
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
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition: misc.c:160
int i
Definition: isn.c:77
void ECPGfree_auto_mem(void)
Definition: memory.c:131
#define printf(...)
Definition: port.h:245
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:108
int main(void)
Definition: sql-dynalloc2.c:94
#define SQLERRMC_LEN
Definition: sql-dynalloc2.c:24
#define sqlca
Definition: sql-dynalloc2.c:71
#define ECPGdebug(X, Y)
Definition: sql-dynalloc2.c:7
Definition: sqlca.h:20
struct sqlca_t::@168 sqlerrm
char sqlerrp[8]
Definition: sqlca.h:29
long sqlerrd[6]
Definition: sqlca.h:30
char sqlstate[5]
Definition: sqlca.h:53
char sqlwarn[8]
Definition: sqlca.h:39
long sqlabc
Definition: sqlca.h:22
char sqlcaid[8]
Definition: sqlca.h:21
char sqlerrmc[SQLERRMC_LEN]
Definition: sqlca.h:27
long sqlcode
Definition: sqlca.h:23
int sqlerrml
Definition: sqlca.h:26