|
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); |
39 | 40 |
|
40 | 41 | static char * _pdo_pgsql_trim_message(const char *message, int persistent) |
41 | 42 | { |
@@ -103,6 +104,13 @@ int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, int errcode, const char * |
103 | 104 | } |
104 | 105 | /* }}} */ |
105 | 106 |
|
| 107 | +static zend_always_inline void pgsql_finish_running_stmt(pdo_pgsql_db_handle *H) |
| 108 | +{ |
| 109 | + if (H->running_stmt && H->running_stmt->is_running_unbuffered) { |
| 110 | + pgsql_stmt_finish(H->running_stmt, 0); |
| 111 | + } |
| 112 | +} |
| 113 | + |
106 | 114 | static void _pdo_pgsql_notice(void *context, const char *message) /* {{{ */ |
107 | 115 | { |
108 | 116 | pdo_dbh_t * dbh = (pdo_dbh_t *)context; |
@@ -348,6 +356,7 @@ static zend_long pgsql_handle_doer(pdo_dbh_t *dbh, const zend_string *sql) |
348 | 356 |
|
349 | 357 | bool in_trans = pgsql_handle_in_transaction(dbh); |
350 | 358 |
|
| 359 | + pgsql_finish_running_stmt(H); |
351 | 360 | if (!(res = PQexec(H->server, ZSTR_VAL(sql)))) { |
352 | 361 | /* fatal error */ |
353 | 362 | pdo_pgsql_error(dbh, PGRES_FATAL_ERROR, NULL); |
@@ -415,6 +424,7 @@ static zend_string *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const zend_string * |
415 | 424 | PGresult *res; |
416 | 425 | ExecStatusType status; |
417 | 426 |
|
| 427 | + pgsql_finish_running_stmt(H); |
418 | 428 | if (name == NULL) { |
419 | 429 | res = PQexec(H->server, "SELECT LASTVAL()"); |
420 | 430 | } else { |
@@ -578,6 +588,7 @@ static bool pdo_pgsql_transaction_cmd(const char *cmd, pdo_dbh_t *dbh) |
578 | 588 | PGresult *res; |
579 | 589 | bool ret = true; |
580 | 590 |
|
| 591 | + pgsql_finish_running_stmt(H); |
581 | 592 | res = PQexec(H->server, cmd); |
582 | 593 |
|
583 | 594 | if (PQresultStatus(res) != PGRES_COMMAND_OK) { |
@@ -686,6 +697,7 @@ void pgsqlCopyFromArray_internal(INTERNAL_FUNCTION_PARAMETERS) |
686 | 697 | while ((pgsql_result = PQgetResult(H->server))) { |
687 | 698 | PQclear(pgsql_result); |
688 | 699 | } |
| 700 | + pgsql_finish_running_stmt(H); /* Maybe in the future combine with the getResult loop in a pgsql_consume_running_stmt */ |
689 | 701 | pgsql_result = PQexec(H->server, query); |
690 | 702 |
|
691 | 703 | efree(query); |
@@ -810,6 +822,7 @@ void pgsqlCopyFromFile_internal(INTERNAL_FUNCTION_PARAMETERS) |
810 | 822 | while ((pgsql_result = PQgetResult(H->server))) { |
811 | 823 | PQclear(pgsql_result); |
812 | 824 | } |
| 825 | + pgsql_finish_running_stmt(H); /* Maybe in the future combine with the getResult loop in a pgsql_consume_running_stmt */ |
813 | 826 | pgsql_result = PQexec(H->server, query); |
814 | 827 |
|
815 | 828 | efree(query); |
@@ -906,6 +919,7 @@ void pgsqlCopyToFile_internal(INTERNAL_FUNCTION_PARAMETERS) |
906 | 919 | while ((pgsql_result = PQgetResult(H->server))) { |
907 | 920 | PQclear(pgsql_result); |
908 | 921 | } |
| 922 | + pgsql_finish_running_stmt(H); /* Maybe in the future combine with the getResult loop in a pgsql_consume_running_stmt */ |
909 | 923 |
|
910 | 924 | /* using pre-9.0 syntax as PDO_pgsql is 7.4+ compatible */ |
911 | 925 | if (pg_fields) { |
@@ -997,6 +1011,7 @@ void pgsqlCopyToArray_internal(INTERNAL_FUNCTION_PARAMETERS) |
997 | 1011 | while ((pgsql_result = PQgetResult(H->server))) { |
998 | 1012 | PQclear(pgsql_result); |
999 | 1013 | } |
| 1014 | + pgsql_finish_running_stmt(H); /* Maybe in the future combine with the getResult loop in a pgsql_consume_running_stmt */ |
1000 | 1015 |
|
1001 | 1016 | /* using pre-9.0 syntax as PDO_pgsql is 7.4+ compatible */ |
1002 | 1017 | if (pg_fields) { |
|
0 commit comments