32nb_async_query.phpt 1.8 KB

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