--- embedaddon/php/ext/pgsql/tests/08escape.phpt 2013/07/22 01:31:59 1.1.1.2 +++ embedaddon/php/ext/pgsql/tests/08escape.phpt 2013/10/14 08:02:28 1.1.1.3 @@ -48,15 +48,24 @@ $sql = "INSERT INTO ".$table_name." (num, bin) VALUES pg_query($db, $sql); // Retrieve binary from DB -$sql = "SELECT bin::bytea FROM ".$table_name." WHERE num = -9999"; -$result = pg_query($db, $sql); -$row = pg_fetch_array($result, 0, PGSQL_ASSOC); +for ($i = 0; $i < 2; $i++) { + $sql = "SELECT bin::bytea FROM ".$table_name." WHERE num = -9999"; + $result = pg_query($db, $sql); + $row = pg_fetch_array($result, 0, PGSQL_ASSOC); -if ($data === pg_unescape_bytea($row['bin'])) { - echo "pg_escape_bytea() actually works with database\n"; -} -else { - echo "pg_escape_bytea() is broken\n"; + if ($data === pg_unescape_bytea($row['bin'])) { + echo "pg_escape_bytea() actually works with database\n"; + break; + } + elseif (!$i) { + // Force bytea escaping and retry + @pg_query($db, "SET bytea_output = 'escape'"); + } + else { + $result = pg_query($db, $sql); + echo "pg_escape_bytea() is broken\n"; + break; + } } // pg_escape_literal/pg_escape_identifier @@ -92,4 +101,4 @@ pg_escape_string() is Ok pg_escape_bytea() is Ok pg_escape_bytea() actually works with database pg_escape_literal() is Ok -pg_escape_identifier() is Ok \ No newline at end of file +pg_escape_identifier() is Ok