xref: /php-src/ext/pgsql/tests/pg_update_001.phpt (revision c15988aa)
1--TEST--
2PostgreSQL pg_update() - basic test using schema
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php include("inc/skipif.inc"); ?>
7--FILE--
8<?php
9
10include('inc/config.inc');
11$schema_name = 'schema_pg_update_001';
12$table_name = 'table_pg_update_001';
13
14$conn = pg_connect($conn_str);
15
16pg_query($conn, "CREATE SCHEMA {$schema_name}");
17
18pg_query($conn, "CREATE TABLE {$table_name} (id INT, id2 INT)");
19pg_query($conn, "CREATE TABLE {$schema_name}.{$table_name} (id INT, id2 INT)");
20
21
22pg_insert($conn, $table_name, array('id' => 1, 'id2' => 1));
23pg_insert($conn, "{$schema_name}.{$table_name}", array('id' => 1, 'id2' => 2));
24
25pg_update($conn, $table_name, array('id' => 10), array('id' => 1));
26var_dump(pg_update($conn, $table_name, array('id' => 10), array('id' => 1), PGSQL_DML_STRING));
27
28pg_update($conn, "{$schema_name}.{$table_name}", array('id' => 100), array('id2' => 2));
29var_dump(pg_update($conn, "{$schema_name}.{$table_name}", array('id' => 100), array('id2' => 2), PGSQL_DML_STRING));
30
31$rs = pg_query($conn, "SELECT * FROM {$table_name} UNION SELECT * FROM {$schema_name}.{$table_name} ORDER BY id");
32while ($row = pg_fetch_assoc($rs)) {
33    var_dump($row);
34}
35
36?>
37--CLEAN--
38<?php
39require_once('inc/config.inc');
40$schema_name = 'schema_pg_update_001';
41$table_name = 'table_pg_update_001';
42
43$conn = pg_connect($conn_str);
44
45pg_query($conn, "DROP TABLE IF EXISTS {$table_name}");
46pg_query($conn, "DROP TABLE IF EXISTS {$schema_name}.{$table_name}");
47pg_query($conn, "DROP SCHEMA IF EXISTS {$schema_name}");
48?>
49--EXPECT--
50string(54) "UPDATE "table_pg_update_001" SET "id"=10 WHERE "id"=1;"
51string(79) "UPDATE "schema_pg_update_001"."table_pg_update_001" SET "id"=100 WHERE "id2"=2;"
52array(2) {
53  ["id"]=>
54  string(2) "10"
55  ["id2"]=>
56  string(1) "1"
57}
58array(2) {
59  ["id"]=>
60  string(3) "100"
61  ["id2"]=>
62  string(1) "2"
63}
64