Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to achieve concurrency with ODBC and MS Jet 4.0

Status
Not open for further replies.

ivoef

Programmer
May 8, 2002
27
CZ
Hi,

I would like to know, how could I resolve the following problem:

I am using ODBC API a MS JET 4.0 driver (MS Access database). In the database there is a simple table with two columns called "Counter" and "IDRow". "IDRow" serves as ID for selecting an unique row.

I need to read and then immediately increment and store a value of the column "Counter" corectly when two or more independent processes are doing the same on this column.

Goal:

When one process reads, increments and stores the value of "Counter", no other process can update this column or the process should be aware of such change.

I have tried to use a cursor with SQL_CURSOR_KEYSET_DRIVEN and SQL_CONCUR_VALUES and SQLSetPos function the following way:

SQLAllocHandle(SQL_HANDLE_STMT, pstRPDBApi->hODBCConSys, &hSysStmt);
SQLSetStmtAttr(hSysStmt, SQL_ATTR_CURSOR_TYPE, (SQLPOINTER) SQL_CURSOR_KEYSET_DRIVEN, SQL_IS_UINTEGER);
SQLSetStmtAttr(hSysStmt, SQL_ATTR_CONCURRENCY, (SQLPOINTER) SQL_CONCUR_VALUES, SQL_IS_UINTEGER);
SQLBindCol(hSysStmt, 1, SQL_C_USHORT, &sunCounter, sizeof(sunIDRelaceNew);
SQLExecDirect(hSysStmt, "SELECT Counter FROM tabTest WHERE IDRow=1", SQL_NTS);
SQLFetch(hSysStmt);

At this point I change from outside the value of Counter at row where IDRow=1 and then continue with the following statement:

SQLSetPos(hSysStmt, 1, SQL_UPDATE, SQL_LOCK_NO_CHANGE);

According to the documentation (if I understood it) I should get an error because of changing the value of "Counter" between fetching and updating with cursor of this type. But there is no error and value is updatet with SQL_SUCCESS.

Could anybody help me with this problem please?

Ivo

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top