Man, I hate having to get you guys to hold my hand through all this, but I've run into another problem. I have my ODBC connecting to a MS access database. This is all coded into a library that gets injected into a video game, and then macro commands call the functions that connect to the database.
After I got it all set up, and wrote a small little test macro which was a loop with a 1 millisecond delay in it, and a function call to the database it totally craps the game out. The ODBC stuff keeps program control while doing the query, and i guess since its injected into the game, it freezes the game for about 1/10th to 1/100th of a second. But this function is to be utilized in a loop... so it just bogs the shit out of the game..... anyone have any ideas on this?
Is there a way to fix that? It would be nice to do the query and have it immediately come back out of the function without waiting for the return... then setup my own loop to wait for it.
I'm not 100% sure my assumption of the problem is correct. Posting the function below with some of the non pertinant stuff left out. For my purposes I only wanted 1 value return so there is no result set loop, and it only links 1 column.
I looped it with a query of "SELECT COUNT(*) WHERE name = 'bob';"
What it looked like in the game it was injected in was as if my framerate dropped to 2 or 3.
bool QueryOneCol(PCHAR query, PCHAR result) {
char szDSN[256];
HENV hEnv;
HDBC hDbc;
RETCODE rc;
int iConnStrLength2Ptr;
char szConnStrOut[256];
SQLCHAR RetCol[128];
int ret;
SQLSMALLINT fieldCount = 0;
HSTMT hStmt;
sprintf(szDSN,"Driver={Microsoft Access Driver (*.mdb)};DSN='';DBQ=%s\\%s;",gszINIPath,dbfilename);
rc = SQLAllocEnv(&hEnv);
rc = SQLAllocConnect(hEnv, &hDbc);
rc = SQLDriverConnect(hDbc, NULL, (unsigned char*)szDSN,SQL_NTS, (unsigned char*)szConnStrOut,255, (SQLSMALLINT*)&iConnStrLength2Ptr, SQL_DRIVER_NOPROMPT);
if (!SQL_SUCCEEDED(rc)) return false;
rc = SQLAllocStmt(hDbc,&hStmt);
rc = SQLPrepare(hStmt, (SQLCHAR*)query, SQL_NTS);
rc = SQLBindCol(hStmt, 1, SQL_C_CHAR, RetCol, 128,(SQLINTEGER*)&ret);
rc = SQLExecute(hStmt);
if (!SQL_SUCCEEDED(rc)) return false;
SQLNumResultCols(hStmt, &fieldCount);
if (fieldCount == 0) return false;
rc = SQLFetch(hStmt);
strcpy(result,(PCHAR)RetCol);
rc = SQLFreeStmt(hStmt, SQL_DROP);
SQLDisconnect(hDbc);
SQLFreeHandle(SQL_HANDLE_DBC, hDbc);
SQLFreeHandle(SQL_HANDLE_ENV, hEnv);
return true;
}