aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/test/expected/compat_oracle-char_array.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2023-04-18 11:20:47 +0900
committerMichael Paquier <michael@paquier.xyz>2023-04-18 11:20:47 +0900
commit8c746be44002e8f95dcf8e98f58a47ac851563ee (patch)
treedf033fa375860353f7896bde0b8a79fec2560f26 /src/interfaces/ecpg/test/expected/compat_oracle-char_array.c
parent2207df7c34bfcecec33da2a47068e94d7882ffdb (diff)
downloadpostgresql-8c746be44002e8f95dcf8e98f58a47ac851563ee.tar.gz
postgresql-8c746be44002e8f95dcf8e98f58a47ac851563ee.zip
ecpg: Fix handling of strings in ORACLE compat code with SQLDA
When compiled with -C ORACLE, ecpg_get_data() had a one-off issue where it would incorrectly store the null terminator byte to str[-1] when varcharsize is 0, which is something that can happen when using SQLDA. This would eat 1 byte from the previous field stored, corrupting the results generated. All the callers of ecpg_get_data() estimate and allocate enough storage for the data received, and the fix of this commit relies on this assumption. Note that this maps to the case where no padding or truncation is required. This issue has been introduced by 3b7ab43 with the Oracle compatibility option, so backpatch down to v11. Author: Kyotaro Horiguchi Discussion: https://postgr.es/m/20230410.173500.440060475837236886.horikyota.ntt@gmail.com Backpatch-through: 11
Diffstat (limited to 'src/interfaces/ecpg/test/expected/compat_oracle-char_array.c')
-rw-r--r--src/interfaces/ecpg/test/expected/compat_oracle-char_array.c216
1 files changed, 160 insertions, 56 deletions
diff --git a/src/interfaces/ecpg/test/expected/compat_oracle-char_array.c b/src/interfaces/ecpg/test/expected/compat_oracle-char_array.c
index 04d4e1969e3..16db663dcc5 100644
--- a/src/interfaces/ecpg/test/expected/compat_oracle-char_array.c
+++ b/src/interfaces/ecpg/test/expected/compat_oracle-char_array.c
@@ -11,6 +11,32 @@
#include <stdlib.h>
#include <string.h>
+#include <pgtypes_numeric.h>
+
+
+#line 1 "sqlda.h"
+#ifndef ECPG_SQLDA_H
+#define ECPG_SQLDA_H
+
+#ifdef _ECPG_INFORMIX_H
+
+#include "sqlda-compat.h"
+typedef struct sqlvar_compat sqlvar_t;
+typedef struct sqlda_compat sqlda_t;
+
+#else
+
+#include "sqlda-native.h"
+typedef struct sqlvar_struct sqlvar_t;
+typedef struct sqlda_struct sqlda_t;
+
+#endif
+
+#endif /* ECPG_SQLDA_H */
+
+#line 7 "char_array.pgc"
+
+
#line 1 "regression.h"
@@ -19,7 +45,7 @@
-#line 5 "char_array.pgc"
+#line 9 "char_array.pgc"
static void warn(void)
@@ -34,125 +60,127 @@ static void warn(void)
int main() {
/* exec sql whenever sql_warning do warn ( ) ; */
-#line 18 "char_array.pgc"
+#line 22 "char_array.pgc"
/* exec sql whenever sqlerror stop ; */
-#line 19 "char_array.pgc"
+#line 23 "char_array.pgc"
const char *ppppp = "XXXXX";
int loopcount;
+ sqlda_t *sqlda = NULL;
+
/* exec sql begin declare section */
-#line 24 "char_array.pgc"
+#line 30 "char_array.pgc"
char shortstr [ 5 ] ;
-#line 25 "char_array.pgc"
+#line 31 "char_array.pgc"
char bigstr [ 11 ] ;
-#line 26 "char_array.pgc"
+#line 32 "char_array.pgc"
short shstr_ind = 0 ;
-#line 27 "char_array.pgc"
+#line 33 "char_array.pgc"
short bigstr_ind = 0 ;
/* exec sql end declare section */
-#line 28 "char_array.pgc"
+#line 34 "char_array.pgc"
ECPGdebug(1, stderr);
{ ECPGconnect(__LINE__, 3, "ecpg1_regression" , NULL, NULL , NULL, 0);
-#line 31 "char_array.pgc"
+#line 37 "char_array.pgc"
if (sqlca.sqlwarn[0] == 'W') warn ( );
-#line 31 "char_array.pgc"
+#line 37 "char_array.pgc"
if (sqlca.sqlcode < 0) exit (1);}
-#line 31 "char_array.pgc"
+#line 37 "char_array.pgc"
{ ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "create table strdbase ( strval varchar ( 10 ) )", ECPGt_EOIT, ECPGt_EORT);
-#line 33 "char_array.pgc"
+#line 39 "char_array.pgc"
if (sqlca.sqlwarn[0] == 'W') warn ( );
-#line 33 "char_array.pgc"
+#line 39 "char_array.pgc"
if (sqlca.sqlcode < 0) exit (1);}
-#line 33 "char_array.pgc"
+#line 39 "char_array.pgc"
{ ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( '' )", ECPGt_EOIT, ECPGt_EORT);
-#line 34 "char_array.pgc"
+#line 40 "char_array.pgc"
if (sqlca.sqlwarn[0] == 'W') warn ( );
-#line 34 "char_array.pgc"
+#line 40 "char_array.pgc"
if (sqlca.sqlcode < 0) exit (1);}
-#line 34 "char_array.pgc"
+#line 40 "char_array.pgc"
{ ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'AB' )", ECPGt_EOIT, ECPGt_EORT);
-#line 35 "char_array.pgc"
+#line 41 "char_array.pgc"
if (sqlca.sqlwarn[0] == 'W') warn ( );
-#line 35 "char_array.pgc"
+#line 41 "char_array.pgc"
if (sqlca.sqlcode < 0) exit (1);}
-#line 35 "char_array.pgc"
+#line 41 "char_array.pgc"
{ ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'ABCD' )", ECPGt_EOIT, ECPGt_EORT);
-#line 36 "char_array.pgc"
+#line 42 "char_array.pgc"
if (sqlca.sqlwarn[0] == 'W') warn ( );
-#line 36 "char_array.pgc"
+#line 42 "char_array.pgc"
if (sqlca.sqlcode < 0) exit (1);}
-#line 36 "char_array.pgc"
+#line 42 "char_array.pgc"
{ ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'ABCDE' )", ECPGt_EOIT, ECPGt_EORT);
-#line 37 "char_array.pgc"
+#line 43 "char_array.pgc"
if (sqlca.sqlwarn[0] == 'W') warn ( );
-#line 37 "char_array.pgc"
+#line 43 "char_array.pgc"
if (sqlca.sqlcode < 0) exit (1);}
-#line 37 "char_array.pgc"
+#line 43 "char_array.pgc"
{ ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'ABCDEF' )", ECPGt_EOIT, ECPGt_EORT);
-#line 38 "char_array.pgc"
+#line 44 "char_array.pgc"
if (sqlca.sqlwarn[0] == 'W') warn ( );
-#line 38 "char_array.pgc"
+#line 44 "char_array.pgc"
if (sqlca.sqlcode < 0) exit (1);}
-#line 38 "char_array.pgc"
+#line 44 "char_array.pgc"
{ ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'ABCDEFGHIJ' )", ECPGt_EOIT, ECPGt_EORT);
-#line 39 "char_array.pgc"
+#line 45 "char_array.pgc"
if (sqlca.sqlwarn[0] == 'W') warn ( );
-#line 39 "char_array.pgc"
+#line 45 "char_array.pgc"
if (sqlca.sqlcode < 0) exit (1);}
-#line 39 "char_array.pgc"
+#line 45 "char_array.pgc"
/* declare C cursor for select strval , strval from strdbase */
-#line 41 "char_array.pgc"
+#line 47 "char_array.pgc"
{ ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "declare C cursor for select strval , strval from strdbase", ECPGt_EOIT, ECPGt_EORT);
-#line 42 "char_array.pgc"
+#line 48 "char_array.pgc"
if (sqlca.sqlwarn[0] == 'W') warn ( );
-#line 42 "char_array.pgc"
+#line 48 "char_array.pgc"
if (sqlca.sqlcode < 0) exit (1);}
-#line 42 "char_array.pgc"
+#line 48 "char_array.pgc"
/* exec sql whenever not found break ; */
-#line 44 "char_array.pgc"
+#line 50 "char_array.pgc"
printf("Full Str. : Short Ind.\n");
@@ -164,59 +192,135 @@ if (sqlca.sqlcode < 0) exit (1);}
ECPGt_short,&(bigstr_ind),(long)1,(long)1,sizeof(short),
ECPGt_char,(shortstr),(long)5,(long)1,(5)*sizeof(char),
ECPGt_short,&(shstr_ind),(long)1,(long)1,sizeof(short), ECPGt_EORT);
-#line 50 "char_array.pgc"
+#line 56 "char_array.pgc"
if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
-#line 50 "char_array.pgc"
+#line 56 "char_array.pgc"
if (sqlca.sqlwarn[0] == 'W') warn ( );
-#line 50 "char_array.pgc"
+#line 56 "char_array.pgc"
if (sqlca.sqlcode < 0) exit (1);}
-#line 50 "char_array.pgc"
+#line 56 "char_array.pgc"
printf("\"%s\": \"%s\" %d\n", bigstr, shortstr, shstr_ind);
}
{ ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "close C", ECPGt_EOIT, ECPGt_EORT);
-#line 54 "char_array.pgc"
+#line 60 "char_array.pgc"
if (sqlca.sqlwarn[0] == 'W') warn ( );
-#line 54 "char_array.pgc"
+#line 60 "char_array.pgc"
if (sqlca.sqlcode < 0) exit (1);}
-#line 54 "char_array.pgc"
+#line 60 "char_array.pgc"
{ ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "drop table strdbase", ECPGt_EOIT, ECPGt_EORT);
-#line 55 "char_array.pgc"
+#line 61 "char_array.pgc"
if (sqlca.sqlwarn[0] == 'W') warn ( );
-#line 55 "char_array.pgc"
+#line 61 "char_array.pgc"
if (sqlca.sqlcode < 0) exit (1);}
-#line 55 "char_array.pgc"
+#line 61 "char_array.pgc"
+ { ECPGtrans(__LINE__, NULL, "commit work");
+#line 62 "char_array.pgc"
- printf("\nGOOD-BYE!!\n\n");
+if (sqlca.sqlwarn[0] == 'W') warn ( );
+#line 62 "char_array.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 62 "char_array.pgc"
+
+
+ /* SQLDA handling */
+ /* exec sql whenever sql_warning sqlprint ; */
+#line 65 "char_array.pgc"
+
+ /* exec sql whenever not found stop ; */
+#line 66 "char_array.pgc"
+
+ { ECPGprepare(__LINE__, NULL, 0, "stmt1", "SELECT 123::numeric(3,0), 't'::varchar(2)");
+#line 67 "char_array.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 67 "char_array.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 67 "char_array.pgc"
+
+ /* declare cur1 cursor for $1 */
+#line 68 "char_array.pgc"
+
+ { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "declare cur1 cursor for $1",
+ ECPGt_char_variable,(ECPGprepared_statement(NULL, "stmt1", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
+ ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+#line 69 "char_array.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 69 "char_array.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 69 "char_array.pgc"
+
+ { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "fetch next from cur1", ECPGt_EOIT,
+ ECPGt_sqlda, &sqlda, 0L, 0L, 0L,
+ ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
+#line 70 "char_array.pgc"
+
+if (sqlca.sqlcode == ECPG_NOT_FOUND) exit (1);
+#line 70 "char_array.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 70 "char_array.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 70 "char_array.pgc"
+
+
+ printf("\n-----------------\ntype : data\n");
+ for (int i = 0 ; i < sqlda->sqld ; i++)
+ {
+ sqlvar_t v = sqlda->sqlvar[i];
+ char *sqldata = v.sqldata;
+
+ if (v.sqltype == ECPGt_numeric)
+ sqldata =
+ PGTYPESnumeric_to_asc((numeric*) sqlda->sqlvar[i].sqldata, -1);
+
+ printf("%-8s: \"%s\"\n", v.sqlname.data, sqldata);
+ }
+
+ { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "close cur1", ECPGt_EOIT, ECPGt_EORT);
+#line 85 "char_array.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 85 "char_array.pgc"
+
+if (sqlca.sqlcode < 0) exit (1);}
+#line 85 "char_array.pgc"
{ ECPGtrans(__LINE__, NULL, "commit work");
-#line 59 "char_array.pgc"
+#line 86 "char_array.pgc"
-if (sqlca.sqlwarn[0] == 'W') warn ( );
-#line 59 "char_array.pgc"
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 86 "char_array.pgc"
if (sqlca.sqlcode < 0) exit (1);}
-#line 59 "char_array.pgc"
+#line 86 "char_array.pgc"
+ printf("\nGOOD-BYE!!\n\n");
+
{ ECPGdisconnect(__LINE__, "ALL");
-#line 61 "char_array.pgc"
+#line 90 "char_array.pgc"
-if (sqlca.sqlwarn[0] == 'W') warn ( );
-#line 61 "char_array.pgc"
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 90 "char_array.pgc"
if (sqlca.sqlcode < 0) exit (1);}
-#line 61 "char_array.pgc"
+#line 90 "char_array.pgc"
return 0;