Skip to content

Commit cf4d9c4

Browse files
author
Michael Meskes
committed
Fix SQL3 type return value.
For non-SQL3 types ecpg used to return -Oid. This will break if there are enough Oids to fill the namespace. Therefore we play it safe and return 0 if there is no Oid->SQL3 tyoe mapping available.
1 parent 43a9a2f commit cf4d9c4

File tree

5 files changed

+41
-47
lines changed

5 files changed

+41
-47
lines changed

src/interfaces/ecpg/ecpglib/typename.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.16 2010/01/05 16:38:23 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.17 2010/01/13 08:41:48 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -98,7 +98,7 @@ ecpg_dynamic_type(Oid type)
9898
case NUMERICOID:
9999
return SQL3_NUMERIC; /* numeric */
100100
default:
101-
return -(int) type;
101+
return 0;
102102
}
103103
}
104104

src/interfaces/ecpg/test/expected/sql-dyntest.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,7 @@ if (sqlca.sqlcode < 0) error ( );}
385385
printf ("varchar()");
386386
break;
387387
default:
388-
if (TYPE < 0)
389-
printf ("<OID %d>", -TYPE);
390-
else
391-
printf ("<SQL3 %d>", TYPE);
388+
printf ("<SQL3 %d>", TYPE);
392389
break;
393390
}
394391
printf (")\n\toctet_length: %d returned_octet_length: %d)\n\t= ",
@@ -402,10 +399,10 @@ if (sqlca.sqlcode < 0) error ( );}
402399
{ ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
403400
ECPGt_bool,&(BOOLVAR),(long)1,(long)1,sizeof(bool), ECPGd_EODT);
404401

405-
#line 166 "dyntest.pgc"
402+
#line 163 "dyntest.pgc"
406403

407404
if (sqlca.sqlcode < 0) error ( );}
408-
#line 166 "dyntest.pgc"
405+
#line 163 "dyntest.pgc"
409406

410407
printf ("%s\n", BOOLVAR ? "true" : "false");
411408
break;
@@ -414,21 +411,21 @@ if (sqlca.sqlcode < 0) error ( );}
414411
{ ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
415412
ECPGt_int,&(INTVAR),(long)1,(long)1,sizeof(int), ECPGd_EODT);
416413

417-
#line 171 "dyntest.pgc"
414+
#line 168 "dyntest.pgc"
418415

419416
if (sqlca.sqlcode < 0) error ( );}
420-
#line 171 "dyntest.pgc"
417+
#line 168 "dyntest.pgc"
421418

422419
printf ("%d\n", INTVAR);
423420
break;
424421
case SQL3_DOUBLE_PRECISION:
425422
{ ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
426423
ECPGt_double,&(DOUBLEVAR),(long)1,(long)1,sizeof(double), ECPGd_EODT);
427424

428-
#line 175 "dyntest.pgc"
425+
#line 172 "dyntest.pgc"
429426

430427
if (sqlca.sqlcode < 0) error ( );}
431-
#line 175 "dyntest.pgc"
428+
#line 172 "dyntest.pgc"
432429

433430
printf ("%.*f\n", PRECISION, DOUBLEVAR);
434431
break;
@@ -437,10 +434,10 @@ if (sqlca.sqlcode < 0) error ( );}
437434
ECPGt_char,(STRINGVAR),(long)1024,(long)1,(1024)*sizeof(char), ECPGd_di_code,
438435
ECPGt_int,&(DATETIME_INTERVAL_CODE),(long)1,(long)1,sizeof(int), ECPGd_EODT);
439436

440-
#line 181 "dyntest.pgc"
437+
#line 178 "dyntest.pgc"
441438

442439
if (sqlca.sqlcode < 0) error ( );}
443-
#line 181 "dyntest.pgc"
440+
#line 178 "dyntest.pgc"
444441

