473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

UPDATE query results not written to database

Using OLEDB, Jet 4.0, C++, Windows.

I have been baffled by UPDATE queries that return S_OK but do not change the
data in the database. It seems that UPDATEs do not update until the
CDataSource object goes out of scope, in some cases, they seem not to update
at all. Apparently the data is being cached and transmitted through some
kind of flushing mechanism.

I would like to "force" writes of data after executing an UPDATE query
through a CCommand<> derived object.

How do I do this?

Some code is posted below.

class CNumberCommandAccessor

{

public:

LONG m_ID;

DATE m_Num0;

BEGIN_PARAM_MAP(CNumberCommandAccessor)

COLUMN_ENTRY_TYPE(1, DBTYPE_DATE, m_Num0)

COLUMN_ENTRY(2, m_ID)

END_PARAM_MAP()

DEFINE_COMMAND_EX(CNumberCommandAccessor, L"\

UPDATE Table2 \

SET Table2.Num0 = (?) \

WHERE Table2.ID =(?)")

};

int wmain(int argc, wchar_t * argv[])

{
CoInitialize(0);

{

CComPtr<IDataConvert> pCvt = 0;

HRESULT hr = CoCreateInstance(CLSID_OLEDB_CONVERSIONLIBRARY, 0,
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IDataConvert, (void
**)&pCvt);

if(FAILED(hr))

return 0;

CSession session;

CDataSource db;

CDBPropSet dbinit[1];

dbinit[0].SetGUID(DBPROPSET_DBINIT);

dbinit[0].AddProperty(DBPROP_AUTH_USERID, OLESTR("Admin"));

dbinit[0].AddProperty(DBPROP_INIT_DATASOURCE, sDBFile);

dbinit[0].AddProperty(DBPROP_INIT_MODE, (long)16);

dbinit[0].AddProperty(DBPROP_INIT_PROMPT, (short)DBPROMPT_NOPROMPT);
if(Open(session, db, dbinit, 1))

{

//CTable<CAccessor<CDateAccessor> > d;

CCommand<CAccessor<CNumberCommandAccessor> > d;

CDBPropSet propset(DBPROPSET_ROWSET);

propset.AddProperty(DBPROP_IRowsetChange, true);

propset.AddProperty(DBPROP_IRowsetUpdate, true);

propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE |
DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE);

/*

We have a record #6, yes ...

*/

d.m_ID = 6;

d.m_Num0 = SOME_NEW_INTEGER_VALUE;

HRESULT hr = d.Open(session); //I EXPECT to see the changes right after this
executes but don't

if(FAILED(hr))

{

Close(session, db);

return 0;

}
d.Close();

session.Commit();
Close(session, db);

//STILL NO CHANGES

}

//NOW THEY APPEAR - WHY NOW?
}

CoUninitialize();

return 0;

}
Nov 13 '05 #1
3 3529
On Sat, 20 Aug 2005 15:55:39 -0700, "Riley DeWiley"
<ri***********@gmail.com> wrote:

I have no specific knowledge about CCommand, but isn't there an
Execute method? Open seems more for recordset-returning commands
(SELECT statements), whereas Execute is typically used for action
queries like UPDATE, DELETE etc.

Your code reminds me why I don't program in C++ anymore. I've lost
appetite for accomplishing simple tasks with many lines of code.

-Tom.

Using OLEDB, Jet 4.0, C++, Windows.

I have been baffled by UPDATE queries that return S_OK but do not change the
data in the database. It seems that UPDATEs do not update until the
CDataSource object goes out of scope, in some cases, they seem not to update
at all. Apparently the data is being cached and transmitted through some
kind of flushing mechanism.

I would like to "force" writes of data after executing an UPDATE query
through a CCommand<> derived object.

How do I do this?

Some code is posted below.

class CNumberCommandAccessor

