xref: /PHP-8.3/ext/pgsql/tests/03sync_query.phpt (revision e378968c)
1--TEST--
2PostgreSQL sync query
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php include("skipif.inc"); ?>
7--FILE--
8<?php
9
10include('config.inc');
11
12$db = pg_connect($conn_str);
13
14$result = pg_query($db, "SELECT * FROM ".$table_name.";");
15if (!($rows   = pg_num_rows($result)))
16{
17    echo "pg_num_row() error\n";
18}
19for ($i=0; $i < $rows; $i++)
20{
21    pg_fetch_array($result, $i, PGSQL_NUM);
22}
23for ($i=0; $i < $rows; $i++)
24{
25    pg_fetch_object($result);
26}
27for ($i=0; $i < $rows; $i++)
28{
29    pg_fetch_row($result, $i);
30}
31for ($i=0; $i < $rows; $i++)
32{
33    pg_fetch_result($result, $i, 0);
34}
35
36try {
37    pg_fetch_result($result, 0, -1);
38} catch (ValueError $e) {
39    echo $e->getMessage(), "\n";
40}
41try {
42    pg_fetch_result($result, 0, 3);
43} catch (ValueError $e) {
44    echo $e->getMessage(), "\n";
45}
46try {
47    pg_fetch_result($result, 0, "unknown");
48} catch (ValueError $e) {
49    echo $e->getMessage(), "\n";
50}
51try {
52    pg_fetch_all_columns($result, -1);
53} catch (ValueError $e) {
54    echo $e->getMessage(), "\n";
55}
56try {
57    pg_fetch_all_columns($result, 3);
58} catch (ValueError $e) {
59    echo $e->getMessage(), "\n";
60}
61
62pg_result_error($result);
63if (function_exists('pg_result_error_field')) {
64    pg_result_error_field($result, PGSQL_DIAG_SEVERITY);
65    pg_result_error_field($result, PGSQL_DIAG_SQLSTATE);
66    pg_result_error_field($result, PGSQL_DIAG_MESSAGE_PRIMARY);
67    pg_result_error_field($result, PGSQL_DIAG_MESSAGE_DETAIL);
68    pg_result_error_field($result, PGSQL_DIAG_MESSAGE_HINT);
69    pg_result_error_field($result, PGSQL_DIAG_STATEMENT_POSITION);
70    if (defined('PGSQL_DIAG_INTERNAL_POSITION'))
71    {
72        pg_result_error_field($result, PGSQL_DIAG_INTERNAL_POSITION);
73    }
74    if (defined('PGSQL_DIAG_INTERNAL_QUERY'))
75    {
76        pg_result_error_field($result, PGSQL_DIAG_INTERNAL_QUERY);
77    }
78    pg_result_error_field($result, PGSQL_DIAG_CONTEXT);
79    pg_result_error_field($result, PGSQL_DIAG_SOURCE_FILE);
80    pg_result_error_field($result, PGSQL_DIAG_SOURCE_LINE);
81    pg_result_error_field($result, PGSQL_DIAG_SOURCE_FUNCTION);
82}
83pg_num_rows(pg_query($db, "SELECT * FROM ".$table_name.";"));
84pg_num_fields(pg_query($db, "SELECT * FROM ".$table_name.";"));
85pg_field_name($result, 0);
86pg_field_num($result, $field_name);
87pg_field_size($result, 0);
88pg_field_type($result, 0);
89pg_field_prtlen($result, 0);
90pg_field_is_null($result, 0);
91
92try {
93    pg_field_is_null($result, -1);
94} catch (ValueError $e) {
95    echo $e->getMessage(), "\n";
96}
97try {
98    pg_field_is_null($result, 3);
99} catch (ValueError $e) {
100    echo $e->getMessage(), "\n";
101}
102try {
103    pg_field_is_null($result, "unknown");
104} catch (ValueError $e) {
105    echo $e->getMessage(), "\n";
106}
107try {
108    pg_field_name($result, -1);
109} catch (ValueError $e) {
110    echo $e->getMessage(), "\n";
111}
112try {
113    pg_field_name($result, 3);
114} catch (ValueError $e) {
115    echo $e->getMessage(), "\n";
116}
117try {
118    pg_field_table($result, -1);
119} catch (ValueError $e) {
120    echo $e->getMessage(), "\n";
121}
122try {
123    pg_field_table($result, 3);
124} catch (ValueError $e) {
125    echo $e->getMessage(), "\n";
126}
127
128$result = pg_query($db, "INSERT INTO ".$table_name." VALUES (9999, 'ABC');");
129pg_last_oid($result);
130var_dump(pg_fetch_all($result));
131
132pg_free_result($result);
133pg_close($db);
134
135echo "OK";
136?>
137--EXPECT--
138Argument #3 must be greater than or equal to 0
139Argument #3 must be less than the number of fields for this result set
140Argument #3 must be a field name from this result set
141pg_fetch_all_columns(): Argument #2 ($field) must be greater than or equal to 0
142pg_fetch_all_columns(): Argument #2 ($field) must be less than the number of fields for this result set
143Argument #2 must be greater than or equal to 0
144Argument #2 must be less than the number of fields for this result set
145Argument #2 must be a field name from this result set
146pg_field_name(): Argument #2 ($field) must be greater than or equal to 0
147pg_field_name(): Argument #2 ($field) must be less than the number of fields for this result set
148pg_field_table(): Argument #2 ($field) must be greater than or equal to 0
149pg_field_table(): Argument #2 ($field) must be less than the number of fields for this result set
150array(0) {
151}
152OK
153