445442
printf ("%d \"%s\"\n", DATETIME_INTERVAL_CODE, STRINGVAR);
446443
break;
@@ -449,21 +446,21 @@ if (sqlca.sqlcode < 0) error ( );}
449446
{ ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
450447
ECPGt_char,(STRINGVAR),(long)1024,(long)1,(1024)*sizeof(char), ECPGd_EODT);
451448

452-
#line 186 "dyntest.pgc"
449+
#line 183 "dyntest.pgc"
453450

454451
if (sqlca.sqlcode < 0) error ( );}
455-
#line 186 "dyntest.pgc"
452+
#line 183 "dyntest.pgc"
456453

457454
printf ("\"%s\"\n", STRINGVAR);
458455
break;
459456
default:
460457
{ ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
461458
ECPGt_char,(STRINGVAR),(long)1024,(long)1,(1024)*sizeof(char), ECPGd_EODT);
462459

463-
#line 190 "dyntest.pgc"
460+
#line 187 "dyntest.pgc"
464461

465462
if (sqlca.sqlcode < 0) error ( );}
466-
#line 190 "dyntest.pgc"
463+
#line 187 "dyntest.pgc"
467464

468465
printf ("<\"%s\">\n", STRINGVAR);
469466
break;
@@ -472,17 +469,17 @@ if (sqlca.sqlcode < 0) error ( );}
472469
}
473470

474471
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close MYCURS", ECPGt_EOIT, ECPGt_EORT);
475-
#line 197 "dyntest.pgc"
472+
#line 194 "dyntest.pgc"
476473

477474
if (sqlca.sqlcode < 0) error ( );}
478-
#line 197 "dyntest.pgc"
475+
#line 194 "dyntest.pgc"
479476

480477

481478
ECPGdeallocate_desc(__LINE__, "MYDESC");
482-
#line 199 "dyntest.pgc"
479+
#line 196 "dyntest.pgc"
483480

484481
if (sqlca.sqlcode < 0) error ( );
485-
#line 199 "dyntest.pgc"
482+
#line 196 "dyntest.pgc"
486483

487484

488485
return 0;

