|
36 | 36 | #include "pgsql_driver_arginfo.h" |
37 | 37 |
|
38 | 38 | static bool pgsql_handle_in_transaction(pdo_dbh_t *dbh); |
39 | | -void pgsql_stmt_finish(pdo_pgsql_stmt *S, int fin_mode); |
40 | 39 |
|
41 | 40 | static char * _pdo_pgsql_trim_message(const char *message, int persistent) |
42 | 41 | { |
@@ -110,37 +109,6 @@ int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, int errcode, const char * |
110 | 109 | } |
111 | 110 | /* }}} */ |
112 | 111 |
|
113 | | -static zend_always_inline void pgsql_finish_running_stmt(pdo_pgsql_db_handle *H) |
114 | | -{ |
115 | | - if (H->running_stmt) { |
116 | | - pgsql_stmt_finish(H->running_stmt, 0); |
117 | | - } |
118 | | -} |
119 | | - |
120 | | -static zend_always_inline void pgsql_discard_running_stmt(pdo_pgsql_db_handle *H) |
121 | | -{ |
122 | | - if (H->running_stmt) { |
123 | | - pgsql_stmt_finish(H->running_stmt, FIN_DISCARD); |
124 | | - } |
125 | | - |
126 | | - PGresult *pgsql_result; |
127 | | - bool first = true; |
128 | | - while ((pgsql_result = PQgetResult(H->server))) { |
129 | | - /* We should not arrive here, where libpq has a result to deliver without us |
130 | | - * having registered a running statement: |
131 | | - * every result discarding should go through the unified pgsql_stmt_finish, |
132 | | - * but maybe there still is an internal query that we omitted to adapt. |
133 | | - * So instead of asserting let's just emit an informational notice, |
134 | | - * and consume anyway (results consumption is handle-wise, so we have no formal |
135 | | - * need for the statement). */ |
136 | | - if (first) { |
137 | | - php_error_docref(NULL, E_NOTICE, "Internal error: unable to link a libpq result to consume, to its origin statement"); |
138 | | - first = false; |
139 | | - } |
140 | | - PQclear(pgsql_result); |
141 | | - } |
142 | | -} |
143 | | - |
144 | 112 | static void _pdo_pgsql_notice(void *context, const char *message) /* {{{ */ |
145 | 113 | { |
146 | 114 | pdo_dbh_t * dbh = (pdo_dbh_t *)context; |
@@ -290,10 +258,6 @@ static void pgsql_handle_closer(pdo_dbh_t *dbh) /* {{{ */ |
290 | 258 | PQfinish(H->server); |
291 | 259 | H->server = NULL; |
292 | 260 | } |
293 | | - if (H->cached_table_name) { |
294 | | - efree(H->cached_table_name); |
295 | | - H->cached_table_name = NULL; |
296 | | - } |
297 | 261 | if (H->einfo.errmsg) { |
298 | 262 | pefree(H->einfo.errmsg, dbh->is_persistent); |
299 | 263 | H->einfo.errmsg = NULL; |
@@ -387,7 +351,6 @@ static zend_long pgsql_handle_doer(pdo_dbh_t *dbh, const zend_string *sql) |
387 | 351 |
|
388 | 352 | bool in_trans = pgsql_handle_in_transaction(dbh); |
389 | 353 |
|
390 | | - pgsql_finish_running_stmt(H); |
391 | 354 | if (!(res = PQexec(H->server, ZSTR_VAL(sql)))) { |
392 | 355 | /* fatal error */ |
393 | 356 | pdo_pgsql_error(dbh, PGRES_FATAL_ERROR, NULL); |
@@ -463,7 +426,6 @@ static zend_string *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const zend_string * |
463 | 426 | PGresult *res; |
464 | 427 | ExecStatusType status; |
465 | 428 |
|
466 | | - pgsql_finish_running_stmt(H); |
467 | 429 | if (name == NULL) { |
468 | 430 | res = PQexec(H->server, "SELECT LASTVAL()"); |
469 | 431 | } else { |
@@ -627,7 +589,6 @@ static bool pdo_pgsql_transaction_cmd(const char *cmd, pdo_dbh_t *dbh) |
627 | 589 | PGresult *res; |
628 | 590 | bool ret = true; |
629 | 591 |
|
630 | | - pgsql_finish_running_stmt(H); |
631 | 592 | res = PQexec(H->server, cmd); |
632 | 593 |
|
633 | 594 | if (PQresultStatus(res) != PGRES_COMMAND_OK) { |
@@ -735,8 +696,9 @@ void pgsqlCopyFromArray_internal(INTERNAL_FUNCTION_PARAMETERS) |
735 | 696 | /* Obtain db Handle */ |
736 | 697 | H = (pdo_pgsql_db_handle *)dbh->driver_data; |
737 | 698 |
|
738 | | - pgsql_discard_running_stmt(H); |
739 | | - |
| 699 | + while ((pgsql_result = PQgetResult(H->server))) { |
| 700 | + PQclear(pgsql_result); |
| 701 | + } |
740 | 702 | pgsql_result = PQexec(H->server, query); |
741 | 703 |
|
742 | 704 | efree(query); |
@@ -858,8 +820,9 @@ void pgsqlCopyFromFile_internal(INTERNAL_FUNCTION_PARAMETERS) |
858 | 820 |
|
859 | 821 | H = (pdo_pgsql_db_handle *)dbh->driver_data; |
860 | 822 |
|
861 | | - pgsql_discard_running_stmt(H); |
862 | | - |
| 823 | + while ((pgsql_result = PQgetResult(H->server))) { |
| 824 | + PQclear(pgsql_result); |
| 825 | + } |
863 | 826 | pgsql_result = PQexec(H->server, query); |
864 | 827 |
|
865 | 828 | efree(query); |
@@ -953,7 +916,9 @@ void pgsqlCopyToFile_internal(INTERNAL_FUNCTION_PARAMETERS) |
953 | 916 | RETURN_FALSE; |
954 | 917 | } |
955 | 918 |
|
956 | | - pgsql_discard_running_stmt(H); |
| 919 | + while ((pgsql_result = PQgetResult(H->server))) { |
| 920 | + PQclear(pgsql_result); |
| 921 | + } |
957 | 922 |
|
958 | 923 | /* using pre-9.0 syntax as PDO_pgsql is 7.4+ compatible */ |
959 | 924 | if (pg_fields) { |
@@ -1042,7 +1007,9 @@ void pgsqlCopyToArray_internal(INTERNAL_FUNCTION_PARAMETERS) |
1042 | 1007 |
|
1043 | 1008 | H = (pdo_pgsql_db_handle *)dbh->driver_data; |
1044 | 1009 |
|
1045 | | - pgsql_discard_running_stmt(H); |
| 1010 | + while ((pgsql_result = PQgetResult(H->server))) { |
| 1011 | + PQclear(pgsql_result); |
| 1012 | + } |
1046 | 1013 |
|
1047 | 1014 | /* using pre-9.0 syntax as PDO_pgsql is 7.4+ compatible */ |
1048 | 1015 | if (pg_fields) { |
@@ -1494,7 +1461,6 @@ static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{ |
1494 | 1461 |
|
1495 | 1462 | H->attached = 1; |
1496 | 1463 | H->pgoid = -1; |
1497 | | - H->cached_table_oid = InvalidOid; |
1498 | 1464 |
|
1499 | 1465 | dbh->methods = &pgsql_methods; |
1500 | 1466 | dbh->alloc_own_columns = 1; |
|
0 commit comments