]> granicus.if.org Git - php/commitdiff
Add real pg_escape_bytea() test.
authorYasuo Ohgaki <yohgaki@php.net>
Fri, 5 Apr 2002 06:05:28 +0000 (06:05 +0000)
committerYasuo Ohgaki <yohgaki@php.net>
Fri, 5 Apr 2002 06:05:28 +0000 (06:05 +0000)
ext/pgsql/tests/08escape.phpt
ext/pgsql/tests/escape.inc
ext/pgsql/tests/php.gif [new file with mode: 0644]

index ce4e22a7bfaf20938f6363110a48d5a7ebb20c66..a26e0162ed6e4d355572abc64474d92c374207ee 100644 (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
index c02ac423f8834f7cab0605ca800fa0646a0263ce..f7517952f01ad8b60957c14b28e629615685db30 100644 (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";
+}
+
 ?>
diff --git a/ext/pgsql/tests/php.gif b/ext/pgsql/tests/php.gif
new file mode 100644 (file)
index 0000000..7beda43
Binary files /dev/null and b/ext/pgsql/tests/php.gif differ