xref: /PHP-7.2/ext/pgsql/tests/pg_delete_001.phpt (revision f718684a)
1--TEST--
2PostgreSQL pg_delete() - basic test using schema
3--SKIPIF--
4<?php include("skipif.inc"); ?>
5--FILE--
6<?php
7
8include('config.inc');
9
10$conn = pg_connect($conn_str);
11
12pg_query('CREATE SCHEMA phptests');
13
14pg_query('CREATE TABLE foo (id INT, id2 INT)');
15pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)');
16
17pg_insert($conn, 'foo', array('id' => 1, 'id2' => 1));
18pg_insert($conn, 'foo', array('id' => 1, 'id2' => 2));
19pg_insert($conn, 'foo', array('id' => 1, 'id2' => 2));
20pg_insert($conn, 'foo', array('id' => 3, 'id2' => 3));
21
22pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 1));
23pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2));
24pg_insert($conn, 'phptests.foo', array('id' => 2, 'id2' => 3));
25pg_insert($conn, 'phptests.foo', array('id' => 2, 'id2' => 3));
26
27pg_delete($conn, 'foo', array('id' => 1, 'id2' => 0));
28pg_delete($conn, 'foo', array('id' => 1, 'id2' => 2));
29var_dump(pg_delete($conn, 'foo', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING));
30
31pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 1));
32pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 3));
33var_dump(pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 3), PGSQL_DML_STRING));
34
35var_dump(pg_fetch_all(pg_query('SELECT * FROM foo')));
36var_dump(pg_fetch_all(pg_query('SELECT * FROM phptests.foo')));
37
38/* Inexistent */
39pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2));
40var_dump(pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING));
41
42pg_query('DROP TABLE foo');
43pg_query('DROP TABLE phptests.foo');
44pg_query('DROP SCHEMA phptests');
45
46?>
47--EXPECTF--
48string(43) "DELETE FROM "foo" WHERE "id"=1 AND "id2"=2;"
49string(54) "DELETE FROM "phptests"."foo" WHERE "id"=2 AND "id2"=3;"
50array(2) {
51  [0]=>
52  array(2) {
53    ["id"]=>
54    string(1) "1"
55    ["id2"]=>
56    string(1) "1"
57  }
58  [1]=>
59  array(2) {
60    ["id"]=>
61    string(1) "3"
62    ["id2"]=>
63    string(1) "3"
64  }
65}
66array(2) {
67  [0]=>
68  array(2) {
69    ["id"]=>
70    string(1) "1"
71    ["id2"]=>
72    string(1) "1"
73  }
74  [1]=>
75  array(2) {
76    ["id"]=>
77    string(1) "1"
78    ["id2"]=>
79    string(1) "2"
80  }
81}
82
83Warning: pg_delete(): Table 'bar' doesn't exists in %s on line %d
84
85Warning: pg_delete(): Table 'bar' doesn't exists in %s on line %d
86bool(false)
87