Monday, March 12, 2012

OLEDB Bookmarks

I generated an ATL OLEDB Consumer with the VS 2005 wizard. The table is very simple and is located on my local SQL Server. It has two varchar columns and no keys or constraints. I can modify, insert and delete rows with no problem.

Now I want to use bookmarks. I added the following to the accessor class:

1. CBookmark<4> m_bookmark; // member variable

2. pPropSet->AddProperty(DBPROP_IRowsetLocate, true); // rowset property

3. BOOKMARK_ENTRY(m_bookmark) // column map entry

Now I can delete but I can no longer modify or insert. The error is DB_E_ERRORSOCCURED and the status of the two columns after a setdata or insert is DBSTATUS_E_UNAVAILABLE. This is the only error information available.

When I comment out the bookmark entry from the column map, I can modify, insert and delete again. The problem appears to be in how IRowsetChange handles bookmarks. I tried adding bookmarks to other tables using the above 3 steps and they also refuse to modify or insert with bookmarks enabled.

The bookmarks appear to be correct, as I can do a successful MoveToBookmark for any row in the table.

My environment: Windows XP SP2, VC++ 2005, SQL Server 2005 Express, WTL 8.0

Any ideas?

I guess you are doing the following when you modify:

Request IRowsetUpdate/IRowsetChange (get a rowset off that) and bind the columns (IColumnsInfo::GetColumnInfo) to create the accessor, you will see bookmark column. Detect this column and not bind it (use column flags to detect it) when you create the accessor. Or also try to set the status to DBSTATUS_S_IGNORE (so that when you update it will be ignored)

Hope this works

|||

Excellent suggestions, Raj! I created a new macro called bookmark_entry_status in atldbcli.h and in my application I set the status of the bookmark status variable to DBSTATUS_S_IGNORE. Now I can modify, insert and delete consumers that have bookmarks enabled. Here is the macro:

#define BOOKMARK_ENTRY_STATUS(variable, status) \

COLUMN_ENTRY_TYPE_STATUS(0, DBTYPE_BYTES, status, variable##.m_rgBuffer)

Thanks for the ideas. It set me on the proper path to the solution.

No comments:

Post a Comment