Skip to content

Commit e0ec1cb

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 f74f871 commit e0ec1cb

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;
@@ -305,7 +311,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
305311
case ECPGt_int:
306312
case ECPGt_long:
307313
res = strtol(pval, &scan_length, 10);
308-
if (garbage_left(isarray, scan_length, compat))
314+
if (garbage_left(isarray, &scan_length, compat))
309315
{
310316
ecpg_raise(lineno, ECPG_INT_FORMAT,
311317
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
@@ -334,7 +340,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
334340
case ECPGt_unsigned_int:
335341
case ECPGt_unsigned_long:
336342
ures = strtoul(pval, &scan_length, 10);
337-
if (garbage_left(isarray, scan_length, compat))
343+
if (garbage_left(isarray, &scan_length, compat))
338344
{
339345
ecpg_raise(lineno, ECPG_UINT_FORMAT,
340346
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
@@ -363,7 +369,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
363369
#ifdef HAVE_STRTOLL
364370
case ECPGt_long_long:
365371
*((long long int *) (var + offset * act_tuple)) = strtoll(pval, &scan_length, 10);
366-
if (garbage_left(isarray, scan_length, compat))
372+
if (garbage_left(isarray, &scan_length, compat))
367373
{
368374
ecpg_raise(lineno, ECPG_INT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
369375
return (false);
@@ -375,7 +381,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
375381
#ifdef HAVE_STRTOULL
376382
case ECPGt_unsigned_long_long:
377383
*((unsigned long long int *) (var + offset * act_tuple)) = strtoull(pval, &scan_length, 10);
378-
if (garbage_left(isarray, scan_length, compat))
384+
if (garbage_left(isarray, &scan_length, compat))
379385
{
380386
ecpg_raise(lineno, ECPG_UINT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
381387
return (false);
@@ -397,7 +403,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
397403
if (isarray && *scan_length == '"')
398404
scan_length++;
399405

400-
if (garbage_left(isarray, scan_length, compat))
406+
if (garbage_left(isarray, &scan_length, compat))
401407
{
402408
ecpg_raise(lineno, ECPG_FLOAT_FORMAT,
403409
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
@@ -595,7 +601,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
595601
}
596602
else
597603
{
598-
if (!isarray && garbage_left(isarray, scan_length, compat))
604+
if (!isarray && garbage_left(isarray, &scan_length, compat))
599605
{
600606
free(nres);
601607
ecpg_raise(lineno, ECPG_NUMERIC_FORMAT,
@@ -653,7 +659,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
653659
if (*scan_length == '"')
654660
scan_length++;
655661

656-
if (!isarray && garbage_left(isarray, scan_length, compat))
662+
if (!isarray && garbage_left(isarray, &scan_length, compat))
657663
{
658664
free(ires);
659665
ecpg_raise(lineno, ECPG_INTERVAL_FORMAT,
@@ -703,7 +709,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
703709
if (*scan_length == '"')
704710
scan_length++;
705711

706-
if (!isarray && garbage_left(isarray, scan_length, compat))
712+
if (!isarray && garbage_left(isarray, &scan_length, compat))
707713
{
708714
ecpg_raise(lineno, ECPG_DATE_FORMAT,
709715
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
@@ -751,7 +757,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
751757
if (*scan_length == '"')
752758
scan_length++;
753759

754-
if (!isarray && garbage_left(isarray, scan_length, compat))
760+
if (!isarray && garbage_left(isarray, &scan_length, compat))
755761
{
756762
ecpg_raise(lineno, ECPG_TIMESTAMP_FORMAT,
757763
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);

0 commit comments

Comments
 (0)