PostgreSQL Source Code: src/interfaces/ecpg/test/expected/sql-sqlda.c Source File (original) (raw)

1

2

6

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

8

9#line 1 "sqlda.pgc"

10#include <stdlib.h>

12#include <limits.h>

13#include "ecpg_config.h"

14

15

16#line 1 "regression.h"

17

18

19

20

21

22

23#line 6 "sqlda.pgc"

24

25

26#line 1 "sqlda.h"

27#ifndef ECPG_SQLDA_H

28#define ECPG_SQLDA_H

29

30#ifdef _ECPG_INFORMIX_H

31

35

36#else

37

41

42#endif

43

44#endif

45

46#line 7 "sqlda.pgc"

47

48

49#line 1 "pgtypes_numeric.h"

50#ifndef PGTYPES_NUMERIC

51#define PGTYPES_NUMERIC

52

54

55#define NUMERIC_POS 0x0000

56#define NUMERIC_NEG 0x4000

57#define NUMERIC_NAN 0xC000

58#define NUMERIC_NULL 0xF000

59#define NUMERIC_MAX_PRECISION 1000

60#define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION

61#define NUMERIC_MIN_DISPLAY_SCALE 0

62#define NUMERIC_MIN_SIG_DIGITS 16

63

64#define DECSIZE 30

65

67typedef struct

