Skip to content

Commit dd888df

Browse files
committed
Update
1 parent 3bc5be1 commit dd888df

File tree

3 files changed

+278
-24
lines changed

3 files changed

+278
-24
lines changed

src/cursor.cpp

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <datetime.h>
2727
#include "handle.h"
2828

29+
#include <stdio.h>
30+
2931
enum
3032
{
3133
CURSOR_REQUIRE_CNXN = 0x00000001,
@@ -711,13 +713,15 @@ static PyObject * prepare_statement(Cursor* cur, PyObject* pSql, PyObject* param
711713
{
712714
return 0;
713715
}
714-
716+
//return RaiseErrorV(0, PyExc_TypeError, "You called Prepare and now I am going to die");
715717
Py_INCREF(cur);
716718
Handle *hndl = Handle_New(cur);
717719
hndl->hstmt = cur->hstmt;
720+
//fprintf(stderr, "There: %i", cur->hstmt)
718721
return (PyObject*)hndl;
719722
}
720723

724+
#include <unistd.h>
721725

722726
static PyObject* executePreparedStatement(Cursor* cur, Handle *hndl, PyObject* params, bool skip_first)
723727
{
@@ -735,19 +739,29 @@ static PyObject* executePreparedStatement(Cursor* cur, Handle *hndl, PyObject* p
735739

736740
SQLRETURN ret = 0;
737741

738-
FreeParameterData(cur);
739-
740-
SQLCancelHandle(SQL_HANDLE_STMT, hndl->hstmt);
742+
free_results(cur, KEEP_STATEMENT | KEEP_PREPARED);
743+
FreeParameterData(cur);
744+
SQLFreeStmt(hndl->hstmt, SQL_RESET_PARAMS);
745+
SQLFreeStmt(hndl->hstmt, SQL_UNBIND);
746+
SQLCloseCursor(hndl->hstmt);
747+
//SQLCancelHandle(SQL_HANDLE_STMT, hndl->hstmt);
748+
//fprintf(stderr, "Statment Handle %p Handle Id %i", hndl, *(int *)hndl->hstmt);
741749

742750
const char* szLastFunction = "";
743751

744-
if (!Bind(cur, params, skip_first))
752+
cur->hstmt = hndl->hstmt;
753+
if (!BindWithHandle(cur, hndl, params, skip_first))
745754
return 0;
755+
//sleep(5);
746756

747-
szLastFunction = "SQLExecute";
757+
//return RaiseErrorV(0, PyExc_TypeError, "You called Bind and now i am going to die");
748758
Py_BEGIN_ALLOW_THREADS
749759
ret = SQLExecute(hndl->hstmt);
750760
Py_END_ALLOW_THREADS
761+
762+
//fprintf(stderr, "SQLExecute: %i\n", ret);
763+
//sleep(5);
764+
//return RaiseErrorV(0, PyExc_TypeError, "You called execute and now i am going to die");
751765

752766

753767
if (cur->cnxn->hdbc == SQL_NULL_HANDLE)
@@ -787,27 +801,21 @@ static PyObject* executePreparedStatement(Cursor* cur, Handle *hndl, PyObject* p
787801
Py_BEGIN_ALLOW_THREADS
788802
ret = SQLParamData(hndl->hstmt, (SQLPOINTER*)&pInfo);
789803
Py_END_ALLOW_THREADS
790-
804+
//fprintf(stderr, "paramdata\n");
791805
if (ret != SQL_NEED_DATA && ret != SQL_NO_DATA && !SQL_SUCCEEDED(ret))
792806
return RaiseErrorFromHandle(cur->cnxn, "SQLParamData", cur->cnxn->hdbc, hndl->hstmt);
793807

794808
TRACE("SQLParamData() --> %d\n", ret);
795809

796-
if (ret == SQL_NEED_DATA)
797-
{
810+
if (ret == SQL_NEED_DATA) {
798811
szLastFunction = "SQLPutData";
799-
if (pInfo->pObject && (PyBytes_Check(pInfo->pObject) || PyByteArray_Check(pInfo->pObject)
800-
))
801-
{
812+
if (pInfo->pObject && (PyBytes_Check(pInfo->pObject) || PyByteArray_Check(pInfo->pObject))) {
802813
char *(*pGetPtr)(PyObject*);
803814
Py_ssize_t (*pGetLen)(PyObject*);
804-
if (PyByteArray_Check(pInfo->pObject))
805-
{
815+
if (PyByteArray_Check(pInfo->pObject)) {
806816
pGetPtr = PyByteArray_AsString;
807817
pGetLen = PyByteArray_Size;
808-
}
809-
else
810-
{
818+
} else {
811819
pGetPtr = PyBytes_AsString;
812820
pGetLen = PyBytes_Size;
813821
}
@@ -818,6 +826,7 @@ static PyObject* executePreparedStatement(Cursor* cur, Handle *hndl, PyObject* p
818826

819827
do
820828
{
829+
//fprintf(stderr, "do putdata\n");
821830
SQLLEN remaining = pInfo->maxlength ? min(pInfo->maxlength, cb - offset) : cb;
822831
TRACE("SQLPutData [%d] (%d) %.10s\n", offset, remaining, &p[offset]);
823832
Py_BEGIN_ALLOW_THREADS
@@ -882,6 +891,7 @@ static PyObject* executePreparedStatement(Cursor* cur, Handle *hndl, PyObject* p
882891
}
883892
else
884893
{
894+
//fprintf(stderr, "else putdata\n");
885895
// TVP column sent as DAE
886896
Py_BEGIN_ALLOW_THREADS
887897
ret = SQLPutData(hndl->hstmt, pInfo->ParameterValuePtr, pInfo->BufferLength);
@@ -890,9 +900,12 @@ static PyObject* executePreparedStatement(Cursor* cur, Handle *hndl, PyObject* p
890900
return RaiseErrorFromHandle(cur->cnxn, "SQLPutData", cur->cnxn->hdbc, hndl->hstmt);
891901
}
892902
ret = SQL_NEED_DATA;
903+
893904
}
894-
}
895905

906+
}
907+
908+
//return RaiseErrorV(0, ProgrammingError, "fadsTHEREH");
896909
FreeParameterData(cur);
897910

898911
if (ret == SQL_NO_DATA)
@@ -951,6 +964,9 @@ static PyObject* executePreparedStatement(Cursor* cur, Handle *hndl, PyObject* p
951964
return 0;
952965
}
953966

967+
//return RaiseErrorV(0, PyExc_TypeError, "You called executeCPreparedStatement and now i am going to die");
968+
969+
954970
Py_INCREF(cur);
955971
return (PyObject*)cur;
956972
}
@@ -1352,8 +1368,8 @@ PyObject* Cursor_executePreparedStatement(PyObject* self, PyObject* args)
13521368
skip_first = true;
13531369
}
13541370

1371+
//fprintf(stderr, "Here: %i", ((Handle *)hndl)->hstmt);
13551372
// Execute.
1356-
13571373
return executePreparedStatement(cursor, (Handle *)hndl, params, skip_first);
13581374
}
13591375

0 commit comments

Comments
 (0)