ID:               45377
 User updated by:  kk219459 at students dot mimuw dot edu dot pl
 Reported By:      kk219459 at students dot mimuw dot edu dot pl
-Status:           Feedback
+Status:           Open
 Bug Type:         PostgreSQL related
 Operating System: OpenBSD
 PHP Version:      5.2.6
 New Comment:

The bug was reproduced on php5.2-200810251430 (Linux 2.6.26),
5.2.7RC3-dev


Previous Comments:
------------------------------------------------------------------------

[2008-10-24 15:58:28] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/



------------------------------------------------------------------------

[2008-06-27 14:50:54] kk219459 at students dot mimuw dot edu dot pl

Description:
------------
OpenBSD 4.1
Apache/1.3.29
php5-core-5.1.6p1
postgresql-client-8.2.4

I want to insert some binary data to a table.

$q = "UPDATE tbl SET data = decode($1, 'base64') WHERE id = $2";
$params = array(base64_encode('binary string'), 123);
$res = pg_query_params($q, $params);

OK

$q = "UPDATE tbl SET data = $1::bytea WHERE id = $2";
$params = array('binary string', 123);
$res = pg_query_params($q, $params);

ERROR: invalid byte sequence for encoding "UTF8": 0x89 HINT: This error
can also happen if the byte sequence does not match the encoding
expected by the server, which is controlled by "client_encoding".

This could possibly work, but does not. Ok, not a problem.

(end of introduction)


Reproduce code:
---------------
# first
$q = "UPDATE tbl SET data = decode($1, 'escape') WHERE id = $2";
$params = array(pg_escape_bytea('binary string'), 123);
$res = pg_query_params($q, $params);

# second
$q = "UPDATE tbl SET data = $1::bytea WHERE id = $2";
$params = array(pg_escape_bytea('binary string'), 123);
$res = pg_query_params($q, $params);


Expected result:
----------------
Be sure to replace 'binary string' with something more challenging!

At least one of these should work (insert the data correctly)


Actual result:
--------------
Both approaches give the same result.

The data gets loaded, but incorrectly.
select length(data) from tbl; -- too large
data contains character sequences like '\000' instead of their values.

btw.
select content = decode(encode(data, 'escape'), 'escape') from tbl; --
works (sequence of TRUEs)



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=45377&edit=1

Reply via email to