Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: if the connection is broken when calling SQLFreeHandle, the client can't be notified #1

Closed
wants to merge 12 commits into from
22 changes: 17 additions & 5 deletions statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -525,7 +535,7 @@ SC_Destructor(StatementClass *self)

MYLOG(0, "leaving\n");

return TRUE;
return cRet;
}

void
Expand Down Expand Up @@ -2304,7 +2314,7 @@ MYLOG(DETAIL_LOG_LEVEL, "!!SC_fetch return =%d\n", ret);
{
char fetch[128];
QResultClass *last = NULL, *res;
BOOL refcursor_found = FALSE;
BOOL refcursor_found = FALSE;

/* Iterate the columns in the result to look for refcursors */
numcols = QR_NumResultCols(rhold.first);
Expand All @@ -2319,9 +2329,9 @@ MYLOG(DETAIL_LOG_LEVEL, "!!SC_fetch return =%d\n", ret);
break;
}

refcursor_found = TRUE;
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) */
/* Skip NULL refcursors (allows procedure to return a variable number of results) */
if (!SC_cursor_is_valid(self))
continue;

Expand Down Expand Up @@ -2349,6 +2359,7 @@ MYLOG(DETAIL_LOG_LEVEL, "!!SC_fetch return =%d\n", ret);
if (!QR_command_maybe_successful(res))
{
SC_set_errorinfo(self, res, 0);
QR_Destructor(rhold.first);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was removed in f3d6671 on purpose to fix a crash (due to destructing the same object twice) and should not be added back. rhold.first is destructed on line 2374 below.

break;
}
}
Expand All @@ -2362,6 +2373,7 @@ MYLOG(DETAIL_LOG_LEVEL, "!!SC_fetch return =%d\n", ret);
else
QR_Destructor(rhold.first);
}

}
}
cleanup:
Expand Down