8000 Make sure ecpglib does accepts digits behind decimal point even for i… · koderP/postgres@d64a4d3 · GitHub
[go: up one dir, main page]

Skip to content

Commit d64a4d3

Browse files
author
Michael Meskes
committed
Make sure ecpglib does accepts digits behind decimal point even for integers in
Informix mode. Spotted and fixed by 高增琦 <pgf00a@gmail.com>
1 parent e06b9e9 commit d64a4d3

File tree

1 file changed

+19
-13
lines changed
  • src/interfaces/ecpg/ecpglib

1 file changed

+19
-13
lines changed

src/interfaces/ecpg/ecpglib/data.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,27 @@ array_boundary(enum ARRAY_TYPE isarray, char c)
4646

4747
/* returns true if some garbage is found at the end of the scanned string */
4848
static bool
49-
garbage_left(enum ARRAY_TYPE isarray, char *scan_length, enum COMPAT_MODE compat)
49+
garbage_left(enum ARRAY_TYPE isarray, char **scan_length, enum COMPAT_MODE compat)
5050
{
5151
/*
5252
* INFORMIX allows for selecting a numeric into an int, the result is
5353
* truncated
5454
*/
5555
if (isarray == ECPG_ARRAY_NONE)
5656
{
57-
if (INFORMIX_MODE(compat) && *scan_length == '.')
57+
if (INFORMIX_MODE(compat) && **scan_length == '.')
58+
{
59+
/* skip invalid characters */
60+
do {
61+
(*scan_length)++;
62+
} while (**scan_length != ' ' && **scan_length != '\0' && isdigit(**scan_length));
5863
return false;
64+
}
5965

60-
if (*scan_length != ' ' && *scan_length != '\0')
66+
if (**scan_length != ' ' && **scan_length != '\0')
6167
return true;
6268
}
63-
else if (ECPG_IS_ARRAY(isarray) && !array_delimiter(isarray, *scan_length) && !array_boundary(isarray, *scan_length))
69+
else if (ECPG_IS_ARRAY(isarray) && !array_delimiter(isarray, **scan_length) && !array_boundary(isarray, **scan_length))
6470
return true;
6571

6672
return false;
@@ -304,7 +310,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
304310
case ECPGt_int:
305311
case ECPGt_long:
306312
res = strtol(pval, &scan_length, 10);
307-
if (garbage_left(isarray, scan_length, compat))
313+
if (garbage_left(isarray, &scan_length, compat))
308314
{
309315
ecpg_raise(lineno, ECPG_INT_FORMAT,
310316
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
@@ -333,7 +339,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
333339
case ECPGt_unsigned_int:
334340
case ECPGt_unsigned_long:
335341
ures = strtoul(pval, &scan_length, 10);
336-
if (garbage_left(isarray, scan_length, compat))
342+
if (garbage_left(isarray, &scan_length, compat))
337343
{
338344
ecpg_raise(lineno, ECPG_UINT_FORMAT,
339345
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
@@ -362,7 +368,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
362368
#ifdef HAVE_STRTOLL
363369
case ECPGt_long_long:
364370
*((long long int *) (var + offset * act_tuple)) = strtoll(pval, &scan_length, 10);
365-
if (garbage_left(isarray, scan_length, compat))
371+
if (garbage_left(isarray, &scan_length, compat))
366372
{
367373
ecpg_raise(lineno, ECPG_INT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
368374
return (false);
@@ -374,7 +380,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
374380
#ifdef HAVE_STRTOULL
375381
case ECPGt_unsigned_long_long:
376382
*((unsigned long long int *) (var + offset * act_tuple)) = strtoull(pval, &scan_length, 10);
377-
if (garbage_left(isarray, scan_length, compat))
383+
if (garbage_left(isarray, &scan_length, compat))
378384
{
379385
ecpg_raise(lineno, ECPG_UINT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
380386
return (false);
@@ -396,7 +402,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
396402
if (isarray && *scan_length == '"')
397403
scan_length++;
398404

399-
if (garbage_left(isarray, scan_length, compat))
405+
if (garbage_left(isarray, &scan_length, compat))
400406
{
401407
ecpg_raise(lineno, ECPG_FLOAT_FORMAT,
402408
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
@@ -594,7 +600,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
594600
}
595601
else
596602
{
597-
if (!isarray && garbage_left(isarray, scan_length, compat))
603+
if (!isarray && garbage_left(isarray, &scan_length, compat))
598604
{
599605
free(nres);
600606
ecpg_raise(lineno, ECPG_NUMERIC_FORMAT,
@@ -652,7 +658,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
652658
if (*scan_length == '"')
653659
scan_length++;
654660

655-
if (!isarray && garbage_left(isarray, scan_length, compat))
661+
if (!isarray && garbage_left(isarray, &scan_length, compat))
656662
{
657663
free(ires);
658664
ecpg_raise(lineno, ECPG_INTERVAL_FORMAT,
@@ -702,7 +708,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
702708
if (*scan_length == '"')
703709
scan_length++;
704710

705-
if (!isarray && garbage_left(isarray, scan_length, compat))
711+
if (!isarray && garbage_left(isarray, &scan_length, compat))
706712
{
707713
ecpg_raise(lineno, ECPG_DATE_FORMAT,
708714
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
@@ -750,7 +756,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
750756
if (*scan_length == '"')
751757
scan_length++;
752758

753-
if (!isarray && garbage_left(isarray, scan_length, compat))
759+
if (!isarray && garbage_left(isarray, &scan_length, compat))
754760
{
755761
ecpg_raise(lineno, ECPG_TIMESTAMP_FORMAT,
756762
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);

0 commit comments

Comments
 (0)
0