- 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...
This commit is contained in:
Jouni Ahto 2000-08-16 01:03:20 +00:00
parent 81b8e08b13
commit e85ba0901a

View File

@ -883,11 +883,15 @@ PHP_FUNCTION(pg_result)
RETURN_FALSE;
}
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,6 +937,14 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type)
}
array_init(return_value);
for (i = 0, num_fields = PQnfields(pgsql_result); i<num_fields; i++) {
if (PQgetisnull(pgsql_result, Z_LVAL_PP(row), i)) {
if (result_type & PGSQL_NUM) {
add_index_unset(return_value, i);
} else {
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) {
@ -956,9 +968,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type)
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); */
}
}
}
}