pg_delete_001.phpt 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. --TEST--
  2. PostgreSQL pg_delete() - basic test using schema
  3. --EXTENSIONS--
  4. pgsql
  5. --SKIPIF--
  6. <?php include("skipif.inc"); ?>
  7. --FILE--
  8. <?php
  9. include('config.inc');
  10. $conn = pg_connect($conn_str);
  11. pg_query($conn, 'CREATE SCHEMA phptests');
  12. pg_query($conn, 'CREATE TABLE foo (id INT, id2 INT)');
  13. pg_query($conn, 'CREATE TABLE phptests.foo (id INT, id2 INT)');
  14. pg_insert($conn, 'foo', array('id' => 1, 'id2' => 1));
  15. pg_insert($conn, 'foo', array('id' => 1, 'id2' => 2));
  16. pg_insert($conn, 'foo', array('id' => 1, 'id2' => 2));
  17. pg_insert($conn, 'foo', array('id' => 3, 'id2' => 3));
  18. pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 1));
  19. pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2));
  20. pg_insert($conn, 'phptests.foo', array('id' => 2, 'id2' => 3));
  21. pg_insert($conn, 'phptests.foo', array('id' => 2, 'id2' => 3));
  22. pg_delete($conn, 'foo', array('id' => 1, 'id2' => 0));
  23. pg_delete($conn, 'foo', array('id' => 1, 'id2' => 2));
  24. var_dump(pg_delete($conn, 'foo', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING));
  25. pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 1));
  26. pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 3));
  27. var_dump(pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 3), PGSQL_DML_STRING));
  28. var_dump(pg_fetch_all(pg_query($conn, 'SELECT * FROM foo')));
  29. var_dump(pg_fetch_all(pg_query($conn, 'SELECT * FROM phptests.foo')));
  30. /* Inexistent */
  31. pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2));
  32. var_dump(pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING));
  33. pg_query($conn, 'DROP TABLE foo');
  34. pg_query($conn, 'DROP TABLE phptests.foo');
  35. pg_query($conn, 'DROP SCHEMA phptests');
  36. ?>
  37. --EXPECTF--
  38. string(43) "DELETE FROM "foo" WHERE "id"=1 AND "id2"=2;"
  39. string(54) "DELETE FROM "phptests"."foo" WHERE "id"=2 AND "id2"=3;"
  40. array(2) {
  41. [0]=>
  42. array(2) {
  43. ["id"]=>
  44. string(1) "1"
  45. ["id2"]=>
  46. string(1) "1"
  47. }
  48. [1]=>
  49. array(2) {
  50. ["id"]=>
  51. string(1) "3"
  52. ["id2"]=>
  53. string(1) "3"
  54. }
  55. }
  56. array(2) {
  57. [0]=>
  58. array(2) {
  59. ["id"]=>
  60. string(1) "1"
  61. ["id2"]=>
  62. string(1) "1"
  63. }
  64. [1]=>
  65. array(2) {
  66. ["id"]=>
  67. string(1) "1"
  68. ["id2"]=>
  69. string(1) "2"
  70. }
  71. }
  72. Warning: pg_delete(): Table 'bar' doesn't exists in %s on line %d
  73. Warning: pg_delete(): Table 'bar' doesn't exists in %s on line %d
  74. bool(false)