cvs: php4 /ext/pgsql pgsql.c

From: Date: Wed, 16 Aug 2000 01:03:20 +0000
Subject: cvs: php4 /ext/pgsql pgsql.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-1196@lists.php.net to get a copy of this message
jah Tue Aug 15 18:03:20 2000 EDT Modified files: /php4/ext/pgsql pgsql.c Log: - Return NULL type when column is NULL, now that we have it in PHP4. - Fixed a bug in handling NULL columns, PQgetvalue() doesn't return a NULL pointer in this case, but a pointer to a string of 0 length... Index: php4/ext/pgsql/pgsql.c diff -u php4/ext/pgsql/pgsql.c:1.66 php4/ext/pgsql/pgsql.c:1.67 --- php4/ext/pgsql/pgsql.c:1.66 Fri Jul 28 23:07:26 2000 +++ php4/ext/pgsql/pgsql.c Tue Aug 15 18:03:20 2000 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pgsql.c,v 1.66 2000/07/29 06:07:26 jah Exp $ */ +/* $Id: pgsql.c,v 1.67 2000/08/16 01:03:20 jah Exp $ */ #include <stdlib.h> @@ -883,10 +883,14 @@ RETURN_FALSE; } - return_value->value.str.val = PQgetvalue(pgsql_result, Z_LVAL_PP(row), field_offset); - return_value->value.str.len = (return_value->value.str.val ? strlen(return_value->value.str.val) : 0); - return_value->value.str.val = safe_estrndup(return_value->value.str.val,return_value->value.str.len); - return_value->type = IS_STRING; + if (PQgetisnull(pgsql_result, Z_LVAL_PP(row), field_offset)) { + return_value->type = IS_NULL; + } else { + return_value->value.str.val = PQgetvalue(pgsql_result, Z_LVAL_PP(row), field_offset); + return_value->value.str.len = (return_value->value.str.val ? strlen(return_value->value.str.val) : 0); + return_value->value.str.val = safe_estrndup(return_value->value.str.val,return_value->value.str.len); + return_value->type = IS_STRING; + } } /* }}} */ @@ -933,33 +937,39 @@ } array_init(return_value); for (i = 0, num_fields = PQnfields(pgsql_result); i<num_fields; i++) { - element = PQgetvalue(pgsql_result, Z_LVAL_PP(row), i); - element_len = (element ? strlen(element) : 0); - if (element) { - char *data; - int data_len; - int should_copy=0; - - if (PG(magic_quotes_runtime)) { - data = php_addslashes(element, element_len, &data_len, 0); + if (PQgetisnull(pgsql_result, Z_LVAL_PP(row), i)) { + if (result_type & PGSQL_NUM) { + add_index_unset(return_value, i); } else { - data = safe_estrndup(element, element_len); - data_len = element_len; + field_name = PQfname(pgsql_result, i); + add_assoc_unset(return_value, field_name); } + } else { + element = PQgetvalue(pgsql_result, Z_LVAL_PP(row), i); + element_len = (element ? strlen(element) : 0); + if (element) { + char *data; + int data_len; + int should_copy=0; + + if (PG(magic_quotes_runtime)) { + data = php_addslashes(element, element_len, &data_len, 0); + } else { + data = safe_estrndup(element, element_len); + data_len = element_len; + } - if (result_type & PGSQL_NUM) { - add_index_stringl(return_value, i, data, data_len, should_copy); - should_copy=1; - } + if (result_type & PGSQL_NUM) { + add_index_stringl(return_value, i, data, data_len, should_copy); + should_copy=1; + } - if (result_type & PGSQL_ASSOC) { - field_name = PQfname(pgsql_result, i); - add_assoc_stringl(return_value, field_name, data, data_len, should_copy); + if (result_type & PGSQL_ASSOC) { + field_name = PQfname(pgsql_result, i); + add_assoc_stringl(return_value, field_name, data, data_len, should_copy); + } } - } else { - /* NULL field, don't set it */ - /* add_get_index_stringl(return_value, i, empty_string, 0, (void **) &pval_ptr); */ - } + } } }

« previous php.cvs (#1196) next »