32nb_async_query.phpt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. --TEST--
  2. PostgreSQL non-blocking async queries
  3. --SKIPIF--
  4. <?php
  5. include("skipif.inc");
  6. if (!function_exists('pg_send_prepare')) die('skip function pg_send_prepare() does not exist');
  7. ?>
  8. --FILE--
  9. <?php
  10. include('config.inc');
  11. include('nonblocking.inc');
  12. $db = pg_connect($conn_str);
  13. $version = pg_version($db);
  14. if ($version['protocol'] < 3) {
  15. echo "OK";
  16. exit(0);
  17. }
  18. $db_socket = pg_socket($db);
  19. stream_set_blocking($db_socket, false);
  20. $nb_send = pg_send_query($db, "SELECT * FROM ".$table_name.";");
  21. if ($nb_send === FALSE) {
  22. echo "pg_send_query() error\n";
  23. } elseif ($nb_send === 0) {
  24. nb_flush($db, $db_socket);
  25. }
  26. nb_consume($db, $db_socket);
  27. if (!($result = pg_get_result($db))) {
  28. echo "pg_get_result() error\n";
  29. }
  30. if (!($rows = pg_num_rows($result))) {
  31. echo "pg_num_rows() error\n";
  32. }
  33. for ($i=0; $i < $rows; $i++) {
  34. pg_fetch_array($result, $i, PGSQL_NUM);
  35. }
  36. for ($i=0; $i < $rows; $i++) {
  37. pg_fetch_object($result);
  38. }
  39. for ($i=0; $i < $rows; $i++) {
  40. pg_fetch_row($result, $i);
  41. }
  42. for ($i=0; $i < $rows; $i++) {
  43. pg_fetch_result($result, $i, 0);
  44. }
  45. pg_num_rows(pg_query($db, "SELECT * FROM ".$table_name.";"));
  46. pg_num_fields(pg_query($db, "SELECT * FROM ".$table_name.";"));
  47. pg_field_name($result, 0);
  48. pg_field_num($result, $field_name);
  49. pg_field_size($result, 0);
  50. pg_field_type($result, 0);
  51. pg_field_prtlen($result, 0);
  52. pg_field_is_null($result, 0);
  53. $nb_send = pg_send_query($db, "INSERT INTO ".$table_name." VALUES (8888, 'GGG');");
  54. if ($nb_send === FALSE) {
  55. echo "pg_send_query() error\n";
  56. } elseif ($nb_send === 0) {
  57. nb_flush($db, $db_socket);
  58. }
  59. nb_consume($db, $db_socket);
  60. if (!($result = pg_get_result($db))) {
  61. echo "pg_get_result() error\n";
  62. }
  63. pg_last_oid($result);
  64. pg_free_result($result);
  65. pg_close($db);
  66. echo "OK";
  67. ?>
  68. --EXPECT--
  69. OK