fix async queries not cleared prior some sync queries
authorMichael Wallner <mike@php.net>
Wed, 11 Aug 2021 08:13:19 +0000 (10:13 +0200)
committerMichael Wallner <mike@php.net>
Wed, 11 Aug 2021 16:46:27 +0000 (18:46 +0200)
src/php_pqconn.c
src/php_pqconn_event.c
tests/async010.phpt [new file with mode: 0644]

index 3a44a952a944548d4d5c94945874c1aa9f546877..6278323627ebad84f102a12de5a0f6f2eb827f76 100644 (file)
@@ -590,7 +590,7 @@ static inline PGresult *unlisten(PGconn *conn, const char *channel_str, size_t c
                smart_str_appends(&cmd, quoted_channel);
                smart_str_0(&cmd);
 
-               res = PQexec(conn, smart_str_v(&cmd));
+               res = php_pq_exec(conn, smart_str_v(&cmd));
 
                smart_str_free(&cmd);
                PQfreemem(quoted_channel);
@@ -990,7 +990,7 @@ static PHP_METHOD(pqconn, notify) {
                        PGresult *res;
                        char *params[2] = {channel_str, message_str};
 
-                       res = PQexecParams(obj->intern->conn, "select pg_notify($1, $2)", 2, NULL, (const char *const*) params, NULL, NULL, 0);
+                       res = php_pq_exec_params(obj->intern->conn, "select pg_notify($1, $2)", 2, NULL, (const char *const*) params, NULL, NULL, 0);
 
                        if (!res) {
                                throw_exce(EX_RUNTIME, "Failed to notify listeners (%s)", PHP_PQerrorMessage(obj->intern->conn));
@@ -1224,7 +1224,7 @@ static PHP_METHOD(pqconn, execParams) {
                        php_pq_params_t *params;
 
                        params = php_pq_params_init(&obj->intern->converters, ztypes ? Z_ARRVAL_P(ztypes) : NULL, Z_ARRVAL_P(zparams));
-                       res = PQexecParams(obj->intern->conn, query_str, params->param.count, params->type.oids, (const char *const*) params->param.strings, NULL, NULL, 0);
+                       res = php_pq_exec_params(obj->intern->conn, query_str, params->param.count, params->type.oids, (const char *const*) params->param.strings, NULL, NULL, 0);
                        php_pq_params_free(&params);
 
                        if (!res) {
index 802a9e482914235a3eeb39a081261b014871de4d..13e790a2cc3605472b11edcfde794e411d65472c 100644 (file)
@@ -55,7 +55,7 @@ static inline PGresult *relisten(PGconn *conn, const char *channel_str, size_t c
                smart_str_appends(&cmd, quoted_channel);
                smart_str_0(&cmd);
 
-               res = PQexec(conn, smart_str_v(&cmd));
+               res = php_pq_exec(conn, smart_str_v(&cmd));
 
                smart_str_free(&cmd);
                PQfreemem(quoted_channel);
diff --git a/tests/async010.phpt b/tests/async010.phpt
new file mode 100644 (file)
index 0000000..8ae089e
--- /dev/null
@@ -0,0 +1,67 @@
+--TEST--
+asnyc query not cleaned before sync exec
+--SKIPIF--
+<?php include "_skipif.inc"; ?>
+--FILE--
+<?php
+echo "Test\n";
+include "_setup.inc";
+
+$c = new pq\Connection(PQ_DSN);
+
+var_dump([
+       "async" => $c->execAsync("select clock_timestamp(), pg_sleep(0.1), clock_timestamp()", function($r) {
+               var_dump([
+                       "cb" => $r->fetchRow()
+               ]);
+       })
+]);
+
+var_dump([
+       "execParams" => $c->execParams("select \$1", [123])->fetchRow()
+]);
+?>
+DONE
+--EXPECTF--
+Test
+array(1) {
+  ["async"]=>
+  NULL
+}
+array(1) {
+  ["cb"]=>
+  array(3) {
+    [0]=>
+    object(pq\DateTime)#%d (4) {
+      ["format"]=>
+      string(14) "Y-m-d H:i:s.uO"
+      ["date"]=>
+      string(26) "%s"
+      ["timezone_type"]=>
+      int(1)
+      ["timezone"]=>
+      string(6) "%s"
+    }
+    [1]=>
+    string(0) ""
+    [2]=>
+    object(pq\DateTime)#%d (4) {
+      ["format"]=>
+      string(14) "Y-m-d H:i:s.uO"
+      ["date"]=>
+      string(26) "%s"
+      ["timezone_type"]=>
+      int(1)
+      ["timezone"]=>
+      string(6) "%s"
+    }
+  }
+}
+array(1) {
+  ["execParams"]=>
+  array(1) {
+    [0]=>
+    string(3) "123"
+  }
+}
+DONE
\ No newline at end of file