diff options
author | Felipe Pena <felipe@php.net> | 2008-10-13 13:44:32 +0000 |
---|---|---|
committer | Felipe Pena <felipe@php.net> | 2008-10-13 13:44:32 +0000 |
commit | 310ac30e5ae0d8634f4f2d0eb458e0ab507c32d5 (patch) | |
tree | 4524820701ca4399efe14e427a468199f6541160 /ext/pgsql | |
parent | 8f8f18bc181806f3386c94ccfab44843b043c8c5 (diff) | |
download | php-git-310ac30e5ae0d8634f4f2d0eb458e0ab507c32d5.tar.gz |
MFH:
- Fixed bug #37100 (data is returned truncated with BINARY CURSOR)
Patch by Tony
Diffstat (limited to 'ext/pgsql')
-rw-r--r-- | ext/pgsql/pgsql.c | 7 | ||||
-rw-r--r-- | ext/pgsql/tests/bug37100.phpt | 43 |
2 files changed, 46 insertions, 4 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 8583837fbe..35c171d967 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -2482,10 +2482,9 @@ PHP_FUNCTION(pg_fetch_result) if (PQgetisnull(pgsql_result, pgsql_row, field_offset)) { Z_TYPE_P(return_value) = IS_NULL; } else { - Z_STRVAL_P(return_value) = PQgetvalue(pgsql_result, pgsql_row, field_offset); - Z_STRLEN_P(return_value) = (Z_STRVAL_P(return_value) ? strlen(Z_STRVAL_P(return_value)) : 0); - Z_STRVAL_P(return_value) = safe_estrndup(Z_STRVAL_P(return_value),Z_STRLEN_P(return_value)); - Z_TYPE_P(return_value) = IS_STRING; + char *value = PQgetvalue(pgsql_result, pgsql_row, field_offset); + int value_len = PQgetlength(pgsql_result, pgsql_row, field_offset); + ZVAL_STRINGL(return_value, value, value_len, 1); } } /* }}} */ diff --git a/ext/pgsql/tests/bug37100.phpt b/ext/pgsql/tests/bug37100.phpt new file mode 100644 index 0000000000..b66149e4a5 --- /dev/null +++ b/ext/pgsql/tests/bug37100.phpt @@ -0,0 +1,43 @@ +--TEST-- +Bug #37100 (data is returned truncated with BINARY CURSOR) +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +include 'config.inc'; + +$db = pg_connect($conn_str); + +@pg_query('DROP TABLE test_bug'); + +pg_query('CREATE TABLE test_bug (binfield byteA) ;'); +pg_query("INSERT INTO test_bug VALUES (decode('0103AA000812','hex'))"); + + +$data = pg_query("SELECT binfield FROM test_bug"); +$res = pg_fetch_result($data,0); +var_dump($res); +var_dump(bin2hex(pg_unescape_bytea($res))); + +$sql = "BEGIN; DECLARE mycursor BINARY CURSOR FOR SELECT binfield FROM test_bug; FETCH ALL IN mycursor;"; + +$data = pg_query($sql); +$res = pg_fetch_result($data,0); + +var_dump(strlen($res)); +var_dump(bin2hex($res)); + +pg_close($db); + +$db = pg_connect($conn_str); +pg_query('DROP TABLE test_bug'); +pg_close($db); + + +?> +--EXPECT-- +string(24) "\001\003\252\000\010\022" +string(12) "0103aa000812" +int(6) +string(12) "0103aa000812" |