src/interfaces/ecpg/test/expected/sql-dyntest.stderr

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
[NO_PID]: sqlca: code: 0, state: 00000
6565
[NO_PID]: ECPGget_desc: reading items for tuple 1
6666
[NO_PID]: sqlca: code: 0, state: 00000
67-
[NO_PID]: ecpg_get_data on line 186: RESULT: first entry offset: -1; array: yes
67+
[NO_PID]: ecpg_get_data on line 183: RESULT: first entry offset: -1; array: yes
6868
[NO_PID]: sqlca: code: 0, state: 00000
6969
[NO_PID]: ECPGget_desc: reading items for tuple 2
7070
[NO_PID]: sqlca: code: 0, state: 00000
@@ -86,7 +86,7 @@
8686
[NO_PID]: sqlca: code: 0, state: 00000
8787
[NO_PID]: ECPGget_desc: reading items for tuple 2
8888
[NO_PID]: sqlca: code: 0, state: 00000
89-
[NO_PID]: ecpg_get_data on line 175: RESULT: 14.7 offset: -1; array: yes
89+
[NO_PID]: ecpg_get_data on line 172: RESULT: 14.7 offset: -1; array: yes
9090
[NO_PID]: sqlca: code: 0, state: 00000
9191
[NO_PID]: ECPGget_desc: reading items for tuple 3
9292
[NO_PID]: sqlca: code: 0, state: 00000
@@ -108,7 +108,7 @@
108108
[NO_PID]: sqlca: code: 0, state: 00000
109109
[NO_PID]: ECPGget_desc: reading items for tuple 3
110110
[NO_PID]: sqlca: code: 0, state: 00000
111-
[NO_PID]: ecpg_get_data on line 171: RESULT: 14 offset: -1; array: yes
111+
[NO_PID]: ecpg_get_data on line 168: RESULT: 14 offset: -1; array: yes
112112
[NO_PID]: sqlca: code: 0, state: 00000
113113
[NO_PID]: ECPGget_desc: reading items for tuple 4
114114
[NO_PID]: sqlca: code: 0, state: 00000
@@ -124,13 +124,13 @@
124124
[NO_PID]: sqlca: code: 0, state: 00000
125125
[NO_PID]: ECPGget_desc: LENGTH = -5
126126
[NO_PID]: sqlca: code: 0, state: 00000
127-
[NO_PID]: ECPGget_desc: TYPE = -20
127+
[NO_PID]: ECPGget_desc: TYPE = 0
128128
[NO_PID]: sqlca: code: 0, state: 00000
129129
[NO_PID]: ECPGget_desc: INDICATOR[0] = 0
130130
[NO_PID]: sqlca: code: 0, state: 00000
131131
[NO_PID]: ECPGget_desc: reading items for tuple 4
132132
[NO_PID]: sqlca: code: 0, state: 00000
133-
[NO_PID]: ecpg_get_data on line 190: RESULT: 123045607890 offset: -1; array: yes
133+
[NO_PID]: ecpg_get_data on line 187: RESULT: 123045607890 offset: -1; array: yes
134134
[NO_PID]: sqlca: code: 0, state: 00000
135135
[NO_PID]: ECPGget_desc: reading items for tuple 5
136136
[NO_PID]: sqlca: code: 0, state: 00000
@@ -152,7 +152,7 @@
152152
[NO_PID]: sqlca: code: 0, state: 00000
153153
[NO_PID]: ECPGget_desc: reading items for tuple 5
154154
[NO_PID]: sqlca: code: 0, state: 00000
155-
[NO_PID]: ecpg_get_data on line 166: RESULT: t offset: -1; array: yes
155+
[NO_PID]: ecpg_get_data on line 163: RESULT: t offset: -1; array: yes
156156
[NO_PID]: sqlca: code: 0, state: 00000
157157
[NO_PID]: ECPGget_desc: reading items for tuple 6
158158
[NO_PID]: sqlca: code: 0, state: 00000
@@ -174,7 +174,7 @@
174174
[NO_PID]: sqlca: code: 0, state: 00000
175175
[NO_PID]: ECPGget_desc: reading items for tuple 6
176176
[NO_PID]: sqlca: code: 0, state: 00000
177-
[NO_PID]: ecpg_get_data on line 186: RESULT: The world's most advanced open source database. offset: -1; array: yes
177+
[NO_PID]: ecpg_get_data on line 183: RESULT: The world's most advanced open source database. offset: -1; array: yes
178178
[NO_PID]: sqlca: code: 0, state: 00000
179179
[NO_PID]: ECPGget_desc: reading items for tuple 7
180180
[NO_PID]: sqlca: code: 0, state: 00000
@@ -202,7 +202,7 @@
202202
[NO_PID]: sqlca: code: 0, state: 00000
203203
[NO_PID]: ECPGget_desc: TYPE = 1
204204
[NO_PID]: sqlca: code: 0, state: 00000
205-
[NO_PID]: ecpg_get_data on line 179: RESULT: 14.07.1987 offset: -1; array: yes
205+
[NO_PID]: ecpg_get_data on line 176: RESULT: 14.07.1987 offset: -1; array: yes
206206
[NO_PID]: sqlca: code: 0, state: 00000
207207
[NO_PID]: ecpg_execute on line 64: query: fetch in MYCURS; with 0 parameter(s) on connection regress1
208208
[NO_PID]: sqlca: code: 0, state: 00000
@@ -234,7 +234,7 @@
234234
[NO_PID]: sqlca: code: 0, state: 00000
235235
[NO_PID]: ECPGget_desc: reading items for tuple 1
236236
[NO_PID]: sqlca: code: 0, state: 00000
237-
[NO_PID]: ecpg_get_data on line 186: RESULT: second entry offset: -1; array: yes
237+
[NO_PID]: ecpg_get_data on line 183: RESULT: second entry offset: -1; array: yes
238238
[NO_PID]: sqlca: code: 0, state: 00000
239239
[NO_PID]: ECPGget_desc: reading items for tuple 2
240240
[NO_PID]: sqlca: code: 0, state: 00000
@@ -256,7 +256,7 @@
256256
[NO_PID]: sqlca: code: 0, state: 00000
257257
[NO_PID]: ECPGget_desc: reading items for tuple 2
258258
[NO_PID]: sqlca: code: 0, state: 00000
259-
[NO_PID]: ecpg_get_data on line 175: RESULT: 1407.87 offset: -1; array: yes
259+
[NO_PID]: ecpg_get_data on line 172: RESULT: 1407.87 offset: -1; array: yes
260260
[NO_PID]: sqlca: code: 0, state: 00000
261261
[NO_PID]: ECPGget_desc: reading items for tuple 3
262262
[NO_PID]: sqlca: code: 0, state: 00000
@@ -278,7 +278,7 @@
278278
[NO_PID]: sqlca: code: 0, state: 00000
279279
[NO_PID]: ECPGget_desc: reading items for tuple 3
280280
[NO_PID]: sqlca: code: 0, state: 00000
281-
[NO_PID]: ecpg_get_data on line 171: RESULT: 1407 offset: -1; array: yes
281+
[NO_PID]: ecpg_get_data on line 168: RESULT: 1407 offset: -1; array: yes
282282
[NO_PID]: sqlca: code: 0, state: 00000
283283
[NO_PID]: ECPGget_desc: reading items for tuple 4
284284
[NO_PID]: sqlca: code: 0, state: 00000
@@ -294,13 +294,13 @@
294294
[NO_PID]: sqlca: code: 0, state: 00000
295295
[NO_PID]: ECPGget_desc: LENGTH = -5
296296
[NO_PID]: sqlca: code: 0, state: 00000
297-
[NO_PID]: ECPGget_desc: TYPE = -20
297+
[NO_PID]: ECPGget_desc: TYPE = 0
298298
[NO_PID]: sqlca: code: 0, state: 00000
299299
[NO_PID]: ECPGget_desc: INDICATOR[0] = 0
300300
[NO_PID]: sqlca: code: 0, state: 00000
301301
[NO_PID]: ECPGget_desc: reading items for tuple 4
302302
[NO_PID]: sqlca: code: 0, state: 00000
303-
[NO_PID]: ecpg_get_data on line 190: RESULT: 987065403210 offset: -1; array: yes
303+
[NO_PID]: ecpg_get_data on line 187: RESULT: 987065403210 offset: -1; array: yes
304304
[NO_PID]: sqlca: code: 0, state: 00000
305305
[NO_PID]: ECPGget_desc: reading items for tuple 5
306306
[NO_PID]: sqlca: code: 0, state: 00000
@@ -322,7 +322,7 @@
322322
[NO_PID]: sqlca: code: 0, state: 00000
323323
[NO_PID]: ECPGget_desc: reading items for tuple 5
324324
[NO_PID]: sqlca: code: 0, state: 00000
325-
[NO_PID]: ecpg_get_data on line 166: RESULT: f offset: -1; array: yes
325+
[NO_PID]: ecpg_get_data on line 163: RESULT: f offset: -1; array: yes
326326
[NO_PID]: sqlca: code: 0, state: 00000
327327
[NO_PID]: ECPGget_desc: reading items for tuple 6
328328
[NO_PID]: sqlca: code: 0, state: 00000
@@ -344,7 +344,7 @@
344344
[NO_PID]: sqlca: code: 0, state: 00000
345345
[NO_PID]: ECPGget_desc: reading items for tuple 6
346346
[NO_PID]: sqlca: code: 0, state: 00000
347-
[NO_PID]: ecpg_get_data on line 186: RESULT: The elephant never forgets. offset: -1; array: yes
347+
[NO_PID]: ecpg_get_data on line 183: RESULT: The elephant never forgets. offset: -1; array: yes
348348
[NO_PID]: sqlca: code: 0, state: 00000
349349
[NO_PID]: ECPGget_desc: reading items for tuple 7
350350
[NO_PID]: sqlca: code: 0, state: 00000
@@ -372,7 +372,7 @@
372372
[NO_PID]: sqlca: code: 0, state: 00000
373373
[NO_PID]: ECPGget_desc: TYPE = 1
374374
[NO_PID]: sqlca: code: 0, state: 00000
375-
[NO_PID]: ecpg_get_data on line 179: RESULT: 05.11.1999 offset: -1; array: yes
375+
[NO_PID]: ecpg_get_data on line 176: RESULT: 05.11.1999 offset: -1; array: yes
376376
[NO_PID]: sqlca: code: 0, state: 00000
377377
[NO_PID]: ecpg_execute on line 64: query: fetch in MYCURS; with 0 parameter(s) on connection regress1
378378
[NO_PID]: sqlca: code: 0, state: 00000
@@ -382,9 +382,9 @@
382382
[NO_PID]: sqlca: code: 0, state: 00000
383383
[NO_PID]: raising sqlcode 100 on line 64: no data found on line 64
384384
[NO_PID]: sqlca: code: 100, state: 02000
385-
[NO_PID]: ecpg_execute on line 197: query: close MYCURS; with 0 parameter(s) on connection regress1
385+
[NO_PID]: ecpg_execute on line 194: query: close MYCURS; with 0 parameter(s) on connection regress1
386386
[NO_PID]: sqlca: code: 0, state: 00000
387-
[NO_PID]: ecpg_execute on line 197: using PQexec
387+
[NO_PID]: ecpg_execute on line 194: using PQexec
388388
[NO_PID]: sqlca: code: 0, state: 00000
389-
[NO_PID]: ecpg_execute on line 197: OK: CLOSE CURSOR
389+
[NO_PID]: ecpg_execute on line 194: OK: CLOSE CURSOR
390390
[NO_PID]: sqlca: code: 0, state: 00000