{

public:

LONG m_ID;

DATE m_Num0;

BEGIN_PARAM_MAP(CNumberCommandAccessor)

COLUMN_ENTRY_TYPE(1, DBTYPE_DATE, m_Num0)

COLUMN_ENTRY(2, m_ID)

END_PARAM_MAP()

DEFINE_COMMAND_EX(CNumberCommandAccessor, L"\

UPDATE Table2 \

SET Table2.Num0 = (?) \

WHERE Table2.ID =(?)")

};

int wmain(int argc, wchar_t * argv[])

{
CoInitialize(0);

{

CComPtr<IDataConvert> pCvt = 0;

HRESULT hr = CoCreateInstance(CLSID_OLEDB_CONVERSIONLIBRARY, 0,
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IDataConvert, (void
**)&pCvt);

if(FAILED(hr))

return 0;

CSession session;

CDataSource db;

CDBPropSet dbinit[1];

dbinit[0].SetGUID(DBPROPSET_DBINIT);

dbinit[0].AddProperty(DBPROP_AUTH_USERID, OLESTR("Admin"));

dbinit[0].AddProperty(DBPROP_INIT_DATASOURCE, sDBFile);

dbinit[0].AddProperty(DBPROP_INIT_MODE, (long)16);

dbinit[0].AddProperty(DBPROP_INIT_PROMPT, (short)DBPROMPT_NOPROMPT);
if(Open(session, db, dbinit, 1))

{

//CTable<CAccessor<CDateAccessor> > d;

CCommand<CAccessor<CNumberCommandAccessor> > d;

CDBPropSet propset(DBPROPSET_ROWSET);

propset.AddProperty(DBPROP_IRowsetChange, true);

propset.AddProperty(DBPROP_IRowsetUpdate, true);

propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE |
DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE);

/*

We have a record #6, yes ...

*/

d.m_ID = 6;

d.m_Num0 = SOME_NEW_INTEGER_VALUE;

HRESULT hr = d.Open(session); //I EXPECT to see the changes right after this
executes but don't

if(FAILED(hr))

{

Close(session, db);

return 0;

}
d.Close();

session.Commit();
Close(session, db);

//STILL NO CHANGES

}

//NOW THEY APPEAR - WHY NOW?
}

CoUninitialize();

return 0;

}


Nov 13 '05 #2
Yes, this is how the Jet driver works. Data modifications are
asynchronously flushed to the database file.
You have to do some special things to bypass this asynch behavior, I'm
digging around but I can't find anything to help you here. I wrote a KB
article about 5-6 years ago about this but it looks like they deleted it.

Matt Neerincx [MSFT]

This posting is provided "AS IS", with no warranties, and confers no rights.

Please do not send email directly to this alias. This alias is for newsgroup
purposes only.

"Riley DeWiley" <ri***********@gmail.com> wrote in message
news:CN********************@seanet.com...
Using OLEDB, Jet 4.0, C++, Windows.

I have been baffled by UPDATE queries that return S_OK but do not change
the data in the database. It seems that UPDATEs do not update until the
CDataSource object goes out of scope, in some cases, they seem not to
update at all. Apparently the data is being cached and transmitted through
some kind of flushing mechanism.

I would like to "force" writes of data after executing an UPDATE query
through a CCommand<> derived object.

How do I do this?

Some code is posted below.

class CNumberCommandAccessor

{

public:

LONG m_ID;

DATE m_Num0;

BEGIN_PARAM_MAP(CNumberCommandAccessor)

COLUMN_ENTRY_TYPE(1, DBTYPE_DATE, m_Num0)

COLUMN_ENTRY(2, m_ID)

END_PARAM_MAP()

DEFINE_COMMAND_EX(CNumberCommandAccessor, L"\

UPDATE Table2 \

SET Table2.Num0 = (?) \

WHERE Table2.ID =(?)")

};

int wmain(int argc, wchar_t * argv[])

{
CoInitialize(0);

{

CComPtr<IDataConvert> pCvt = 0;

HRESULT hr = CoCreateInstance(CLSID_OLEDB_CONVERSIONLIBRARY, 0,
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IDataConvert, (void
**)&pCvt);

if(FAILED(hr))

return 0;

CSession session;

CDataSource db;

CDBPropSet dbinit[1];

dbinit[0].SetGUID(DBPROPSET_DBINIT);

dbinit[0].AddProperty(DBPROP_AUTH_USERID, OLESTR("Admin"));

dbinit[0].AddProperty(DBPROP_INIT_DATASOURCE, sDBFile);

dbinit[0].AddProperty(DBPROP_INIT_MODE, (long)16);

dbinit[0].AddProperty(DBPROP_INIT_PROMPT, (short)DBPROMPT_NOPROMPT);
if(Open(session, db, dbinit, 1))

{

//CTable<CAccessor<CDateAccessor> > d;

CCommand<CAccessor<CNumberCommandAccessor> > d;

CDBPropSet propset(DBPROPSET_ROWSET);

propset.AddProperty(DBPROP_IRowsetChange, true);

propset.AddProperty(DBPROP_IRowsetUpdate, true);

propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE |
DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE);

/*

We have a record #6, yes ...

*/

d.m_ID = 6;

d.m_Num0 = SOME_NEW_INTEGER_VALUE;

HRESULT hr = d.Open(session); //I EXPECT to see the changes right after
this executes but don't

if(FAILED(hr))

{

Close(session, db);

return 0;

}
d.Close();

session.Commit();
Close(session, db);

//STILL NO CHANGES

}

//NOW THEY APPEAR - WHY NOW?
}

CoUninitialize();

return 0;

}

