xref: /PHP-8.4/ext/pgsql/tests/bug47199.phpt (revision c15988aa)
1--TEST--
2Bug #47199 (pg_delete fails on NULL)
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php
7require_once('inc/skipif.inc');
8?>
9--FILE--
10<?php
11
12require_once('inc/config.inc');
13
14$dbh = pg_connect($conn_str);
15$tbl_name = 'test_47199';
16pg_query($dbh, "CREATE TABLE $tbl_name (null_field INT, not_null_field INT NOT NULL)");
17
18pg_insert($dbh, $tbl_name, array('null_field' => null, 'not_null_field' => 1));
19pg_insert($dbh, $tbl_name, array('null_field' => null, 'not_null_field' => 2));
20
21var_dump(pg_fetch_all(pg_query($dbh, 'SELECT * FROM '. $tbl_name)));
22
23$query = pg_delete($dbh, $tbl_name, array('null_field' => NULL,'not_null_field' => 2), PGSQL_DML_STRING|PGSQL_DML_EXEC);
24
25echo $query, "\n";
26
27$query = pg_update($dbh, $tbl_name, array('null_field' => NULL, 'not_null_field' => 0), array('not_null_field' => 1, 'null_field' => ''), PGSQL_DML_STRING|PGSQL_DML_EXEC);
28
29echo $query, "\n";
30
31var_dump(pg_fetch_all(pg_query($dbh, 'SELECT * FROM '. $tbl_name)));
32
33pg_close($dbh);
34
35echo PHP_EOL."Done".PHP_EOL;
36
37?>
38--CLEAN--
39<?php
40require_once('inc/config.inc');
41$dbh = pg_connect($conn_str);
42
43$tbl_name = 'test_47199';
44pg_query($dbh, "DROP TABLE IF EXISTS $tbl_name");
45?>
46--EXPECT--
47array(2) {
48  [0]=>
49  array(2) {
50    ["null_field"]=>
51    NULL
52    ["not_null_field"]=>
53    string(1) "1"
54  }
55  [1]=>
56  array(2) {
57    ["null_field"]=>
58    NULL
59    ["not_null_field"]=>
60    string(1) "2"
61  }
62}
63DELETE FROM "test_47199" WHERE "null_field" IS NULL AND "not_null_field"=2;
64UPDATE "test_47199" SET "null_field"=NULL,"not_null_field"=0 WHERE "not_null_field"=1 AND "null_field" IS NULL;
65array(1) {
66  [0]=>
67  array(2) {
68    ["null_field"]=>
69    NULL
70    ["not_null_field"]=>
71    string(1) "0"
72  }
73}
74
75Done
76