src/interfaces/ecpg/test/expected/sql-dyntest.stdout

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Found 7 columns
88
3 i (type: 4 length: -5 precision: -1 scale: 65531 = integer)
99
octet_length: 4 returned_octet_length: 2)
1010
= 14
11-
4 bignumber (type: -20 length: -5 precision: -1 scale: 65531 = <OID 20>)
11+
4 bignumber (type: 0 length: -5 precision: -1 scale: 65531 = <SQL3 0>)
1212
octet_length: 8 returned_octet_length: 12)
1313
= <"123045607890">
1414
5 b (type: 16 length: -5 precision: -1 scale: 65531 = bool)
@@ -29,7 +29,7 @@ Found 7 columns
2929
3 i (type: 4 length: -5 precision: -1 scale: 65531 = integer)
3030
octet_length: 4 returned_octet_length: 4)
3131
= 1407
32-
4 bignumber (type: -20 length: -5 precision: -1 scale: 65531 = <OID 20>)
32+
4 bignumber (type: 0 length: -5 precision: -1 scale: 65531 = <SQL3 0>)
3333
octet_length: 8 returned_octet_length: 12)
3434
= <"987065403210">
3535
5 b (type: 16 length: -5 precision: -1 scale: 65531 = bool)

src/interfaces/ecpg/test/sql/dyntest.pgc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,7 @@ main ()
149149
printf ("varchar()");
150150
break;
151151
default:
152-
if (TYPE < 0)
153-
printf ("<OID %d>", -TYPE);
154-
else
155-
printf ("<SQL3 %d>", TYPE);
152+
printf ("<SQL3 %d>", TYPE);
156153
break;
157154
}
158155
printf (")\n\toctet_length: %d returned_octet_length: %d)\n\t= ",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy