Annotation of embedaddon/php/ext/pgsql/tests/08escape.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: PostgreSQL escape functions
3: --SKIPIF--
4: <?php include("skipif.inc"); ?>
5: --FILE--
6: <?php
7:
8: include 'config.inc';
9: define('FILE_NAME', dirname(__FILE__) . '/php.gif');
10:
11: // pg_escape_string() test
12: $before = "ABC\\ABC\'";
13: $expect = "ABC\\\\ABC\\'";
14: $after = pg_escape_string($before);
15: if ($expect === $after) {
16: echo "pg_escape_string() is Ok\n";
17: }
18: else {
19: echo "pg_escape_string() is NOT Ok\n";
20: var_dump($before);
21: var_dump($after);
22: var_dump($expect);
23: }
24:
25: // pg_escape_bytea() test
26: $before = "ABC\\ABC";
27: $expect = "ABC\\\\\\\\ABC";
28: $after = pg_escape_bytea($before);
29: if ($expect === $after) {
30: echo "pg_escape_bytea() is Ok\n";
31: }
32: else {
33: echo "pg_escape_byte() is NOT Ok\n";
34: var_dump($before);
35: var_dump($after);
36: var_dump($expect);
37: }
38:
39: // Test using database
40: $data = file_get_contents(FILE_NAME);
41: $db = pg_connect($conn_str);
42:
43: // Insert binary to DB
44: $escaped_data = pg_escape_bytea($data);
45: pg_query("DELETE FROM ".$table_name." WHERE num = -9999;");
46: $sql = "INSERT INTO ".$table_name." (num, bin) VALUES (-9999, CAST ('".$escaped_data."' AS BYTEA));";
47: pg_query($db, $sql);
48:
49: // Retrieve binary from DB
50: $sql = "SELECT bin::bytea FROM ".$table_name." WHERE num = -9999";
51: $result = pg_query($db, $sql);
52: $row = pg_fetch_array($result, 0, PGSQL_ASSOC);
53:
54: if ($data === pg_unescape_bytea($row['bin'])) {
55: echo "pg_escape_bytea() actually works with database\n";
56: }
57: else {
58: echo "pg_escape_bytea() is broken\n";
59: }
60:
61: ?>
62: --EXPECT--
63: pg_escape_string() is NOT Ok
64: string(9) "ABC\ABC\'"
65: string(12) "ABC\\ABC\\''"
66: string(10) "ABC\\ABC\'"
67: pg_escape_bytea() is Ok
68: pg_escape_bytea() actually works with database
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>