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.
This commit is contained in:
Michael Meskes 2010-01-13 08:41:50 +00:00
parent 43a9a2fb89
commit cf4d9c4772
5 changed files with 41 additions and 47 deletions

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.16 2010/01/05 16:38:23 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.17 2010/01/13 08:41:48 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@ -98,7 +98,7 @@ ecpg_dynamic_type(Oid type)
case NUMERICOID:
return SQL3_NUMERIC; /* numeric */
default:
return -(int) type;
return 0;
}
}

View File

@ -385,9 +385,6 @@ if (sqlca.sqlcode < 0) error ( );}
printf ("varchar()");
break;
default:
if (TYPE < 0)
printf ("<OID %d>", -TYPE);
else
printf ("<SQL3 %d>", TYPE);
break;
}
@ -402,10 +399,10 @@ if (sqlca.sqlcode < 0) error ( );}
{ ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
ECPGt_bool,&(BOOLVAR),(long)1,(long)1,sizeof(bool), ECPGd_EODT);
#line 166 "dyntest.pgc"
#line 163 "dyntest.pgc"
if (sqlca.sqlcode < 0) error ( );}
#line 166 "dyntest.pgc"
#line 163 "dyntest.pgc"
printf ("%s\n", BOOLVAR ? "true" : "false");
break;
@ -414,10 +411,10 @@ if (sqlca.sqlcode < 0) error ( );}
{ ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
ECPGt_int,&(INTVAR),(long)1,(long)1,sizeof(int), ECPGd_EODT);
#line 171 "dyntest.pgc"
#line 168 "dyntest.pgc"
if (sqlca.sqlcode < 0) error ( );}
#line 171 "dyntest.pgc"
#line 168 "dyntest.pgc"
printf ("%d\n", INTVAR);
break;
@ -425,10 +422,10 @@ if (sqlca.sqlcode < 0) error ( );}
{ ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
ECPGt_double,&(DOUBLEVAR),(long)1,(long)1,sizeof(double), ECPGd_EODT);
#line 175 "dyntest.pgc"
#line 172 "dyntest.pgc"
if (sqlca.sqlcode < 0) error ( );}
#line 175 "dyntest.pgc"
#line 172 "dyntest.pgc"
printf ("%.*f\n", PRECISION, DOUBLEVAR);
break;
@ -437,10 +434,10 @@ if (sqlca.sqlcode < 0) error ( );}
ECPGt_char,(STRINGVAR),(long)1024,(long)1,(1024)*sizeof(char), ECPGd_di_code,
ECPGt_int,&(DATETIME_INTERVAL_CODE),(long)1,(long)1,sizeof(int), ECPGd_EODT);
#line 181 "dyntest.pgc"
#line 178 "dyntest.pgc"
if (sqlca.sqlcode < 0) error ( );}
#line 181 "dyntest.pgc"
#line 178 "dyntest.pgc"
printf ("%d \"%s\"\n", DATETIME_INTERVAL_CODE, STRINGVAR);
break;
@ -449,10 +446,10 @@ if (sqlca.sqlcode < 0) error ( );}
{ ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
ECPGt_char,(STRINGVAR),(long)1024,(long)1,(1024)*sizeof(char), ECPGd_EODT);
#line 186 "dyntest.pgc"
#line 183 "dyntest.pgc"
if (sqlca.sqlcode < 0) error ( );}
#line 186 "dyntest.pgc"
#line 183 "dyntest.pgc"
printf ("\"%s\"\n", STRINGVAR);
break;
@ -460,10 +457,10 @@ if (sqlca.sqlcode < 0) error ( );}
{ ECPGget_desc(__LINE__, "MYDESC", INDEX,ECPGd_data,
ECPGt_char,(STRINGVAR),(long)1024,(long)1,(1024)*sizeof(char), ECPGd_EODT);
#line 190 "dyntest.pgc"
#line 187 "dyntest.pgc"
if (sqlca.sqlcode < 0) error ( );}
#line 190 "dyntest.pgc"
#line 187 "dyntest.pgc"
printf ("<\"%s\">\n", STRINGVAR);
break;
@ -472,17 +469,17 @@ if (sqlca.sqlcode < 0) error ( );}
}
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close MYCURS", ECPGt_EOIT, ECPGt_EORT);
#line 197 "dyntest.pgc"
#line 194 "dyntest.pgc"
if (sqlca.sqlcode < 0) error ( );}
#line 197 "dyntest.pgc"
#line 194 "dyntest.pgc"
ECPGdeallocate_desc(__LINE__, "MYDESC");
#line 199 "dyntest.pgc"
#line 196 "dyntest.pgc"
if (sqlca.sqlcode < 0) error ( );
#line 199 "dyntest.pgc"
#line 196 "dyntest.pgc"
return 0;

View File

