diff options
| -rw-r--r-- | execute.c | 5 | ||||
| -rw-r--r-- | odbcapi.c | 1 | ||||
| -rw-r--r-- | qresult.c | 21 | ||||
| -rw-r--r-- | qresult.h | 1 | ||||
| -rw-r--r-- | statement.c | 31 | ||||
| -rw-r--r-- | statement.h | 1 |
6 files changed, 51 insertions, 9 deletions
@@ -976,16 +976,13 @@ PGAPI_Execute(HSTMT hstmt, UWORD flag) else if (PREPARED_PERMANENTLY == stmt->prepared || PREPARED_TEMPORARILY == stmt->prepared) { - QResultClass *res; - /* * re-executing an prepared statement. * Don't recycle the statement but * discard the old result. */ recycle = FALSE; - if (res = SC_get_Result(stmt), res) - QR_close_result(res, FALSE); + SC_reset_result_for_rerun(stmt); } /* * If SQLExecute is being called again, recycle the statement. Note @@ -386,6 +386,7 @@ SQLExecute(HSTMT StatementHandle) else { StartRollbackState(stmt); + stmt->exec_current_row = -1; ret = PGAPI_Execute(StatementHandle, flag); ret = DiscardStatementSvp(stmt, ret, FALSE); } @@ -196,7 +196,6 @@ QR_Constructor(void) rv->notice = NULL; rv->conn = NULL; rv->next = NULL; - rv->pstatus = 0; rv->count_backend_allocated = 0; rv->count_keyset_allocated = 0; rv->num_total_read = 0; @@ -320,6 +319,25 @@ QR_close_result(QResultClass *self, BOOL destroy) } void +QR_reset_for_re_execute(QResultClass *self) +{ + mylog("QResult: enter %s for %x\n", __FUNCTION__, self); + if (!self) return; + QR_close_result(self, FALSE); + /* reset flags etc */ + self->flags = 0; + QR_set_rowstart_in_cache(self, -1); + self->recent_processed_row_count = -1; + /* clear error info etc */ + self->rstatus = PORES_EMPTY_QUERY; + self->aborted = FALSE; + self->sqlstate[0] = '\0'; + self->messageref = NULL; + + mylog("QResult: exit %s\n", __FUNCTION__); +} + +void QR_Destructor(QResultClass *self) { mylog("QResult: enter DESTRUCTOR\n"); @@ -464,6 +482,7 @@ QR_free_memory(QResultClass *self) self->count_backend_allocated = 0; self->backend_tuples = NULL; self->dataFilled = FALSE; + self->tupleField = NULL; } if (self->keyset) { @@ -226,6 +226,7 @@ int QR_next_tuple(QResultClass *self, StatementClass *, int *LastMessageType); int QR_close(QResultClass *self); void QR_on_close_cursor(QResultClass *self); void QR_close_result(QResultClass *self, BOOL destroy); +void QR_reset_for_re_execute(QResultClass *self); char QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, const char *cursor, int *LastMessageType); void QR_free_memory(QResultClass *self); void QR_set_command(QResultClass *self, const char *msg); diff --git a/statement.c b/statement.c index a6229f6..78013cc 100644 --- a/statement.c +++ b/statement.c @@ -805,6 +805,27 @@ SC_initialize_and_recycle(StatementClass *self) return SQL_SUCCESS; } +void +SC_reset_result_for_rerun(StatementClass *self) +{ + QResultClass *res; + ColumnInfoClass *flds; + + if (!self) return; + if (res = SC_get_Result(self), NULL == res) + return; + flds = QR_get_fields(res); + if (NULL == flds || + 0 == CI_get_num_fields(flds)) + SC_set_Result(self, NULL); + else + { + QR_reset_for_re_execute(res); + self->curr_param_result = 1; + SC_set_Curres(self, NULL); + } +} + /* * Called from SQLPrepare if STMT_PREMATURE, or * from SQLExecute if STMT_FINISHED, or @@ -880,11 +901,10 @@ inolog("SC_clear_parse_status\n"); { case PREPARED_PERMANENTLY: case PREPARED_TEMPORARILY: - QR_close_result(res, FALSE); + SC_reset_result_for_rerun(self); break; default: - QR_Destructor(res); - SC_init_Result(self); + SC_set_Result(self, NULL); break; } } @@ -2533,7 +2553,8 @@ ReflectColumnsInfo(StatementClass *self, QResultClass *res) if (res->num_fields > 0) return FALSE; pres = SC_get_Result(self); - if (pres != res && + if (pres != NULL && + pres != res && pres->num_fields > 0) { QR_set_fields(res, QR_get_fields(pres)); @@ -2626,6 +2647,8 @@ inolog(" response_length=%d\n", response_length); res->recent_processed_row_count = ret1; } } + else if (QR_command_successful(res)) + QR_set_rstatus(res, PORES_COMMAND_OK); break; case 'E': /* ErrorMessage */ handle_error_message(conn, msgbuffer, sizeof(msgbuffer), res->sqlstate, comment, res); diff --git a/statement.h b/statement.h index 6a138be..25f8c32 100644 --- a/statement.h +++ b/statement.h @@ -466,6 +466,7 @@ char SC_Destructor(StatementClass *self); BOOL SC_opencheck(StatementClass *self, const char *func); RETCODE SC_initialize_and_recycle(StatementClass *self); void SC_initialize_cols_info(StatementClass *self, BOOL DCdestroy, BOOL parseReset); +void SC_reset_result_for_rerun(StatementClass *self); int statement_type(const char *statement); char parse_statement(StatementClass *stmt, BOOL); char parse_sqlsvr(StatementClass *stmt); |
