I used the below code to fill the table using BulkOperations (abbrev.)
After finishing it, the table is filled with all values, BUT the cursor
still
hangs (as seen in the Enterprise manager) and blocks the next created
cursor, so the deadlock arises and the program freezes.
What am I doing wrong?
Thanks for your answers in advance, Michael
#define MAX_STRUCT 1
struct InsCard {
unsigned long ID_IMPORTU;
long i1;
};
InsCard* ICStruct;
ICStruct = (InsCard*)malloc(MAX_STRUCT*sizeof(InsCard));
SQLAllocStmt( hdbc, &hstmt);
SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_ARRAY_SIZE, (void*)MAX_STRUCT, 0);
SQLSetStmtAttr(hstmt, SQL_ATTR_CONCURRENCY,(void*)SQL_CONCUR_VALUES,0);
SQLSetStmtAttr(hstmt, SQL_ATTR_CURSOR_TYPE,
(void*)SQL_CURSOR_KEYSET_DRIVEN, 0);
SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_BIND_TYPE, (void*)sizeof(InsCard), 0);
SQLBindCol(stmtSel, 1, SQL_C_ULONG, &ICStruct[0].ID_IMPORTU, 0,
&ICStruct[0].i1);
ICStruct[0].i2=0;
SQLExecDirect(stmtSel, (UCHAR*)sql, SQL_NTS);
ICStruct[0].ID_IMPORTU =1;
ICStruct[0].i1 =0;
int currentrow=1;
SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_ARRAY_SIZE, (void*)currentrow, 0);
SQLBulkOperations(hstmt, SQL_ADD);
free(ICStruct);
SQLCloseCursor(hstmt);
SQLCancel(hstmt);
SQLFreeStmt(hstmt, SQL_DROP);
P.S.
The presence or absence of SQLCloseCursor(hstmt) and/or SQLCancel(hstmt)
is not affecting the deadlock by any way.