diff options
author | Vlad Krupin <vlad@php.net> | 2001-12-14 04:22:01 +0000 |
---|---|---|
committer | Vlad Krupin <vlad@php.net> | 2001-12-14 04:22:01 +0000 |
commit | fb8c06324948c88368d7de5c9033515a49ee2117 (patch) | |
tree | 36df7ab970b3c8cdef7a106e7490eb9a09d57dda /ext/dbase | |
parent | ae24aa4b8e25204896c61d1c2f522b89b535f286 (diff) | |
download | php-git-fb8c06324948c88368d7de5c9033515a49ee2117.tar.gz |
Fixed bug #5993. Now if the result returned from a database is bigger
than a long, dbase_get_record() and dbase_get_record_with_names() will
return a string instead.
# Need to update documentation to reflect that change
@ Fixed problem with dbase not returning very large (larger than long)
@ integers properly. (Vlad)
Diffstat (limited to 'ext/dbase')
-rw-r--r-- | ext/dbase/dbase.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/ext/dbase/dbase.c b/ext/dbase/dbase.c index 7fe99fda07..78840d2875 100644 --- a/ext/dbase/dbase.c +++ b/ext/dbase/dbase.c @@ -431,6 +431,8 @@ PHP_FUNCTION(dbase_get_record) dbfield_t *dbf, *cur_f; char *data, *fnp, *str_value; size_t cursize = 0; + long overflow_test; + int errno_save; DBase_TLS_VARS; if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &dbh_id, &record)==FAILURE) { @@ -476,7 +478,16 @@ PHP_FUNCTION(dbase_get_record) case 'I': /* FALLS THROUGH */ case 'N': if (cur_f->db_fdc == 0) { - add_next_index_long(return_value, strtol(str_value, NULL, 10)); + /* Large integers in dbase can be larger than long */ + errno_save = errno; + overflow_test = strtol(str_value, NULL, 10); + if (errno == ERANGE) { + /* If the integer is too large, keep it as string */ + add_next_index_string(return_value, str_value, 1); + } else { + add_next_index_long(return_value, overflow_test); + } + errno = errno_save; } else { add_next_index_double(return_value, atof(str_value)); } @@ -528,6 +539,8 @@ PHP_FUNCTION(dbase_get_record_with_names) int dbh_type; dbfield_t *dbf, *cur_f; char *data, *fnp, *str_value; + long overflow_test; + int errno_save; DBase_TLS_VARS; if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &dbh_id, &record)==FAILURE) { @@ -568,7 +581,16 @@ PHP_FUNCTION(dbase_get_record_with_names) case 'I': /* FALLS THROUGH */ case 'N': if (cur_f->db_fdc == 0) { - add_assoc_long(return_value, cur_f->db_fname, strtol(str_value, NULL, 10)); + /* Large integers in dbase can be larger than long */ + errno_save = errno; + overflow_test = strtol(str_value, NULL, 10); + if (errno == ERANGE) { + /* If the integer is too large, keep it as string */ + add_assoc_string(return_value, cur_f->db_fname, str_value, 1); + } else { + add_assoc_long(return_value, cur_f->db_fname, overflow_test); + } + errno = errno_save; } else { add_assoc_double(return_value, cur_f->db_fname, atof(str_value)); } |