Browse Source
MFH:
MFH:
- Fixed: . Memory leak in pg_delete() when using PGSQL_DML_STRING. . Bug #24679 (pg_insert problem!) . Bug #35996 (pg_meta_data should take the schema into account) . Bug #40808 (pg_insert problem) . Bug #42078 (pg_meta_data mix tables metadata from different schemas) - Improved: . Error messages - Added: . TestsPECL
6 changed files with 357 additions and 7 deletions
-
34ext/pgsql/pgsql.c
-
86ext/pgsql/tests/pg_delete_001.phpt
-
40ext/pgsql/tests/pg_insert_001.phpt
-
92ext/pgsql/tests/pg_meta_data_001.phpt
-
61ext/pgsql/tests/pg_select_001.phpt
-
51ext/pgsql/tests/pg_update_001.phpt
@ -0,0 +1,86 @@ |
|||
--TEST-- |
|||
PostgreSQL pg_delete() - basic test using schema |
|||
--SKIPIF-- |
|||
<?php include("skipif.inc"); ?> |
|||
--FILE-- |
|||
<?php |
|||
|
|||
include('config.inc'); |
|||
|
|||
$conn = pg_connect($conn_str); |
|||
|
|||
pg_query('CREATE SCHEMA phptests'); |
|||
|
|||
pg_query('CREATE TABLE foo (id INT, id2 INT)'); |
|||
pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)'); |
|||
|
|||
pg_insert($conn, 'foo', array('id' => 1, 'id2' => 1)); |
|||
pg_insert($conn, 'foo', array('id' => 1, 'id2' => 2)); |
|||
pg_insert($conn, 'foo', array('id' => 1, 'id2' => 2)); |
|||
pg_insert($conn, 'foo', array('id' => 3, 'id2' => 3)); |
|||
|
|||
pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 1)); |
|||
pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2)); |
|||
pg_insert($conn, 'phptests.foo', array('id' => 2, 'id2' => 3)); |
|||
pg_insert($conn, 'phptests.foo', array('id' => 2, 'id2' => 3)); |
|||
|
|||
pg_delete($conn, 'foo', array('id' => 1, 'id2' => 0)); |
|||
pg_delete($conn, 'foo', array('id' => 1, 'id2' => 2)); |
|||
var_dump(pg_delete($conn, 'foo', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING)); |
|||
|
|||
pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 1)); |
|||
pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 3)); |
|||
var_dump(pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 3), PGSQL_DML_STRING)); |
|||
|
|||
var_dump(pg_fetch_all(pg_query('SELECT * FROM foo'))); |
|||
var_dump(pg_fetch_all(pg_query('SELECT * FROM phptests.foo'))); |
|||
|
|||
/* Inexistent */ |
|||
pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2)); |
|||
var_dump(pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING)); |
|||
|
|||
pg_query('DROP TABLE foo'); |
|||
pg_query('DROP TABLE phptests.foo'); |
|||
pg_query('DROP SCHEMA phptests'); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
string(37) "DELETE FROM foo WHERE id=1 AND id2=2;" |
|||
string(46) "DELETE FROM phptests.foo WHERE id=2 AND id2=3;" |
|||
array(2) { |
|||
[0]=> |
|||
array(2) { |
|||
["id"]=> |
|||
string(1) "1" |
|||
["id2"]=> |
|||
string(1) "1" |
|||
} |
|||
[1]=> |
|||
array(2) { |
|||
["id"]=> |
|||
string(1) "3" |
|||
["id2"]=> |
|||
string(1) "3" |
|||
} |
|||
} |
|||
array(2) { |
|||
[0]=> |
|||
array(2) { |
|||
["id"]=> |
|||
string(1) "1" |
|||
["id2"]=> |
|||
string(1) "1" |
|||
} |
|||
[1]=> |
|||
array(2) { |
|||
["id"]=> |
|||
string(1) "1" |
|||
["id2"]=> |
|||
string(1) "2" |
|||
} |
|||
} |
|||
|
|||
Warning: pg_delete(): Table 'bar' doesn't exists in %s on line %d |
|||
|
|||
Warning: pg_delete(): Table 'bar' doesn't exists in %s on line %d |
|||
bool(false) |
|||
@ -0,0 +1,40 @@ |
|||
--TEST-- |
|||
PostgreSQL pg_select() - basic test using schema |
|||
--SKIPIF-- |
|||
<?php include("skipif.inc"); ?> |
|||
--FILE-- |
|||
<?php |
|||
|
|||
include('config.inc'); |
|||
|
|||
$conn = pg_connect($conn_str); |
|||
|
|||
pg_query('CREATE SCHEMA phptests'); |
|||
pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)'); |
|||
|
|||
|
|||
pg_insert($conn, 'foo', array('id' => 1, 'id2' => 1)); |
|||
|
|||
pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2)); |
|||
|
|||
var_dump(pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING)); |
|||
|
|||
var_dump(pg_select($conn, 'phptests.foo', array('id' => 1))); |
|||
|
|||
pg_query('DROP TABLE phptests.foo'); |
|||
pg_query('DROP SCHEMA phptests'); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
|
|||
Warning: pg_insert(): Table 'foo' doesn't exists in %s on line %d |
|||
string(47) "INSERT INTO phptests.foo (id,id2) VALUES (1,2);" |
|||
array(1) { |
|||
[0]=> |
|||
array(2) { |
|||
["id"]=> |
|||
string(1) "1" |
|||
["id2"]=> |
|||
string(1) "2" |
|||
} |
|||
} |
|||
@ -0,0 +1,92 @@ |
|||
--TEST-- |
|||
PostgreSQL pg_meta_data() - basic test using schema |
|||
--SKIPIF-- |
|||
<?php include("skipif.inc"); ?> |
|||
--FILE-- |
|||
<?php |
|||
|
|||
include('config.inc'); |
|||
|
|||
$conn = pg_connect($conn_str); |
|||
|
|||
pg_query('CREATE SCHEMA phptests'); |
|||
|
|||
pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)'); |
|||
|
|||
pg_query('CREATE TABLE foo (id INT, id3 INT)'); |
|||
|
|||
|
|||
var_dump(pg_meta_data($conn, 'foo')); |
|||
var_dump(pg_meta_data($conn, 'phptests.foo')); |
|||
|
|||
|
|||
pg_query('DROP TABLE foo'); |
|||
pg_query('DROP TABLE phptests.foo'); |
|||
pg_query('DROP SCHEMA phptests'); |
|||
|
|||
?> |
|||
--EXPECT-- |
|||
array(2) { |
|||
["id"]=> |
|||
array(6) { |
|||
["num"]=> |
|||
int(1) |
|||
["type"]=> |
|||
string(4) "int4" |
|||
["len"]=> |
|||
int(4) |
|||
["not null"]=> |
|||
bool(false) |
|||
["has default"]=> |
|||
bool(false) |
|||
["array dims"]=> |
|||
int(0) |
|||
} |
|||
["id3"]=> |
|||
array(6) { |
|||
["num"]=> |
|||
int(2) |
|||
["type"]=> |
|||
string(4) "int4" |
|||
["len"]=> |
|||
int(4) |
|||
["not null"]=> |
|||
bool(false) |
|||
["has default"]=> |
|||
bool(false) |
|||
["array dims"]=> |
|||
int(0) |
|||
} |
|||
} |
|||
array(2) { |
|||
["id"]=> |
|||
array(6) { |
|||
["num"]=> |
|||
int(1) |
|||
["type"]=> |
|||
string(4) "int4" |
|||
["len"]=> |
|||
int(4) |
|||
["not null"]=> |
|||
bool(false) |
|||
["has default"]=> |
|||
bool(false) |
|||
["array dims"]=> |
|||
int(0) |
|||
} |
|||
["id2"]=> |
|||
array(6) { |
|||
["num"]=> |
|||
int(2) |
|||
["type"]=> |
|||
string(4) "int4" |
|||
["len"]=> |
|||
int(4) |
|||
["not null"]=> |
|||
bool(false) |
|||
["has default"]=> |
|||
bool(false) |
|||
["array dims"]=> |
|||
int(0) |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
--TEST-- |
|||
PostgreSQL pg_select() - basic test using schema |
|||
--SKIPIF-- |
|||
<?php include("skipif.inc"); ?> |
|||
--FILE-- |
|||
<?php |
|||
|
|||
include('config.inc'); |
|||
|
|||
$conn = pg_connect($conn_str); |
|||
|
|||
pg_query('CREATE SCHEMA phptests'); |
|||
|
|||
pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)'); |
|||
pg_query('INSERT INTO phptests.foo VALUES (1,2), (2,3)'); |
|||
|
|||
pg_query('CREATE TABLE phptests.bar (id4 INT, id3 INT)'); |
|||
pg_query('INSERT INTO phptests.bar VALUES (4,5), (6,7)'); |
|||
|
|||
/* Inexistent table */ |
|||
var_dump(pg_select($conn, 'foo', array('id' => 1))); |
|||
|
|||
/* Existent column */ |
|||
var_dump(pg_select($conn, 'phptests.foo', array('id' => 1))); |
|||
|
|||
/* Testing with inexistent column */ |
|||
var_dump(pg_select($conn, 'phptests.bar', array('id' => 1))); |
|||
|
|||
/* Existent column */ |
|||
var_dump(pg_select($conn, 'phptests.bar', array('id4' => 4))); |
|||
|
|||
|
|||
pg_query('DROP TABLE phptests.foo'); |
|||
pg_query('DROP TABLE phptests.bar'); |
|||
pg_query('DROP SCHEMA phptests'); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Warning: pg_select(): Table 'foo' doesn't exists in %s on line %d |
|||
bool(false) |
|||
array(1) { |
|||
[0]=> |
|||
array(2) { |
|||
["id"]=> |
|||
string(1) "1" |
|||
["id2"]=> |
|||
string(1) "2" |
|||
} |
|||
} |
|||
|
|||
Notice: pg_select(): Invalid field name (id) in values in %s on line %d |
|||
bool(false) |
|||
array(1) { |
|||
[0]=> |
|||
array(2) { |
|||
["id4"]=> |
|||
string(1) "4" |
|||
["id3"]=> |
|||
string(1) "5" |
|||
} |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
--TEST-- |
|||
PostgreSQL pg_update() - basic test using schema |
|||
--SKIPIF-- |
|||
<?php include("skipif.inc"); ?> |
|||
--FILE-- |
|||
<?php |
|||
|
|||
include('config.inc'); |
|||
|
|||
$conn = pg_connect($conn_str); |
|||
|
|||
pg_query('CREATE SCHEMA phptests'); |
|||
|
|||
pg_query('CREATE TABLE foo (id INT, id2 INT)'); |
|||
pg_query('CREATE TABLE phptests.foo (id INT, id2 INT)'); |
|||
|
|||
|
|||
pg_insert($conn, 'foo', array('id' => 1, 'id2' => 1)); |
|||
pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2)); |
|||
|
|||
pg_update($conn, 'foo', array('id' => 10), array('id' => 1)); |
|||
var_dump(pg_update($conn, 'foo', array('id' => 10), array('id' => 1), PGSQL_DML_STRING)); |
|||
|
|||
pg_update($conn, 'phptests.foo', array('id' => 100), array('id2' => 2)); |
|||
var_dump(pg_update($conn, 'phptests.foo', array('id' => 100), array('id2' => 2), PGSQL_DML_STRING)); |
|||
|
|||
$rs = pg_query('SELECT * FROM foo UNION SELECT * FROM phptests.foo'); |
|||
while ($row = pg_fetch_assoc($rs)) { |
|||
var_dump($row); |
|||
} |
|||
|
|||
pg_query('DROP TABLE foo'); |
|||
pg_query('DROP TABLE phptests.foo'); |
|||
pg_query('DROP SCHEMA phptests'); |
|||
|
|||
?> |
|||
--EXPECT-- |
|||
string(32) "UPDATE foo SET id=10 WHERE id=1;" |
|||
string(43) "UPDATE phptests.foo SET id=100 WHERE id2=2;" |
|||
array(2) { |
|||
["id"]=> |
|||
string(2) "10" |
|||
["id2"]=> |
|||
string(1) "1" |
|||
} |
|||
array(2) { |
|||
["id"]=> |
|||
string(3) "100" |
|||
["id2"]=> |
|||
string(1) "2" |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue