xref: /PHP-8.4/ext/pgsql/tests/bug77047.phpt (revision c15988aa)
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("inc/skipif.inc");
8?>
9--FILE--
10<?php
11error_reporting(E_ALL);
12
13include 'inc/config.inc';
14$table_name = 'table_bug77047';
15
16$db = pg_connect($conn_str);
17
18pg_query($db, "CREATE TABLE {$table_name} (
19        t TIME WITHOUT TIME ZONE
20    )");
21
22try {
23    pg_insert($db, $table_name, array("t" => "13:31"));
24} catch (\TypeError $e) {
25    echo $e->getMessage();
26}
27pg_insert($db, $table_name, array("t" => "13:31:13"));
28pg_insert($db, $table_name, array("t" => "1:2:3"));
29try {
30    pg_insert($db, $table_name, array("t" => "xyz"));
31} catch (\TypeError $e) {
32    echo $e->getMessage() . PHP_EOL;
33}
34pg_insert($db, $table_name, array("t" => NULL));
35pg_insert($db, $table_name, array("t" => ""));
36
37$res = pg_query($db, "SELECT t FROM {$table_name}");
38while (false !== ($row = pg_fetch_row($res))) {
39    var_dump(array_pop($row));
40}
41
42?>
43--CLEAN--
44<?php
45require_once('inc/config.inc');
46$table_name = 'table_bug77047';
47
48$db = pg_connect($conn_str);
49pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
50?>
51--EXPECTF--
52pg_insert(): Field "t" must be of type string|null, time given
53string(8) "13:31:00"
54string(8) "13:31:13"
55string(8) "01:02:03"
56NULL
57NULL
58