diff --git a/statement.c b/statement.c index f45cd79..0df55d4 100644 --- a/statement.c +++ b/statement.c @@ -296,7 +296,10 @@ PGAPI_FreeStmt(HSTMT hstmt, if (stmt->execute_parent) stmt->execute_parent->execute_delegate = NULL; /* Destroy the statement and free any results, cursors, etc. */ - SC_Destructor(stmt); + //SC_Destructor(stmt); + /*if the connection was give up,return SQL_ERROR.*/ + if(SC_Destructor(stmt) == FALSE) + return SQL_ERROR; } else if (fOption == SQL_UNBIND) SC_unbind_cols(stmt); @@ -477,6 +480,7 @@ SC_Constructor(ConnectionClass *conn) char SC_Destructor(StatementClass *self) { + char cRet = TRUE; CSTR func = "SC_Destructor"; QResultClass *res = SC_get_Result(self); @@ -498,6 +502,12 @@ SC_Destructor(StatementClass *self) SC_initialize_stmts(self, TRUE); + if(self->hdbc && !self->hdbc->pqconn) + { + SC_set_error(self, STMT_COMMUNICATION_ERROR, "connection error.", func); + cRet = FALSE; + } + /* Free the parsed table information */ SC_initialize_cols_info(self, FALSE, TRUE); @@ -525,7 +535,7 @@ SC_Destructor(StatementClass *self) MYLOG(0, "leaving\n"); - return TRUE; + return cRet; } void @@ -2304,7 +2314,6 @@ MYLOG(DETAIL_LOG_LEVEL, "!!SC_fetch return =%d\n", ret); { char fetch[128]; QResultClass *last = NULL, *res; - BOOL refcursor_found = FALSE; /* Iterate the columns in the result to look for refcursors */ numcols = QR_NumResultCols(rhold.first); @@ -2319,12 +2328,7 @@ MYLOG(DETAIL_LOG_LEVEL, "!!SC_fetch return =%d\n", ret); break; } - refcursor_found = TRUE; STR_TO_NAME(self->cursor_name, QR_get_value_backend_text(rhold.first, 0, i)); - /* Skip NULL refcursors (allows procedure to return a variable number of results) */ - if (!SC_cursor_is_valid(self)) - continue; - SC_set_fetchcursor(self); qi.result_in = NULL; qi.cursor = SC_cursor_name(self); @@ -2345,23 +2349,19 @@ MYLOG(DETAIL_LOG_LEVEL, "!!SC_fetch return =%d\n", ret); QR_concat(last, res); self->multi_statement = TRUE; } - last = res; if (!QR_command_maybe_successful(res)) { SC_set_errorinfo(self, res, 0); + QR_Destructor(rhold.first); break; } + + last = res; } } } - if (refcursor_found) - { - /* Discard original result */ - if (NULL == last) - SC_set_Result(self, QR_Constructor()); /* return empty result */ - else - QR_Destructor(rhold.first); - } + if (last) + QR_Destructor(rhold.first); } } cleanup: