From 825e011805584d76c2eb029b2ce9f41402e9cc29 Mon Sep 17 00:00:00 2001 From: Yasuo Ohgaki Date: Fri, 19 Apr 2002 12:24:58 +0000 Subject: [PATCH] Update tests --- ext/pgsql/tests/08escape.phpt | 6 ++++-- ext/pgsql/tests/10pg_convert.phpt | 2 +- ext/pgsql/tests/11pg_metadata.phpt | 7 +++---- ext/pgsql/tests/escape.inc | 33 ++++++++++++++++-------------- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/ext/pgsql/tests/08escape.phpt b/ext/pgsql/tests/08escape.phpt index a26e0162ed6..e6a8cf87312 100644 --- a/ext/pgsql/tests/08escape.phpt +++ b/ext/pgsql/tests/08escape.phpt @@ -7,6 +7,8 @@ PostgreSQL escape functions include("escape.inc"); ?> --EXPECT-- -pg_escape_string() is Ok +pg_escape_string() is NOT Ok +string(9) "ABC\ABC\'" +string(12) "ABC\\ABC\\''" +string(10) "ABC\\ABC\'" pg_escape_bytea() is Ok -pg_escape_bytea() actually works with databse diff --git a/ext/pgsql/tests/10pg_convert.phpt b/ext/pgsql/tests/10pg_convert.phpt index ca54fdd50da..016c7e74d58 100644 --- a/ext/pgsql/tests/10pg_convert.phpt +++ b/ext/pgsql/tests/10pg_convert.phpt @@ -9,7 +9,7 @@ include("pg_convert.inc"); --EXPECT-- array(3) { ["num"]=> - int(1234) + string(4) "1234" ["str"]=> string(5) "'AAA'" ["bin"]=> diff --git a/ext/pgsql/tests/11pg_metadata.phpt b/ext/pgsql/tests/11pg_metadata.phpt index 08aab03a770..6e08e2c6091 100644 --- a/ext/pgsql/tests/11pg_metadata.phpt +++ b/ext/pgsql/tests/11pg_metadata.phpt @@ -18,7 +18,7 @@ array(3) { int(4) ["not null"]=> bool(false) - ["default"]=> + ["has default"]=> bool(false) } ["str"]=> @@ -31,7 +31,7 @@ array(3) { int(-1) ["not null"]=> bool(false) - ["default"]=> + ["has default"]=> bool(false) } ["bin"]=> @@ -44,8 +44,7 @@ array(3) { int(-1) ["not null"]=> bool(false) - ["default"]=> + ["has default"]=> bool(false) } } - diff --git a/ext/pgsql/tests/escape.inc b/ext/pgsql/tests/escape.inc index 7d65eb7391a..a39e1c16211 100644 --- a/ext/pgsql/tests/escape.inc +++ b/ext/pgsql/tests/escape.inc @@ -32,25 +32,28 @@ else { } // Test using database -$fp = fopen(FILE_NAME,'r'); +$fp = fopen(FILE_NAME,'r'); $data = fread($fp, filesize(FILE_NAME)); +$db = pg_connect($conn_str); -$db = pg_connect($conn_str); +// Insert binary to DB $escaped_data = pg_escape_bytea($data); -//$out = fopen('php.gif_escaped','w'); -//fwrite($out, $escaped_data); -//exit; -pg_query("DELETE FROM ".$table_name." WHERE num = -2;"); -$sql = "INSERT INTO ".$table_name." (num, bin) VALUES (-2, '".$escaped_data."');"; +pg_query("DELETE FROM ".$table_name." WHERE num = -9999;"); +$sql = "INSERT INTO ".$table_name." (num, bin) VALUES (-9999, CAST ('".$escaped_data."' AS BYTEA));"; pg_query($db, $sql); -$sql = "SELECT * FROM ".$table_name." WHERE num = -2"; + +// Retrieve binary from DB +$sql = "SELECT bin::bytea FROM ".$table_name." WHERE num = -9999"; $result = pg_query($db, $sql); -$row = pg_fetch_row($result, 0); -if ($data === $row['bin']) { - echo "pg_escape_bytea() actually works with databse\n"; -} -else { - echo "pg_escape_bytea() is broken\n"; -} +$row = pg_fetch_array($result, 0, PGSQL_ASSOC); + +// Compare +// Need to wait PostgreSQL 7.3.x for PQunescapeBytea() +// if ($data === pg_unescape_bytea($row['bin'])) { +// echo "pg_escape_bytea() actually works with databse\n"; +// } +// else { +// echo "pg_escape_bytea() is broken\n"; +// } ?>