Add real pg_escape_bytea() test.

This commit is contained in:
Yasuo Ohgaki 2002-04-05 06:05:28 +00:00
parent eb7ed9105a
commit 22007a29de
3 changed files with 31 additions and 2 deletions

View file

@ -9,3 +9,4 @@ include("escape.inc");
--EXPECT--
pg_escape_string() is Ok
pg_escape_bytea() is Ok
pg_escape_bytea() actually works with databse

View file

@ -1,6 +1,11 @@
<?php
$before = "ABC\\ABC";
$expect = "ABC\\\\ABC";
include 'config.inc';
define('FILE_NAME', './php.gif');
// pg_escape_string() test
$before = "ABC\\ABC\'";
$expect = "ABC\\\\ABC\\'";
$after = pg_escape_string($before);
if ($expect === $after) {
echo "pg_escape_string() is Ok\n";
@ -12,6 +17,7 @@ else {
var_dump($expect);
}
// pg_escape_bytea() test
$before = "ABC\\ABC";
$expect = "ABC\\\\\\\\ABC";
$after = pg_escape_bytea($before);
@ -25,4 +31,26 @@ else {
var_dump($expect);
}
// Test using database
$fp = fopen(FILE_NAME,'r');
$data = fread($fp, filesize(FILE_NAME));
$db = pg_connect($conn_str);
$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($db, $sql);
$sql = "SELECT * FROM ".$table_name." WHERE num = -2";
$result = pg_query($db, $sql);
$row = pg_fetch_row($result, 0);
if ($data === $row['bin']) {
echo "pg_escape_bytea actually works\n";
}
else {
echo "pg_escape_bytea is broken\n";
}
?>

BIN
ext/pgsql/tests/php.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB