Skip to content

Refactor ext/pgsql test #12608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions ext/pgsql/tests/06copy_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@ pgsql
<?php

include('inc/config.inc');
$table_name = 'table_06copy_2';

$db = pg_connect($conn_str);

pg_query($db, 'CREATE TABLE test_copy (x int)');
pg_query($db, "CREATE TABLE {$table_name} (x int)");

pg_query($db, 'COPY test_copy FROM STDIN');
pg_query($db, "COPY {$table_name} FROM STDIN");

pg_put_line($db, "1\n");
pg_put_line($db, "\\N\n");
pg_put_line($db, "\\.\n");
pg_end_copy($db);

var_dump(pg_fetch_all_columns(pg_query($db, 'SELECT * FROM test_copy ORDER BY 1')));
var_dump(pg_fetch_all_columns(pg_query($db, "SELECT * FROM {$table_name} ORDER BY 1")));
?>
--CLEAN--
<?php
include('inc/config.inc');
$db = pg_connect($conn_str);
$table_name = 'table_06copy_2';

pg_query($db, 'DROP TABLE test_copy');
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE {$table_name}");
?>
--EXPECT--
array(2) {
Expand Down
13 changes: 8 additions & 5 deletions ext/pgsql/tests/80_bug24499.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ require_once('inc/skipif.inc');
<?php

require_once('inc/config.inc');
$table_name = 'table_80_bug24499';

$dbh = @pg_connect($conn_str);
if (!$dbh) {
die ("Could not connect to the server");
}

pg_query($dbh, "CREATE TABLE id (id SERIAL, t INT)");
pg_query($dbh, "CREATE TABLE {$table_name} (id SERIAL, t INT)");

for ($i=0; $i<4; $i++) {
pg_query($dbh, "INSERT INTO id (t) VALUES ($i)");
pg_query($dbh, "INSERT INTO {$table_name} (t) VALUES ($i)");
}

class Id
Expand All @@ -29,8 +30,9 @@ class Id
public function getId()
{
global $dbh;
global $table_name;

$q = pg_query($dbh, "SELECT id FROM id");
$q = pg_query($dbh, "SELECT id FROM {$table_name}");
print_r(pg_fetch_array($q));
print_r(pg_fetch_array($q));
$id = pg_fetch_object($q);
Expand All @@ -50,9 +52,10 @@ echo "Done\n";
--CLEAN--
<?php
require_once('inc/config.inc');
$dbh = pg_connect($conn_str);
$table_name = 'table_80_bug24499';

pg_query($dbh, "DROP TABLE id CASCADE");
$dbh = pg_connect($conn_str);
pg_query($dbh, "DROP TABLE {$table_name} CASCADE");
?>
--EXPECTF--
Array
Expand Down
12 changes: 7 additions & 5 deletions ext/pgsql/tests/80_bug27597.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@ require_once('inc/skipif.inc');
<?php

require_once(__DIR__ . '/inc/config.inc');
$table_name = 'table_80_bug27597';

$dbh = @pg_connect($conn_str);
if (!$dbh) {
die ("Could not connect to the server");
}

pg_query($dbh, "CREATE TABLE id (id INT)");
pg_query($dbh, "CREATE TABLE {$table_name} (id INT)");

for ($i=0; $i<4; $i++) {
pg_query($dbh, "INSERT INTO id (id) VALUES ($i)");
pg_query($dbh, "INSERT INTO {$table_name} (id) VALUES ($i)");
}

function xi_fetch_array($res, $type = PGSQL_ASSOC) {
$a = pg_fetch_array($res, NULL, $type) ;
return $a ;
}

$res = pg_query($dbh, "SELECT * FROM id");
$res = pg_query($dbh, "SELECT * FROM {$table_name}");
$i = 0; // endless-loop protection
while($row = xi_fetch_array($res)) {
print_r($row);
Expand All @@ -43,9 +44,10 @@ pg_close($dbh);
--CLEAN--
<?php
require_once('inc/config.inc');
$dbh = pg_connect($conn_str);
$table_name = 'table_80_bug27597';

pg_query($dbh, "DROP TABLE id");
$dbh = pg_connect($conn_str);
pg_query($dbh, "DROP TABLE {$table_name}");
?>
--EXPECT--
Array
Expand Down
12 changes: 7 additions & 5 deletions ext/pgsql/tests/80_bug39971.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,28 @@ require_once('inc/skipif.inc');
<?php

require_once('inc/config.inc');
$table_name = 'table_80_bug39971';

$dbh = pg_connect($conn_str);

pg_query($dbh, "CREATE TABLE php_test (id SERIAL, tm timestamp NOT NULL)");
pg_query($dbh, "CREATE TABLE {$table_name} (id SERIAL, tm timestamp NOT NULL)");

$values = array('tm' => 'now()');
pg_insert($dbh, 'php_test', $values);
pg_insert($dbh, $table_name, $values);

$ids = array('id' => 1);
pg_update($dbh, 'php_test', $values, $ids);
pg_update($dbh, $table_name, $values, $ids);

pg_close($dbh);
?>
===DONE===
--CLEAN--
<?php
require_once('inc/config.inc');
$dbh = pg_connect($conn_str);
$table_name = 'table_80_bug39971';

pg_query($dbh, "DROP TABLE php_test");
$dbh = pg_connect($conn_str);
pg_query($dbh, "DROP TABLE {$table_name}");
?>
--EXPECT--
===DONE===
12 changes: 7 additions & 5 deletions ext/pgsql/tests/80_bug42783.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,28 @@ require_once('inc/skipif.inc');
<?php

require_once('inc/config.inc');
$table_name = 'table_80_bug42783';

$dbh = @pg_connect($conn_str);
if (!$dbh) {
die ("Could not connect to the server");
}

pg_query($dbh, "CREATE TABLE php_test (id SERIAL PRIMARY KEY, time TIMESTAMP NOT NULL DEFAULT now())");
pg_query($dbh, "CREATE TABLE {$table_name} (id SERIAL PRIMARY KEY, time TIMESTAMP NOT NULL DEFAULT now())");

pg_insert($dbh, 'php_test', array());
pg_insert($dbh, $table_name, array());

var_dump(pg_fetch_assoc(pg_query($dbh, "SELECT * FROM php_test")));
var_dump(pg_fetch_assoc(pg_query($dbh, "SELECT * FROM {$table_name}")));

pg_close($dbh);
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$dbh = pg_connect($conn_str);
$table_name = 'table_80_bug42783';

pg_query($dbh, "DROP TABLE php_test");
$dbh = pg_connect($conn_str);
pg_query($dbh, "DROP TABLE {$table_name}");
?>
--EXPECTF--
array(2) {
Expand Down
14 changes: 8 additions & 6 deletions ext/pgsql/tests/bug37100.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ skip_bytea_not_escape();
<?php

include 'inc/config.inc';
$table_name = 'table_bug37100';

$db = pg_connect($conn_str);
@pg_query("SET bytea_output = 'escape'");

pg_query('CREATE TABLE test_bug (binfield byteA) ;');
pg_query("INSERT INTO test_bug VALUES (decode('0103AA000812','hex'))");
pg_query("CREATE TABLE {$table_name} (binfield byteA) ;");
pg_query("INSERT INTO {$table_name} VALUES (decode('0103AA000812','hex'))");


$data = pg_query("SELECT binfield FROM test_bug");
$data = pg_query("SELECT binfield FROM {$table_name}");
$res = pg_fetch_result($data,0);
var_dump($res);
var_dump(bin2hex(pg_unescape_bytea($res)));

$sql = "BEGIN; DECLARE mycursor BINARY CURSOR FOR SELECT binfield FROM test_bug; FETCH ALL IN mycursor;";
$sql = "BEGIN; DECLARE mycursor BINARY CURSOR FOR SELECT binfield FROM {$table_name}; FETCH ALL IN mycursor;";

$data = pg_query($sql);
$res = pg_fetch_result($data,0);
Expand All @@ -37,9 +38,10 @@ pg_close($db);
--CLEAN--
<?php
require_once('inc/config.inc');
$db = pg_connect($conn_str);
$table_name = 'table_bug37100';

pg_query('DROP TABLE test_bug');
$db = pg_connect($conn_str);
pg_query("DROP TABLE {$table_name}");
?>
--EXPECT--
string(24) "\001\003\252\000\010\022"
Expand Down
14 changes: 8 additions & 6 deletions ext/pgsql/tests/bug37100_9.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ skip_bytea_not_hex();
<?php

include 'inc/config.inc';
$table_name = 'ttable_bug37100_9';

$db = pg_connect($conn_str);

pg_query($db, 'CREATE TABLE test_bug (binfield byteA) ;');
pg_query($db, "INSERT INTO test_bug VALUES (decode('0103AA000812','hex'))");
pg_query($db, "CREATE TABLE {$table_name} (binfield byteA) ;");
pg_query($db, "INSERT INTO {$table_name} VALUES (decode('0103AA000812','hex'))");


$data = pg_query($db, "SELECT binfield FROM test_bug");
$data = pg_query($db, "SELECT binfield FROM {$table_name}");
$res = pg_fetch_result($data, null, 0);
var_dump($res);
var_dump(bin2hex(pg_unescape_bytea($res)));

$sql = "BEGIN; DECLARE mycursor BINARY CURSOR FOR SELECT binfield FROM test_bug; FETCH ALL IN mycursor;";
$sql = "BEGIN; DECLARE mycursor BINARY CURSOR FOR SELECT binfield FROM {$table_name}; FETCH ALL IN mycursor;";

$data = pg_query($db, $sql);
$res = pg_fetch_result($data, null, 0);
Expand All @@ -41,9 +42,10 @@ pg_close($db);
--CLEAN--
<?php
require_once('inc/config.inc');
$db = pg_connect($conn_str);
$table_name = 'ttable_bug37100_9';

pg_query($db, 'DROP TABLE test_bug');
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE {$table_name}");
?>
--EXPECT--
string(14) "\x0103aa000812"
Expand Down
8 changes: 5 additions & 3 deletions ext/pgsql/tests/bug64609.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ skip_server_version('8.3', '<');
error_reporting(E_ALL);

include 'inc/config.inc';
$table_name = 'table_bug64609';
$type_name = 'type_bug64609';

$db = pg_connect($conn_str);
pg_query($db, "BEGIN");
pg_query($db, "CREATE TYPE t_enum AS ENUM ('ok', 'ko')");
pg_query($db, "CREATE TABLE test_enum (a t_enum)");
pg_query($db, "CREATE TYPE {$type_name} AS ENUM ('ok', 'ko')");
pg_query($db, "CREATE TABLE {$table_name} (a {$type_name})");

$fields = array('a' => 'ok');
$converted = pg_convert($db, 'test_enum', $fields);
$converted = pg_convert($db, $table_name, $fields);

pg_query($db, "ROLLBACK");

Expand Down
6 changes: 4 additions & 2 deletions ext/pgsql/tests/bug65119.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ include("inc/skipif.inc");
--FILE--
<?php
include 'inc/config.inc';
$table_name = 'table_bug65119';

function test(Array $values, $conn_str) {
global $table_name;
$connection = pg_pconnect($conn_str, PGSQL_CONNECT_FORCE_NEW);
pg_query($connection, "begin");
pg_query($connection, "CREATE TABLE bug65119 (i INTEGER)");
pg_copy_from($connection, "bug65119", $values, "\t", "NULL");
pg_query($connection, "CREATE TABLE {$table_name} (i INTEGER)");
pg_copy_from($connection, $table_name, $values, "\t", "NULL");
pg_query($connection, "rollback");
}

Expand Down
13 changes: 8 additions & 5 deletions ext/pgsql/tests/bug71998.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ pgsql
// http://stackoverflow.com/a/17871737/3358424

include('inc/config.inc');
$table_name = 'table_bug71998';

$db = pg_connect($conn_str);

pg_query($db, "CREATE TABLE tmp_statistics (id integer NOT NULL, remote_addr inet);");
pg_query($db, "CREATE TABLE {$table_name} (id integer NOT NULL, remote_addr inet);");

$ips = array(
/* IPv4*/
Expand Down Expand Up @@ -59,7 +60,7 @@ foreach ($ips as $ip) {
$data = array("id" => ++$i, "remote_addr" => $ip);
$r = true;
try {
@pg_insert($db, 'tmp_statistics', $data);
@pg_insert($db, $table_name, $data);
} catch (\ValueError $e) {
echo $e->getMessage() . PHP_EOL;
$r = false;
Expand All @@ -70,11 +71,11 @@ foreach ($ips as $ip) {
//echo pg_last_error($db);
}

//pg_query($db, "INSERT INTO tmp_statistics (id, remote_addr) VALUES (2, '127.0.0.1')"); // OK, record inserted
//pg_query($db, "INSERT INTO {$table_name} (id, remote_addr) VALUES (2, '127.0.0.1')"); // OK, record inserted
}


$r = pg_query($db, "SELECT * FROM tmp_statistics");
$r = pg_query($db, "SELECT * FROM {$table_name}");
while (false != ($row = pg_fetch_row($r))) {
var_dump($row);
}
Expand All @@ -86,9 +87,11 @@ pg_close($db);
--CLEAN--
<?php
require_once('inc/config.inc');
$table_name = 'table_bug71998';

$db = @pg_connect($conn_str);

pg_query($db, "DROP TABLE tmp_statistics");
pg_query($db, "DROP TABLE {$table_name}");
?>
--EXPECT--
pg_insert(): Field "remote_addr" must be a valid IPv4 or IPv6 address string, "256.257.258.259" given
Expand Down
Loading