68{

69 int ndigits;

70 int weight;

71 int rscale;

72 int dscale;

73 int sign;

74 NumericDigit *buf;

77

78typedef struct

79{

80 int ndigits;

81 int weight;

82 int rscale;

83 int dscale;

84 int sign;

87

88#ifdef __cplusplus

89extern "C"

90{

91#endif

92

113

114#ifdef __cplusplus

115}

116#endif

117

118#endif

119

120#line 8 "sqlda.pgc"

121

122

123

124#line 10 "sqlda.pgc"

125

126

127

129

130static void

132{

133 int i;

134

135 if (sqlda == NULL)

136 {

137 printf("dump_sqlda called with NULL sqlda\n");

138 return;

139 }

140

141 for (i = 0; i < sqlda->sqld; i++)

142 {

145 else

147 {

150 break;

153 break;

156 break;

158 printf("name sqlda descriptor: '%s' value %lld\n",

160 break;

163 break;

165 {

166 char *val;

167

171 break;

172 }

173 }

174 }

175}

176

177int

179{

180

181

182

183

184

185

186#line 66 "sqlda.pgc"

187 char * stmt1 = "SELECT * FROM t1" ;

188

189#line 67 "sqlda.pgc"

190 char * stmt2 = "SELECT * FROM t1 WHERE id = ?" ;

191

192#line 68 "sqlda.pgc"

193 int rec ;

194

195#line 69 "sqlda.pgc"

196 int id ;

197

198#line 70 "sqlda.pgc"

199

200

201 char msg[128];

202

204

205 strcpy(msg, "connect");

206 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "regress1", 0);

207#line 77 "sqlda.pgc"

208

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

210#line 77 "sqlda.pgc"

211

212

213 strcpy(msg, "set");

215#line 80 "sqlda.pgc"

216

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

218#line 80 "sqlda.pgc"

219

220

221 strcpy(msg, "create");

222 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table t1 ( id integer , t text , d1 numeric , d2 float8 , c char ( 10 ) , big bigint )", ECPGt_EOIT, ECPGt_EORT);

223#line 90 "sqlda.pgc"

224

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

226#line 90 "sqlda.pgc"

227

228

229 strcpy(msg, "insert");

230 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into t1 values ( 1 , 'a' , 1.0 , 1 , 'a' , 1111111111111111111 ) , ( 2 , null , null , null , null , null ) , ( 3 , 'c' , 0.0 , 3 , 'c' , 3333333333333333333 ) , ( 4 , 'd' , 'NaN' , 4 , 'd' , 4444444444444444444 ) , ( 5 , 'e' , 0.001234 , 5 , 'e' , 5555555555555555555 )", ECPGt_EOIT, ECPGt_EORT);

231#line 98 "sqlda.pgc"

232

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

234#line 98 "sqlda.pgc"

235

236

237 strcpy(msg, "commit");

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

239#line 101 "sqlda.pgc"

240

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

242#line 101 "sqlda.pgc"

243

244

245

246

248

249 strcpy(msg, "prepare");

250 { ECPGprepare(__LINE__, NULL, 0, "st_id1", stmt1);

251#line 108 "sqlda.pgc"

252

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

254#line 108 "sqlda.pgc"

255

256

257 strcpy(msg, "declare");

258

259#line 111 "sqlda.pgc"

260

261

262 strcpy(msg, "open");

263 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur1 cursor for $1",

266#line 114 "sqlda.pgc"

267

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

269#line 114 "sqlda.pgc"

270

271

272

273#line 116 "sqlda.pgc"

274

275

276 rec = 0;

277 while (1)

278 {

279 strcpy(msg, "fetch");

283#line 122 "sqlda.pgc"

284

286#line 122 "sqlda.pgc"

287

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

289#line 122 "sqlda.pgc"

290

291

292 printf("FETCH RECORD %d\n", ++rec);

294 }

295

296

297#line 128 "sqlda.pgc"

298

299

300 strcpy(msg, "close");

302#line 131 "sqlda.pgc"

303

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

305#line 131 "sqlda.pgc"

306

307

308 strcpy(msg, "deallocate");

310#line 134 "sqlda.pgc"

311

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

313#line 134 "sqlda.pgc"

314

315

317

318

319

321

322 strcpy(msg, "prepare");

323 { ECPGprepare(__LINE__, NULL, 0, "st_id2", stmt1);

324#line 143 "sqlda.pgc"

325

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

327#line 143 "sqlda.pgc"

328

329

330 strcpy(msg, "declare");

331

332#line 146 "sqlda.pgc"

333

334

335 strcpy(msg, "open");

336 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur2 cursor for $1",

339#line 149 "sqlda.pgc"

340

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

342#line 149 "sqlda.pgc"

343

344

345 strcpy(msg, "fetch");

349#line 152 "sqlda.pgc"

350

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

352#line 152 "sqlda.pgc"

353

354

356 rec = 0;

358 {

360 printf("FETCH RECORD %d\n", ++rec);

362

366 }

367

368 strcpy(msg, "close");

370#line 168 "sqlda.pgc"

371

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

373#line 168 "sqlda.pgc"

374

375

376 strcpy(msg, "deallocate");

378#line 171 "sqlda.pgc"

379

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

381#line 171 "sqlda.pgc"

382

383

384

385

386

387

388

389

393

396

397 printf("EXECUTE RECORD 4\n");

398

399 id = 4;

400

402

403 strcpy(msg, "prepare");

404 { ECPGprepare(__LINE__, NULL, 0, "st_id3", stmt2);

405#line 193 "sqlda.pgc"

406

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

408#line 193 "sqlda.pgc"

409

410

411 strcpy(msg, "execute");

417#line 196 "sqlda.pgc"

418

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

420#line 196 "sqlda.pgc"

421

422

424

425 strcpy(msg, "deallocate");

427#line 201 "sqlda.pgc"

428

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

430#line 201 "sqlda.pgc"

431

432

435

436

437

438

439

440 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "con2", 0);

441#line 210 "sqlda.pgc"

442

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

444#line 210 "sqlda.pgc"

445

446

447

448

449

450

454

457

458 printf("EXECUTE RECORD 4\n");

459

460 id = 4;

461

463

464 strcpy(msg, "prepare");

465 { ECPGprepare(__LINE__, "con2", 0, "st_id4", stmt2);

466#line 230 "sqlda.pgc"

467

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

469#line 230 "sqlda.pgc"

470

471

472 strcpy(msg, "execute");

478#line 233 "sqlda.pgc"

479

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

481#line 233 "sqlda.pgc"

482

483

485

486 strcpy(msg, "commit");

487 { ECPGtrans(__LINE__, "con2", "commit");

488#line 238 "sqlda.pgc"

489

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

491#line 238 "sqlda.pgc"

492

493

494 strcpy(msg, "deallocate");

496#line 241 "sqlda.pgc"

497

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

499#line 241 "sqlda.pgc"

500

501

504

505 strcpy(msg, "disconnect");

507#line 247 "sqlda.pgc"

508

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

510#line 247 "sqlda.pgc"

511

512

513

514

515 strcpy(msg, "drop");

517#line 252 "sqlda.pgc"

518

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

520#line 252 "sqlda.pgc"

521

522

523 strcpy(msg, "commit");

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

525#line 255 "sqlda.pgc"

526

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

528#line 255 "sqlda.pgc"

529

530

531 strcpy(msg, "disconnect");

533#line 258 "sqlda.pgc"

534

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

536#line 258 "sqlda.pgc"

537

538

539 return 0;

540}

Datum numeric(PG_FUNCTION_ARGS)

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)

char * ECPGprepared_statement(const char *connection_name, const char *name, int lineno)

bool ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)

bool ECPGdeallocate(int lineno, int c, const char *connection_name, const char *name)

void PGTYPESchar_free(char *ptr)

int PGTYPESnumeric_from_double(double d, numeric *dst)

int PGTYPESnumeric_copy(numeric *src, numeric *dst)

int PGTYPESnumeric_from_decimal(decimal *src, numeric *dst)

numeric * PGTYPESnumeric_new(void)

int PGTYPESnumeric_to_decimal(numeric *src, decimal *dst)

char * PGTYPESnumeric_to_asc(numeric *num, int dscale)

void PGTYPESdecimal_free(decimal *var)

int PGTYPESnumeric_mul(numeric *var1, numeric *var2, numeric *result)

int PGTYPESnumeric_to_long(numeric *nv, long *lp)

int PGTYPESnumeric_to_double(numeric *nv, double *dp)

int PGTYPESnumeric_from_long(signed long int long_val, numeric *var)

int PGTYPESnumeric_to_int(numeric *nv, int *ip)

static void dump_sqlda(sqlda_t *sqlda)

int PGTYPESnumeric_from_int(signed int int_val, numeric *var)

int PGTYPESnumeric_sub(numeric *var1, numeric *var2, numeric *result)

decimal * PGTYPESdecimal_new(void)

void PGTYPESnumeric_free(numeric *var)

int PGTYPESnumeric_cmp(numeric *var1, numeric *var2)

int PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric *result)

int PGTYPESnumeric_add(numeric *var1, numeric *var2, numeric *result)

unsigned char NumericDigit

numeric * PGTYPESnumeric_from_asc(char *str, char **endptr)

struct sqlvar_struct sqlvar[1]

struct sqlda_struct * desc_next