pg_delete_001.phpt 2.2 KB

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