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