xref: /PHP-8.3/ext/pgsql/tests/bug77047.phpt (revision 16a63d7b)
1--TEST--
2Bug #77047 pg_insert has a broken regex for the 'TIME WITHOUT TIMEZONE' data type
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php
7include("skipif.inc");
8?>
9--FILE--
10<?php
11error_reporting(E_ALL);
12
13include 'config.inc';
14
15$db = pg_connect($conn_str);
16
17pg_query($db, "DROP TABLE IF EXISTS bug77047");
18pg_query($db, "CREATE TABLE bug77047 (
19        t TIME WITHOUT TIME ZONE
20    )");
21
22try {
23    pg_insert($db, "bug77047", array("t" => "13:31"));
24} catch (\TypeError $e) {
25    echo $e->getMessage();
26}
27pg_insert($db, "bug77047", array("t" => "13:31:13"));
28pg_insert($db, "bug77047", array("t" => "1:2:3"));
29try {
30    pg_insert($db, "bug77047", array("t" => "xyz"));
31} catch (\TypeError $e) {
32    echo $e->getMessage() . PHP_EOL;
33}
34pg_insert($db, "bug77047", array("t" => NULL));
35pg_insert($db, "bug77047", array("t" => ""));
36
37$res = pg_query($db, "SELECT t FROM bug77047");
38while (false !== ($row = pg_fetch_row($res))) {
39    var_dump(array_pop($row));
40}
41
42?>
43--EXPECTF--
44pg_insert(): Field "t" must be of type string|null, time given
45string(8) "13:31:00"
46string(8) "13:31:13"
47string(8) "01:02:03"
48NULL
49NULL
50