xref: /PHP-8.4/ext/pgsql/tests/pg_delete_001.phpt (revision c15988aa)
1--TEST--
2PostgreSQL pg_delete() - 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_delete_001';
12$table_name = 'table_pg_delete_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
21pg_insert($conn, $table_name, array('id' => 1, 'id2' => 1));
22pg_insert($conn, $table_name, array('id' => 1, 'id2' => 2));
23pg_insert($conn, $table_name, array('id' => 1, 'id2' => 2));
24pg_insert($conn, $table_name, array('id' => 3, 'id2' => 3));
25
26pg_insert($conn, "{$schema_name}.{$table_name}", array('id' => 1, 'id2' => 1));
27pg_insert($conn, "{$schema_name}.{$table_name}", array('id' => 1, 'id2' => 2));
28pg_insert($conn, "{$schema_name}.{$table_name}", array('id' => 2, 'id2' => 3));
29pg_insert($conn, "{$schema_name}.{$table_name}", array('id' => 2, 'id2' => 3));
30
31pg_delete($conn, $table_name, array('id' => 1, 'id2' => 0));
32pg_delete($conn, $table_name, array('id' => 1, 'id2' => 2));
33var_dump(pg_delete($conn, $table_name, array('id' => 1, 'id2' => 2), PGSQL_DML_STRING));
34
35pg_delete($conn, "{$schema_name}.{$table_name}", array('id' => 2, 'id2' => 1));
36pg_delete($conn, "{$schema_name}.{$table_name}", array('id' => 2, 'id2' => 3));
37var_dump(pg_delete($conn, "{$schema_name}.{$table_name}", array('id' => 2, 'id2' => 3), PGSQL_DML_STRING));
38
39var_dump(pg_fetch_all(pg_query($conn, "SELECT * FROM {$table_name}")));
40var_dump(pg_fetch_all(pg_query($conn, "SELECT * FROM {$schema_name}.{$table_name}")));
41
42/* Inexistent */
43pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2));
44var_dump(pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING));
45
46?>
47--CLEAN--
48<?php
49require_once('inc/config.inc');
50$schema_name = 'schema_pg_delete_001';
51$table_name = 'table_pg_delete_001';
52
53$conn = pg_connect($conn_str);
54
55pg_query($conn, "DROP TABLE IF EXISTS {$table_name}");
56pg_query($conn, "DROP TABLE IF EXISTS {$schema_name}.{$table_name}");
57pg_query($conn, "DROP SCHEMA IF EXISTS {$schema_name}");
58?>
59--EXPECTF--
60string(59) "DELETE FROM "table_pg_delete_001" WHERE "id"=1 AND "id2"=2;"
61string(82) "DELETE FROM "schema_pg_delete_001"."table_pg_delete_001" WHERE "id"=2 AND "id2"=3;"
62array(2) {
63  [0]=>
64  array(2) {
65    ["id"]=>
66    string(1) "1"
67    ["id2"]=>
68    string(1) "1"
69  }
70  [1]=>
71  array(2) {
72    ["id"]=>
73    string(1) "3"
74    ["id2"]=>
75    string(1) "3"
76  }
77}
78array(2) {
79  [0]=>
80  array(2) {
81    ["id"]=>
82    string(1) "1"
83    ["id2"]=>
84    string(1) "1"
85  }
86  [1]=>
87  array(2) {
88    ["id"]=>
89    string(1) "1"
90    ["id2"]=>
91    string(1) "2"
92  }
93}
94
95Warning: pg_delete(): Table 'bar' doesn't exists in %s on line %d
96
97Warning: pg_delete(): Table 'bar' doesn't exists in %s on line %d
98bool(false)
99