Nov 13 '05 #3
Ok, found it ->

I wrote this KB eons ago, but it still applies.

"How To Synchronizing Reads and Writes Between Two DAO Processes"
http://support.microsoft.com/kb/180223/EN-US/

Looks like the title was translated to some other language and back and
suffered in the process but the KB has all the info you need.
Matt Neerincx [MSFT]
This posting is provided "AS IS", with no warranties, and confers no rights.

Please do not send email directly to this alias. This alias is for newsgroup
purposes only.

"Matt Neerincx [MS]" <ma***@online.microsoft.com> wrote in message
news:O9**************@TK2MSFTNGP09.phx.gbl...
Yes, this is how the Jet driver works. Data modifications are
asynchronously flushed to the database file.
You have to do some special things to bypass this asynch behavior, I'm
digging around but I can't find anything to help you here. I wrote a KB
article about 5-6 years ago about this but it looks like they deleted it.

Matt Neerincx [MSFT]

This posting is provided "AS IS", with no warranties, and confers no
rights.

Please do not send email directly to this alias. This alias is for
newsgroup purposes only.

"Riley DeWiley" <ri***********@gmail.com> wrote in message
news:CN********************@seanet.com...
Using OLEDB, Jet 4.0, C++, Windows.

I have been baffled by UPDATE queries that return S_OK but do not change
the data in the database. It seems that UPDATEs do not update until the
CDataSource object goes out of scope, in some cases, they seem not to
update at all. Apparently the data is being cached and transmitted
through some kind of flushing mechanism.

I would like to "force" writes of data after executing an UPDATE query
through a CCommand<> derived object.

How do I do this?

Some code is posted below.

class CNumberCommandAccessor

{

public:

LONG m_ID;

DATE m_Num0;

BEGIN_PARAM_MAP(CNumberCommandAccessor)

COLUMN_ENTRY_TYPE(1, DBTYPE_DATE, m_Num0)

COLUMN_ENTRY(2, m_ID)

END_PARAM_MAP()

DEFINE_COMMAND_EX(CNumberCommandAccessor, L"\

UPDATE Table2 \

SET Table2.Num0 = (?) \

WHERE Table2.ID =(?)")

};

int wmain(int argc, wchar_t * argv[])

{
CoInitialize(0);

{

CComPtr<IDataConvert> pCvt = 0;

HRESULT hr = CoCreateInstance(CLSID_OLEDB_CONVERSIONLIBRARY, 0,
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IDataConvert, (void
**)&pCvt);

if(FAILED(hr))

return 0;

CSession session;

CDataSource db;

CDBPropSet dbinit[1];

dbinit[0].SetGUID(DBPROPSET_DBINIT);

dbinit[0].AddProperty(DBPROP_AUTH_USERID, OLESTR("Admin"));

dbinit[0].AddProperty(DBPROP_INIT_DATASOURCE, sDBFile);

dbinit[0].AddProperty(DBPROP_INIT_MODE, (long)16);

dbinit[0].AddProperty(DBPROP_INIT_PROMPT, (short)DBPROMPT_NOPROMPT);
if(Open(session, db, dbinit, 1))

{

//CTable<CAccessor<CDateAccessor> > d;

CCommand<CAccessor<CNumberCommandAccessor> > d;

CDBPropSet propset(DBPROPSET_ROWSET);

propset.AddProperty(DBPROP_IRowsetChange, true);

propset.AddProperty(DBPROP_IRowsetUpdate, true);

propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE |
DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE);

/*

We have a record #6, yes ...

*/

d.m_ID = 6;

d.m_Num0 = SOME_NEW_INTEGER_VALUE;

HRESULT hr = d.Open(session); //I EXPECT to see the changes right after
this executes but don't

if(FAILED(hr))

{

Close(session, db);

return 0;

}
d.Close();

session.Commit();
Close(session, db);

//STILL NO CHANGES

}

//NOW THEY APPEAR - WHY NOW?
}

CoUninitialize();

return 0;

}


Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mohammed Mazid | last post by:
Can anyone please help me here? Basically I have modified the source code and understood it but when I update a record in the db using a JSP, it gives me an error "The flight you selected does...
8
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
5
by: cover | last post by:
I have an input form that passes data when submitted to a second form to let the user know what they have just entered into the db. My question comes with using 'update'. I'd like to query the...
4
by: whitemoss | last post by:
Hi, I've made some changes to my coding..but unfortunately, there were errors when compiling it..dunno how to solve it..hope anyone can help me...the errors: client.c: In function senddata:...
9
by: P3Eddie | last post by:
Hello all! I don't know if this can even be done, but I'm sure you will either help or suggest another avenue to accomplish the same. My problem may be a simple find duplicates / do something...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.