Update tests

This commit is contained in:
Yasuo Ohgaki 2002-04-19 12:24:58 +00:00
parent 7a8ad06121
commit 825e011805
4 changed files with 26 additions and 22 deletions

View File

@ -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

View File

@ -9,7 +9,7 @@ include("pg_convert.inc");
--EXPECT--
array(3) {
["num"]=>
int(1234)
string(4) "1234"
["str"]=>
string(5) "'AAA'"
["bin"]=>

View File

@ -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)
}
}

View File

@ -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";
// }
?>