PostgreSQL Source Code: src/interfaces/ecpg/test/expected/preproc-variable.c File Reference (original) (raw)

55{

56 struct birthinfo {

57#line 23 "variable.pgc"

58 long born ;

59

60#line 23 "variable.pgc"

61 short age ;

62 } ;

63#line 23 "variable.pgc"

64

65

66

67

68

69

70

71

72

73

74

75

76

77#line 27 "variable.pgc"

78 struct personal_struct {

79#line 25 "variable.pgc"

81

82#line 26 "variable.pgc"

83 struct birthinfo birth ;

84 } personal , * p ;

85

86#line 30 "variable.pgc"

87 struct personal_indicator {

88#line 28 "variable.pgc"

89 int ind_name ;

90

91#line 29 "variable.pgc"

92 struct birthinfo ind_birth ;

93 } ind_personal , * i ;

94

95#line 31 "variable.pgc"

96 ind ind_children ;

97 struct t1 {

98#line 32 "variable.pgc"

100 } ; struct t2 {

101#line 32 "variable.pgc"

103 } ;

104#line 33 "variable.pgc"

105 static struct varchar_4 { int len; char arr[ 50 ]; } vc1 ; static struct varchar_5 { int len; char arr[ 50 ]; } vc2 ; static struct varchar_6 { int len; char arr[ 255 ]; } vc3 ;

106

107#line 34 "variable.pgc"

108 static int i1 , i2 , i3 ;

109

110#line 35 "variable.pgc"

111

112

113

114#line 37 "variable.pgc"

115 char * married = NULL ;

116

117#line 37 "variable.pgc"

118

119

120#line 38 "variable.pgc"

121 long ind_married ;

122

123#line 38 "variable.pgc"

124

125

126#line 39 "variable.pgc"

127 ind children ;

128

129#line 39 "variable.pgc"

130

131 int loopcount;

132 char msg[128];

133

135

136 strcpy(msg, "connect");

137 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);

138#line 46 "variable.pgc"

139

140if (sqlca.sqlcode < 0) exit (1);}

141#line 46 "variable.pgc"

142

143

144 strcpy(msg, "set");

146#line 49 "variable.pgc"

147

148if (sqlca.sqlcode < 0) exit (1);}

149#line 49 "variable.pgc"

150

151

152 strcpy(msg, "create");

153 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table family ( name char ( 8 ) , born integer , age smallint , married date , children integer )", ECPGt_EOIT, ECPGt_EORT);

154#line 52 "variable.pgc"

155

156if (sqlca.sqlcode < 0) exit (1);}

157#line 52 "variable.pgc"

158

159

160 strcpy(msg, "insert");

161 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , married , children ) values ( 'Mum' , '19870714' , 3 )", ECPGt_EOIT, ECPGt_EORT);

162#line 55 "variable.pgc"

163

164if (sqlca.sqlcode < 0) exit (1);}

165#line 55 "variable.pgc"

166

167 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , born , married , children ) values ( 'Dad' , '19610721' , '19870714' , 3 )", ECPGt_EOIT, ECPGt_EORT);

168#line 56 "variable.pgc"

169

170if (sqlca.sqlcode < 0) exit (1);}

171#line 56 "variable.pgc"

172

173 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , age ) values ( 'Child 1' , 16 )", ECPGt_EOIT, ECPGt_EORT);

174#line 57 "variable.pgc"

175

176if (sqlca.sqlcode < 0) exit (1);}

177#line 57 "variable.pgc"

178

179 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , age ) values ( 'Child 2' , 14 )", ECPGt_EOIT, ECPGt_EORT);

180#line 58 "variable.pgc"

181

182if (sqlca.sqlcode < 0) exit (1);}

183#line 58 "variable.pgc"

184

185 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , age ) values ( 'Child 3' , 9 )", ECPGt_EOIT, ECPGt_EORT);

186#line 59 "variable.pgc"

187

188if (sqlca.sqlcode < 0) exit (1);}

189#line 59 "variable.pgc"

190

191

192 strcpy(msg, "commit");

193 { ECPGtrans(__LINE__, NULL, "commit");

194#line 62 "variable.pgc"

195

196if (sqlca.sqlcode < 0) exit (1);}

197#line 62 "variable.pgc"

198

199

200 strcpy(msg, "open");

201 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur cursor for select name , born , age , married , children from family", ECPGt_EOIT, ECPGt_EORT);

202#line 65 "variable.pgc"

203

204if (sqlca.sqlcode < 0) exit (1);}

205#line 65 "variable.pgc"

206

207

208

209#line 67 "variable.pgc"

210

211

212 p=&personal;

213 i=&ind_personal;

214 memset(i, 0, sizeof(ind_personal));

215 for (loopcount = 0; loopcount < 100; loopcount++) {

216 strcpy(msg, "fetch");

219 ECPGt_int,&(i->ind_name),(long)1,(long)-1,sizeof( struct birthinfo ),

220 ECPGt_long,&(p->birth.born),(long)1,(long)1,sizeof( struct birthinfo ),

221 ECPGt_long,&(i->ind_birth.born),(long)1,(long)1,sizeof( struct birthinfo ),

222 ECPGt_short,&(p->birth.age),(long)1,(long)1,sizeof( struct birthinfo ),

223 ECPGt_short,&(i->ind_birth.age),(long)1,(long)1,sizeof( struct birthinfo ),

224 ECPGt_char,&(married),(long)0,(long)1,(1)*sizeof(char),

225 ECPGt_long,&(ind_married),(long)1,(long)1,sizeof(long),

228#line 74 "variable.pgc"

229

231#line 74 "variable.pgc"

232

233if (sqlca.sqlcode < 0) exit (1);}

234#line 74 "variable.pgc"

235

236 printf("%8.8s", personal.name.arr);

237 if (i->ind_birth.born >= 0)

238 printf(", born %ld", personal.birth.born);

239 if (i->ind_birth.age >= 0)

240 printf(", age = %d", personal.birth.age);

241 if (ind_married >= 0)

242 printf(", married %s", married);

243 if (ind_children.smallint >= 0)

245 putchar('\n');

246

247 free(married);

248 married = NULL;

249 }

250

251 strcpy(msg, "close");

253#line 91 "variable.pgc"

254

255if (sqlca.sqlcode < 0) exit (1);}

256#line 91 "variable.pgc"

257

258

259 strcpy(msg, "drop");

261#line 94 "variable.pgc"

262

263if (sqlca.sqlcode < 0) exit (1);}

264#line 94 "variable.pgc"

265

266

267 strcpy(msg, "commit");

268 { ECPGtrans(__LINE__, NULL, "commit");

269#line 97 "variable.pgc"

270

271if (sqlca.sqlcode < 0) exit (1);}

272#line 97 "variable.pgc"

273

274

275 strcpy(msg, "disconnect");

277#line 100 "variable.pgc"

278

279if (sqlca.sqlcode < 0) exit (1);}

280#line 100 "variable.pgc"

281

282

283

284 vc1.len = vc2.len = vc3.len = 0;

285 i1 = i2 = i3 = 0;

286 printf("%d %d %d %d %d %d\n",

287 vc1.len, vc2.len, vc3.len,

288 i1, i2, i3);

289

290 return 0;

291}

bool ECPGdisconnect(int lineno, const char *connection_name)

bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)

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,...)

bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)