@ -64,7 +64,7 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 186: RESULT: first entry offset: -1; array: yes
[NO_PID]: ecpg_get_data on line 183: RESULT: first entry offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 2
[NO_PID]: sqlca: code: 0, state: 00000
@ -86,7 +86,7 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 2
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 175: RESULT: 14.7 offset: -1; array: yes
[NO_PID]: ecpg_get_data on line 172: RESULT: 14.7 offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 3
[NO_PID]: sqlca: code: 0, state: 00000
@ -108,7 +108,7 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 3
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 171: RESULT: 14 offset: -1; array: yes
[NO_PID]: ecpg_get_data on line 168: RESULT: 14 offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 4
[NO_PID]: sqlca: code: 0, state: 00000
@ -124,13 +124,13 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: LENGTH = -5
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: TYPE = -20
[NO_PID]: ECPGget_desc: TYPE = 0
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: INDICATOR[0] = 0
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 4
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 190: RESULT: 123045607890 offset: -1; array: yes
[NO_PID]: ecpg_get_data on line 187: RESULT: 123045607890 offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 5
[NO_PID]: sqlca: code: 0, state: 00000
@ -152,7 +152,7 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 5
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 166: RESULT: t offset: -1; array: yes
[NO_PID]: ecpg_get_data on line 163: RESULT: t offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 6
[NO_PID]: sqlca: code: 0, state: 00000
@ -174,7 +174,7 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 6
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 186: RESULT: The world's most advanced open source database. offset: -1; array: yes
[NO_PID]: ecpg_get_data on line 183: RESULT: The world's most advanced open source database. offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 7
[NO_PID]: sqlca: code: 0, state: 00000
@ -202,7 +202,7 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: TYPE = 1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 179: RESULT: 14.07.1987 offset: -1; array: yes
[NO_PID]: ecpg_get_data on line 176: RESULT: 14.07.1987 offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 64: query: fetch in MYCURS; with 0 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
@ -234,7 +234,7 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 186: RESULT: second entry offset: -1; array: yes
[NO_PID]: ecpg_get_data on line 183: RESULT: second entry offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 2
[NO_PID]: sqlca: code: 0, state: 00000
@ -256,7 +256,7 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 2
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 175: RESULT: 1407.87 offset: -1; array: yes
[NO_PID]: ecpg_get_data on line 172: RESULT: 1407.87 offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 3
[NO_PID]: sqlca: code: 0, state: 00000
@ -278,7 +278,7 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 3
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 171: RESULT: 1407 offset: -1; array: yes
[NO_PID]: ecpg_get_data on line 168: RESULT: 1407 offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 4
[NO_PID]: sqlca: code: 0, state: 00000
@ -294,13 +294,13 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: LENGTH = -5
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: TYPE = -20
[NO_PID]: ECPGget_desc: TYPE = 0
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: INDICATOR[0] = 0
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 4
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 190: RESULT: 987065403210 offset: -1; array: yes
[NO_PID]: ecpg_get_data on line 187: RESULT: 987065403210 offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 5
[NO_PID]: sqlca: code: 0, state: 00000
@ -322,7 +322,7 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 5
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 166: RESULT: f offset: -1; array: yes
[NO_PID]: ecpg_get_data on line 163: RESULT: f offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 6
[NO_PID]: sqlca: code: 0, state: 00000
@ -344,7 +344,7 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 6
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 186: RESULT: The elephant never forgets. offset: -1; array: yes
[NO_PID]: ecpg_get_data on line 183: RESULT: The elephant never forgets. offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: reading items for tuple 7
[NO_PID]: sqlca: code: 0, state: 00000
@ -372,7 +372,7 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGget_desc: TYPE = 1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 179: RESULT: 05.11.1999 offset: -1; array: yes
[NO_PID]: ecpg_get_data on line 176: RESULT: 05.11.1999 offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 64: query: fetch in MYCURS; with 0 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
@ -382,9 +382,9 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: raising sqlcode 100 on line 64: no data found on line 64
[NO_PID]: sqlca: code: 100, state: 02000
[NO_PID]: ecpg_execute on line 197: query: close MYCURS; with 0 parameter(s) on connection regress1
[NO_PID]: ecpg_execute on line 194: query: close MYCURS; with 0 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 197: using PQexec
[NO_PID]: ecpg_execute on line 194: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 197: OK: CLOSE CURSOR
[NO_PID]: ecpg_execute on line 194: OK: CLOSE CURSOR
[NO_PID]: sqlca: code: 0, state: 00000

View File

@ -8,7 +8,7 @@ Found 7 columns
3 i (type: 4 length: -5 precision: -1 scale: 65531 = integer)
octet_length: 4 returned_octet_length: 2)
= 14
4 bignumber (type: -20 length: -5 precision: -1 scale: 65531 = <OID 20>)
4 bignumber (type: 0 length: -5 precision: -1 scale: 65531 = <SQL3 0>)
octet_length: 8 returned_octet_length: 12)
= <"123045607890">
5 b (type: 16 length: -5 precision: -1 scale: 65531 = bool)
@ -29,7 +29,7 @@ Found 7 columns
3 i (type: 4 length: -5 precision: -1 scale: 65531 = integer)
octet_length: 4 returned_octet_length: 4)
= 1407
4 bignumber (type: -20 length: -5 precision: -1 scale: 65531 = <OID 20>)
4 bignumber (type: 0 length: -5 precision: -1 scale: 65531 = <SQL3 0>)
octet_length: 8 returned_octet_length: 12)
= <"987065403210">
5 b (type: 16 length: -5 precision: -1 scale: 65531 = bool)

View File

@ -149,9 +149,6 @@ main ()
printf ("varchar()");
break;
default:
if (TYPE < 0)
printf ("<OID %d>", -TYPE);
else
printf ("<SQL3 %d>", TYPE);
break;
}