10 Sep 08 2:36
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.
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);
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?