Skip to content

Commit 57c9d71

Browse files
committed
Update
1 parent 42af8d1 commit 57c9d71

File tree

2 files changed

+31
-57
lines changed

2 files changed

+31
-57
lines changed

src/cursor.cpp

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ static bool free_results(Cursor* self, int flags)
325325
// this even when a query has not been executed.
326326

327327
// If we ran out of memory, it is possible that we have a cursor but colinfos is zero. However, we should be
328-
// deleting this object, so the cursor will be freed when the HSTMT is destroyed. */
328+
// deleting this object, so the cursor will be freed when the HSTMT is destroyed.
329329

330330
assert((flags & STATEMENT_MASK) != 0);
331331
assert((flags & PREPARED_MASK) != 0);
@@ -347,7 +347,7 @@ static bool free_results(Cursor* self, int flags)
347347
if ((flags & STATEMENT_MASK) == FREE_STATEMENT)
348348
{
349349
Py_BEGIN_ALLOW_THREADS
350-
//SQLFreeStmt(self->hstmt, SQL_CLOSE);
350+
SQLFreeStmt(self->hstmt, SQL_CLOSE);
351351
SQLFreeStmt(self->hstmt, SQL_UNBIND);
352352
SQLFreeStmt(self->hstmt, SQL_RESET_PARAMS);
353353
Py_END_ALLOW_THREADS;
@@ -398,7 +398,7 @@ static void closeimpl(Cursor* cur)
398398
// An internal function for the shared 'closing' code used by Cursor_close and Cursor_dealloc.
399399
//
400400
// This method releases the GIL lock while closing, so verify the HDBC still exists if you use it.
401-
/*
401+
402402
free_results(cur, FREE_STATEMENT | FREE_PREPARED);
403403

404404
FreeParameterData(cur);
@@ -430,7 +430,7 @@ static void closeimpl(Cursor* cur)
430430
cur->map_name_to_index = 0;
431431
cur->cnxn = 0;
432432
cur->messages = 0;
433-
*/
433+
434434
}
435435

436436
static char close_doc[] =
@@ -682,23 +682,13 @@ int GetDiagRecs(Cursor* cur)
682682
return 0;
683683
}
684684

685-
685+
static bool first_prepare = false;
686686
static PyObject * prepare_statement(Cursor* cur, PyObject* pSql, PyObject* params, bool skip_first)
687687
{
688-
// Internal function to execute SQL, called by .execute and .executemany.
688+
// Internal function to execute SQL, called by .prepareStatement
689689
//
690690
// pSql
691691
// A PyString, PyUnicode, or derived object containing the SQL.
692-
//
693-
// params
694-
// Pointer to an optional sequence of parameters, and possibly the SQL statement (see skip_first):
695-
// (SQL, param1, param2) or (param1, param2).
696-
//
697-
// skip_first
698-
// If true, the first element in `params` is ignored. (It will be the SQL statement and `params` will be the
699-
// entire tuple passed to Cursor.execute.) Otherwise all of the params are used. (This case occurs when called
700-
// from Cursor.executemany, in which case the sequences do not contain the SQL statement.) Ignored if params is
701-
// zero.
702692

703693
if (params)
704694
{
@@ -713,40 +703,18 @@ static PyObject * prepare_statement(Cursor* cur, PyObject* pSql, PyObject* param
713703

714704
SQLRETURN ret = 0;
715705

716-
free_results(cur, FREE_STATEMENT | KEEP_PREPARED);
706+
//free_results(cur, FREE_STATEMENT | KEEP_PREPARED);
717707

718708
const char* szLastFunction = "";
719709

710+
if (!Prepare(cur, pSql))
711+
{
712+
return 0;
713+
}
720714

721-
if (!Prepare(cur, pSql, params, skip_first))
722-
return 0;
723-
724-
725-
715+
first_prepare = true;
726716
Py_INCREF(cur);
727717
return (PyObject*)cur;
728-
729-
730-
//return NULL;
731-
// Internal function to prepare SQL, called by .prepare
732-
//
733-
// pSql
734-
// A PyString, PyUnicode, or derived object containing the SQL.
735-
//
736-
// skip_first
737-
// If true, the first element in `params` is ignored. (It will be the SQL statement and `params` will be the
738-
// entire tuple passed to Cursor.execute.) Otherwise all of the params are used. (This case occurs when called
739-
// from Cursor.executemany, in which case the sequences do not contain the SQL statement.) Ignored if params is
740-
// zero.
741-
742-
// Normalize the parameter variables.
743-
//free_results(cur, FREE_STATEMENT | KEEP_PREPARED);
744-
//Prepare(NULL, NULL);
745-
//SQLRETURN ret = 0;
746-
// Prepare(cur, pSql);//))
747-
//return 0;
748-
//return ret;
749-
//return cur->hstmt;
750718
}
751719

752720

@@ -766,17 +734,26 @@ static PyObject* executePreparedStatement(Cursor* cur, PyObject* params, bool sk
766734

767735
SQLRETURN ret = 0;
768736

769-
//free_results(cur, FREE_STATEMENT | KEEP_PREPARED);
770-
737+
FreeParameterData(cur);
738+
739+
SQLCancelHandle(SQL_HANDLE_STMT, cur->hstmt);
740+
/*if (first_prepare) {
741+
//SQLFreeStmt(cur->hstmt, SQL_CLOSE);
742+
//SQLFreeStmt(cur->hstmt, SQL_UNBIND);
743+
//SQLFreeStmt(cur->hstmt, SQL_RESET_PARAMS);
744+
first_prepare = false;
745+
} else {
746+
SQLCancelHandle(SQL_HANDLE_DBC, cur->hstmt);
747+
}*/
771748
const char* szLastFunction = "";
772749

773-
if (!Bind(cur, params, skip_first))
774-
return 0;
750+
if (!Bind(cur, params, skip_first))
751+
return 0;
775752

776-
szLastFunction = "SQLExecute";
777-
Py_BEGIN_ALLOW_THREADS
778-
ret = SQLExecute(cur->hstmt);
779-
Py_END_ALLOW_THREADS
753+
szLastFunction = "SQLExecute";
754+
Py_BEGIN_ALLOW_THREADS
755+
ret = SQLExecute(cur->hstmt);
756+
Py_END_ALLOW_THREADS
780757

781758

782759
if (cur->cnxn->hdbc == SQL_NULL_HANDLE)
@@ -984,9 +961,6 @@ static PyObject* executePreparedStatement(Cursor* cur, PyObject* params, bool sk
984961
return (PyObject*)cur;
985962
}
986963

987-
988-
989-
990964
static PyObject* execute(Cursor* cur, PyObject* pSql, PyObject* params, bool skip_first)
991965
{
992966
// Internal function to execute SQL, called by .execute and .executemany.
@@ -1017,7 +991,7 @@ static PyObject* execute(Cursor* cur, PyObject* pSql, PyObject* params, bool ski
1017991

1018992
SQLRETURN ret = 0;
1019993

1020-
free_results(cur, FREE_STATEMENT | KEEP_PREPARED);
994+
free_results(cur, KEEP_STATEMENT | KEEP_PREPARED);
1021995

1022996
const char* szLastFunction = "";
1023997

src/params.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ bool Prepare(Cursor* cur, PyObject* pSql)
13531353
//
13541354
// Prepare the SQL if necessary.
13551355
//
1356-
if (pSql != cur->pPreparedSQL)
1356+
//if (pSql != cur->pPreparedSQL)
13571357
{
13581358
FreeParameterInfo(cur);
13591359

0 commit comments

Comments
 (0)