Change SQLFreeStmt(.., SQL_CLOSE) to not DEALLOCATE prepared statements.
authorHiroshi Inoue <inoue@tpf.co.jp>
Fri, 20 Dec 2002 08:30:04 +0000 (08:30 +0000)
committerHiroshi Inoue <inoue@tpf.co.jp>
Fri, 20 Dec 2002 08:30:04 +0000 (08:30 +0000)
execute.c
statement.c
statement.h

index ea2e089d6440d09438b027adba79521cf6ac034e..5bd32449b9ce04871bfb53a21e7a880655d621e9 100644 (file)
--- a/execute.c
+++ b/execute.c
@@ -101,7 +101,7 @@ PGAPI_Prepare(HSTMT hstmt,
    }
 
    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) */
@@ -152,7 +152,7 @@ PGAPI_ExecDirect(
    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
@@ -304,7 +304,7 @@ RETCODE Exec_with_parameters_resolved(StatementClass *stmt, BOOL *exec_end)
            res->next = NULL;
            QR_Destructor(res);
            res = kres;
-           stmt->prepared = TRUE;
+           SC_set_prepared(stmt, TRUE);
        }
        else
        {
index fdb71435b898c3aee2d65dbf9aba796eedf62c5d..ccdc82379d92836c5d5622a3bea06e9a8ccaa5e8 100644 (file)
@@ -433,7 +433,7 @@ SC_free_params(StatementClass *self, char option)
 
 
 int
-statement_type(char *statement)
+statement_type(const char *statement)
 {
    int         i;
 
@@ -448,6 +448,28 @@ statement_type(char *statement)
    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.
@@ -456,10 +478,19 @@ statement_type(char *statement)
 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)
    {
@@ -471,26 +502,7 @@ SC_initialize_stmts(StatementClass *self, BOOL initializeOriginal)
        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;
 }
 
index ab60beb243288476ea3f8cef415d7fa635b9aed6..c1ccc70151aa8aa96874d7a59171d657c698bf7c 100644 (file)
@@ -262,7 +262,7 @@ struct StatementClass_
 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);
@@ -275,6 +275,7 @@ void        SC_error_copy(StatementClass *self, const StatementClass *from);
 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);