}
self->prepare = TRUE;
- self->prepared = FALSE;
+ SC_set_prepared(self, FALSE);
self->statement_type = statement_type(self->statement);
/* Check if connection is onlyread (only selects are allowed) */
mylog("**** %s: hstmt=%u, statement='%s'\n", func, hstmt, stmt->statement);
stmt->prepare = FALSE;
- stmt->prepared = FALSE;
+ SC_set_prepared(stmt, FALSE);
/*
* If an SQLPrepare was performed prior to this, but was left in the
res->next = NULL;
QR_Destructor(res);
res = kres;
- stmt->prepared = TRUE;
+ SC_set_prepared(stmt, TRUE);
}
else
{
int
-statement_type(char *statement)
+statement_type(const char *statement)
{
int i;
return STMT_TYPE_OTHER;
}
+void
+SC_set_prepared(StatementClass *stmt, BOOL prepared)
+{
+ if (prepared == stmt->prepared)
+ return;
+ if (!prepared)
+ {
+ ConnectionClass *conn = SC_get_conn(stmt);
+ if (CONN_CONNECTED == conn->status)
+ {
+ QResultClass *res;
+ char dealloc_stmt[128];
+
+ sprintf(dealloc_stmt, "DEALLOCATE _PLAN%0x", stmt);
+ res = CC_send_query(conn, dealloc_stmt, NULL, 0);
+ if (res)
+ QR_Destructor(res);
+ }
+ }
+ stmt->prepared = prepared;
+}
+
/*
* Initialize stmt_with_params, load_statement and execute_statement
* member pointer deallocating corresponding prepared plan.
RETCODE
SC_initialize_stmts(StatementClass *self, BOOL initializeOriginal)
{
- if (initializeOriginal && self->statement)
+ if (initializeOriginal)
{
- free(self->statement);
- self->statement = NULL;
+ if (self->statement)
+ {
+ free(self->statement);
+ self->statement = NULL;
+ }
+ if (self->execute_statement)
+ {
+ free(self->execute_statement);
+ self->execute_statement = NULL;
+ }
+ SC_set_prepared(self,FALSE);
}
if (self->stmt_with_params)
{
free(self->load_statement);
self->load_statement = NULL;
}
- if (self->execute_statement)
- {
- free(self->execute_statement);
- self->execute_statement = NULL;
- }
- if (self->prepared)
- {
- ConnectionClass *conn = SC_get_conn(self);
- if (CONN_CONNECTED == conn->status)
- {
- QResultClass *res;
- char dealloc_stmt[128];
- sprintf(dealloc_stmt, "DEALLOCATE _PLAN%0x", self);
- res = CC_send_query(conn, dealloc_stmt, NULL, 0);
- if (res)
- QR_Destructor(res);
- }
- self->prepared = FALSE;
- }
return 0;
}
StatementClass *SC_Constructor(void);
void InitializeStatementOptions(StatementOptions *opt);
char SC_Destructor(StatementClass *self);
-int statement_type(char *statement);
+int statement_type(const char *statement);
char parse_statement(StatementClass *stmt);
void SC_pre_execute(StatementClass *self);
char SC_unbind_cols(StatementClass *self);
void SC_full_error_copy(StatementClass *self, const StatementClass *from);
char SC_get_error(StatementClass *self, int *number, char **message);
char *SC_create_errormsg(const StatementClass *self);
+void SC_set_prepared(StatementClass *self, BOOL);
RETCODE SC_initialize_stmts(StatementClass *self, BOOL);
RETCODE SC_execute(StatementClass *self);
RETCODE SC_fetch(StatementClass *self);