Skip to content

Commit 8775831

Browse files
author
Michael Meskes
committed
Made sure an internal array is not treated as a user defined one.
1 parent 449593a commit 8775831

File tree

4 files changed

+172
-118
lines changed

4 files changed

+172
-118
lines changed

src/interfaces/ecpg/ecpglib/data.c

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.20 2003/09/20 09:10:09 meskes Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.21 2003/11/08 19:46:27 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -16,21 +16,39 @@
1616
#include "pgtypes_timestamp.h"
1717
#include "pgtypes_interval.h"
1818

19+
static bool garbage_left(enum ARRAY_TYPE isarray, char *scan_length, enum COMPAT_MODE compat)
20+
{
21+
/* INFORMIX allows for selecting a numeric into an int, the result is truncated */
22+
if (isarray == ECPG_ARRAY_NONE && INFORMIX_MODE(compat) && *scan_length == '.')
23+
return false;
24+
25+
if (isarray == ECPG_ARRAY_ARRAY && *scan_length != ',' && *scan_length != '}')
26+
return true;
27+
28+
if (isarray == ECPG_ARRAY_VECTOR && *scan_length != ' ' && *scan_length != '\0')
29+
return true;
30+
31+
if (isarray == ECPG_ARRAY_NONE && *scan_length != ' ' && *scan_length != '\0')
32+
return true;
33+
34+
return false;
35+
}
36+
1937
bool
2038
ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
2139
enum ECPGttype type, enum ECPGttype ind_type,
2240
char *var, char *ind, long varcharsize, long offset,
23-
long ind_offset, bool isarray, enum COMPAT_MODE compat, bool force_indicator)
41+
long ind_offset, enum ARRAY_TYPE isarray, enum COMPAT_MODE compat, bool force_indicator)
2442
{
2543
struct sqlca_t *sqlca = ECPGget_sqlca();
2644
char *pval = (char *) PQgetvalue(results, act_tuple, act_field);
2745
int value_for_indicator = 0;
2846

29-
ECPGlog("ECPGget_data line %d: RESULT: %s offset: %ld\n", lineno, pval ? pval : "", offset);
47+
ECPGlog("ECPGget_data line %d: RESULT: %s offset: %ld array: %d\n", lineno, pval ? pval : "", offset, isarray);
3048

3149
/* pval is a pointer to the value */
32-
/* let's check is it really is an array if it should be one */
33-
if (isarray)
50+
/* let's check if it really is an array if it should be one */
51+
if (isarray == ECPG_ARRAY_ARRAY)
3452
{
3553
if (*pval != '{')
3654
{
@@ -126,9 +144,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
126144
if (pval)
127145
{
128146
res = strtol(pval, &scan_length, 10);
129-
/* INFORMIX allows for selecting a numeric into an int, the result is truncated */
130-
if ((isarray && *scan_length != ',' && *scan_length != '}')
131-
|| (!isarray && !(INFORMIX_MODE(compat) && *scan_length == '.') && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
147+
if (garbage_left(isarray, scan_length, compat))
132148
{
133149
ECPGraise(lineno, ECPG_INT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
134150
return (false);
@@ -160,8 +176,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
160176
if (pval)
161177
{
162178
ures = strtoul(pval, &scan_length, 10);
163-
if ((isarray && *scan_length != ',' && *scan_length != '}')
164-
|| (!isarray && !(INFORMIX_MODE(compat) && *scan_length == '.') && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
179+
if (garbage_left(isarray, scan_length, compat))
165180
{
166181
ECPGraise(lineno, ECPG_UINT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
167182
return (false);
@@ -193,8 +208,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
193208
if (pval)
194209
{
195210
*((long long int *) (var + offset * act_tuple)) = strtoll(pval, &scan_length, 10);
196-
if ((isarray && *scan_length != ',' && *scan_length != '}')
197-
|| (!isarray && !(INFORMIX_MODE(compat) && *scan_length == '.') && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
211+
if (garbage_left(isarray, scan_length, compat))
198212
{
199213
ECPGraise(lineno, ECPG_INT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
200214
return (false);
@@ -236,8 +250,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
236250
if (isarray && *scan_length == '"')
237251
scan_length++;
238252

239-
if ((isarray && *scan_length != ',' && *scan_length != '}')
240-
|| (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
253+
if (garbage_left(isarray, scan_length, compat))
241254
{
242255
ECPGraise(lineno, ECPG_FLOAT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
243256
return (false);
@@ -411,8 +424,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
411424
if (isarray && *scan_length == '"')
412425
scan_length++;
413426

414-
if ((isarray && *scan_length != ',' && *scan_length != '}')
415-
|| (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
427+
if (garbage_left(isarray, scan_length, compat))
416428
{
417429
ECPGraise(lineno, ECPG_NUMERIC_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
418430
return (false);
@@ -455,8 +467,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
455467
if (isarray && *scan_length == '"')
456468
scan_length++;
457469

458-
if ((isarray && *scan_length != ',' && *scan_length != '}')
459-
|| (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
470+
if (garbage_left(isarray, scan_length, compat))
460471
{
461472
ECPGraise(lineno, ECPG_INTERVAL_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
462473
return (false);
@@ -495,8 +506,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
495506
if (isarray && *scan_length == '"')
496507
scan_length++;
497508

498-
if ((isarray && *scan_length != ',' && *scan_length != '}')
499-
|| (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
509+
if (garbage_left(isarray, scan_length, compat))
500510
{
501511
ECPGraise(lineno, ECPG_DATE_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
502512
return (false);
@@ -534,8 +544,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
534544
if (isarray && *scan_length == '"')
535545
scan_length++;
536546

537-
if ((isarray && *scan_length != ',' && *scan_length != '}')
538-
|| (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
547+
if (garbage_left(isarray, scan_length, compat))
539548
{
540549
ECPGraise(lineno, ECPG_TIMESTAMP_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
541550
return (false);
@@ -551,7 +560,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
551560
return (false);
552561
break;
553562
}
554-
if (isarray)
563+
if (isarray == ECPG_ARRAY_ARRAY)
555564
{
556565
bool string = false;
557566

@@ -566,7 +575,22 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
566575
if (*pval == ',')
567576
++pval;
568577
}
569-
} while (isarray && *pval != '}');
578+
else if (isarray == ECPG_ARRAY_VECTOR)
579+
{
580+
bool string = false;
581+
582+
/* set array to next entry */
583+
++act_tuple;
584+
585+
/* set pval to the next entry */
586+
for (; string || (*pval != ' ' && *pval != '\0'); ++pval)
587+
if (*pval == '"')
588+
string = string ? false : true;
589+
590+
if (*pval == ' ')
591+
++pval;
592+
}
593+
} while ((isarray == ECPG_ARRAY_ARRAY && *pval != '}') || (isarray == ECPG_ARRAY_VECTOR && *pval != '\0'));
570594

571595
return (true);
572596
}

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