473,396 Members | 2,010 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 not happy with date fields

I have an UPDATE query that is always setting 0 records. When I cut and
paste the SQL into Access and use it, it fails in the same way unless I
coerce the date fields to be '=now()', in which case it works. I never get
errors, and if I don't try to update the date fields, I always update the
expected number of rows (1). When I do date conversion using the same
conversion function, then call CRowset::Add() to add a record to the same
table, it works as expected.

I am using OLEDB/C++ against Jet 4.0.

Here are some code fragments for reading enjoyment.

Any insights appreciated.

RDeW

---------------------------------
//accessor
class CFileUpdateByNameAccessor

{

public:

void ClearRecord()

{

memset(&this->m_DriveName, 0, offsetof(CFileUpdateByNameAccessor,
m_TextType) + sizeof(m_TextType));

}

wchar_t m_DriveName[DRIVEBUFSIZE];

wchar_t m_DirName[DIRECTORYBUFSIZE];

wchar_t m_FileName[FILEBUFSIZE];

LONG m_Checksum;

LONG m_SizeLo32;

DATE m_CreationDateTime;

DATE m_LastAccessDateTime;

DATE m_ModificationDateTime;

DATE m_SSLastUpdate;

LONG m_TextType;

BEGIN_PARAM_MAP(CFileUpdateByNameAccessor)

COLUMN_ENTRY_TYPE(1, DBTYPE_DATE, m_CreationDateTime)

COLUMN_ENTRY_TYPE(2, DBTYPE_DATE, m_ModificationDateTime)

COLUMN_ENTRY_TYPE(3, DBTYPE_DATE, m_LastAccessDateTime)

COLUMN_ENTRY_TYPE(4, DBTYPE_DATE, m_SSLastUpdate)

COLUMN_ENTRY(5, m_Checksum)

COLUMN_ENTRY(6, m_SizeLo32)

COLUMN_ENTRY(7, m_TextType)

COLUMN_ENTRY(8, m_DriveName)

COLUMN_ENTRY(9, m_DirName)

COLUMN_ENTRY(10, m_FileName)
END_PARAM_MAP()

DEFINE_COMMAND_EX(CFileUpdateByNameAccessor, L"\

UPDATE Files \

SET \

CreationDateTime = (?), \

ModificationDateTime = (?), \

LastAccessDateTime = (?), \

SSLastUpdate = (?), \

Checksum = (?), \

SizeLo32 = (?), \

TextType = (?) \

WHERE \

Files.FileID in \

(SELECT Files.FileID from files, directories, drives \

where drives.name = (?) and \

directories.name = (?) and \

files.name = (?) and \

drives.driveid = directories.driveid and \

files.directoryid = directories.directoryid)")

};

///date conversion function, uses IDataConvert, returns S_OK and
reasonable-looking values

bool CMyDB::FileTimeToDBDate(const FILETIME *pFT, DATE *pD)

{

unsigned long nBytesConverted = 0;

DBSTATUS dbStatus = {0,};

assert(pFT);

assert(pD);

assert(_Module.pCvt);

/*

HRESULT DataConvert (

DBTYPE wSrcType,

DBTYPE wDstType,

ULONG cbSrcLength,

ULONG * pcbDstLength,

void * pSrc,

void * pDst,

ULONG cbDstMaxLength,

DBSTATUS dbsSrcStatus,

DBSTATUS * pdbsStatus,

BYTE bPrecision,

BYTE bScale,

DBDATACONVERT dwFlags);

*/

HRESULT hr =

_Module.pCvt->DataConvert(

DBTYPE_FILETIME, //file time goes in

DBTYPE_DATE, //date comes out

sizeof(*pFT), //size of input

&nBytesConverted, //how many bytes did we get?

(void *)pFT, //data in

(void *)pD, //data out

sizeof(*pD), //size of data out

DBSTATUS_S_OK, //magic per Status page in OLEDB docs

&dbStatus, //address to store status out

0, //don't care about precision ...

0, //...or about scale

DBDATACONVERT_DEFAULT //default conversion

);

if(FAILED(hr))

{

LogDBError(__WFILE__, __LINE__, hr);

return false;

}

assert(nBytesConverted);

assert(SUCCEEDED(dbStatus));

return true;

}

//------------------------UPDATE code, szFN has a "nice" file name here ...

wcsncpy(fun.m_DriveName, szFN, (pDir - szFN));

wcsncpy(fun.m_DirName, pDir, (pFile - pDir));

wcsncpy(fun.m_FileName, pFile, wcslen(pFile));

//here we get the file dates and times as FILETIME structs
if(!GetFileAttributesExW(szFN, GetFileExInfoStandard, &gfi))

return E_INVALIDARG;
FILETIME ft = {0,};

SYSTEMTIME st = {0,};

GetSystemTime(&st);

SystemTimeToFileTime(&st, &ft);

//convert the FILETIMEs to db DATE per fxn above

FileTimeToDBDate(&ft, &fun.m_SSLastUpdate);

FileTimeToDBDate(&gfi.ftCreationTime, &fun.m_CreationDateTime);

FileTimeToDBDate(&gfi.ftLastAccessTime, &fun.m_LastAccessDateTime);

FileTimeToDBDate(&gfi.ftLastWriteTime, &fun.m_ModificationDateTime);

fun.m_Checksum = CalcChecksum(szFN);

fun.m_SizeLo32 = gfi.nFileSizeLow;
hr = fun.Open();
//...error trap omitted, always get S_OK, but nothing updated, stepping into
code shows 0 records updated.

fun.Close();
Nov 13 '05 #1
1 3572
Sorry, that is CRowset::Insert(), not Add()

RDeW

"Riley DeWiley" <ri***********@gmail.com> wrote in message
news:Wf********************@seanet.com...
I have an UPDATE query that is always setting 0 records. When I cut and
paste the SQL into Access and use it, it fails in the same way unless I
coerce the date fields to be '=now()', in which case it works. I never get
errors, and if I don't try to update the date fields, I always update the
expected number of rows (1). When I do date conversion using the same
conversion function, then call CRowset::Add() to add a record to the same
table, it works as expected.

I am using OLEDB/C++ against Jet 4.0.

Here are some code fragments for reading enjoyment.

Any insights appreciated.

RDeW

---------------------------------
//accessor
class CFileUpdateByNameAccessor

{

public:

void ClearRecord()

{

memset(&this->m_DriveName, 0, offsetof(CFileUpdateByNameAccessor,
m_TextType) + sizeof(m_TextType));

}

wchar_t m_DriveName[DRIVEBUFSIZE];

wchar_t m_DirName[DIRECTORYBUFSIZE];

wchar_t m_FileName[FILEBUFSIZE];

LONG m_Checksum;

LONG m_SizeLo32;

DATE m_CreationDateTime;

DATE m_LastAccessDateTime;

DATE m_ModificationDateTime;

DATE m_SSLastUpdate;

LONG m_TextType;

BEGIN_PARAM_MAP(CFileUpdateByNameAccessor)

COLUMN_ENTRY_TYPE(1, DBTYPE_DATE, m_CreationDateTime)

COLUMN_ENTRY_TYPE(2, DBTYPE_DATE, m_ModificationDateTime)

COLUMN_ENTRY_TYPE(3, DBTYPE_DATE, m_LastAccessDateTime)

COLUMN_ENTRY_TYPE(4, DBTYPE_DATE, m_SSLastUpdate)

COLUMN_ENTRY(5, m_Checksum)

COLUMN_ENTRY(6, m_SizeLo32)

COLUMN_ENTRY(7, m_TextType)

COLUMN_ENTRY(8, m_DriveName)

COLUMN_ENTRY(9, m_DirName)

COLUMN_ENTRY(10, m_FileName)
END_PARAM_MAP()

DEFINE_COMMAND_EX(CFileUpdateByNameAccessor, L"\

UPDATE Files \

SET \

CreationDateTime = (?), \

ModificationDateTime = (?), \

LastAccessDateTime = (?), \

SSLastUpdate = (?), \

Checksum = (?), \

SizeLo32 = (?), \

TextType = (?) \

WHERE \

Files.FileID in \

(SELECT Files.FileID from files, directories, drives \

where drives.name = (?) and \

directories.name = (?) and \

files.name = (?) and \

drives.driveid = directories.driveid and \

files.directoryid = directories.directoryid)")

};

///date conversion function, uses IDataConvert, returns S_OK and
reasonable-looking values

bool CMyDB::FileTimeToDBDate(const FILETIME *pFT, DATE *pD)

{

unsigned long nBytesConverted = 0;

DBSTATUS dbStatus = {0,};

assert(pFT);

assert(pD);

assert(_Module.pCvt);

/*

HRESULT DataConvert (

DBTYPE wSrcType,

DBTYPE wDstType,

ULONG cbSrcLength,

ULONG * pcbDstLength,

void * pSrc,

void * pDst,

ULONG cbDstMaxLength,

DBSTATUS dbsSrcStatus,

DBSTATUS * pdbsStatus,

BYTE bPrecision,

BYTE bScale,

DBDATACONVERT dwFlags);

*/

HRESULT hr =

_Module.pCvt->DataConvert(

DBTYPE_FILETIME, //file time goes in

DBTYPE_DATE, //date comes out

sizeof(*pFT), //size of input

&nBytesConverted, //how many bytes did we get?

(void *)pFT, //data in

(void *)pD, //data out

sizeof(*pD), //size of data out

DBSTATUS_S_OK, //magic per Status page in OLEDB docs

&dbStatus, //address to store status out

0, //don't care about precision ...

0, //...or about scale

DBDATACONVERT_DEFAULT //default conversion

);

if(FAILED(hr))

{

LogDBError(__WFILE__, __LINE__, hr);

return false;

}

assert(nBytesConverted);

assert(SUCCEEDED(dbStatus));

return true;

}

//------------------------UPDATE code, szFN has a "nice" file name here
...

wcsncpy(fun.m_DriveName, szFN, (pDir - szFN));

wcsncpy(fun.m_DirName, pDir, (pFile - pDir));

wcsncpy(fun.m_FileName, pFile, wcslen(pFile));

//here we get the file dates and times as FILETIME structs
if(!GetFileAttributesExW(szFN, GetFileExInfoStandard, &gfi))

return E_INVALIDARG;
FILETIME ft = {0,};

SYSTEMTIME st = {0,};

GetSystemTime(&st);

SystemTimeToFileTime(&st, &ft);

//convert the FILETIMEs to db DATE per fxn above

FileTimeToDBDate(&ft, &fun.m_SSLastUpdate);

FileTimeToDBDate(&gfi.ftCreationTime, &fun.m_CreationDateTime);

FileTimeToDBDate(&gfi.ftLastAccessTime, &fun.m_LastAccessDateTime);

FileTimeToDBDate(&gfi.ftLastWriteTime, &fun.m_ModificationDateTime);

fun.m_Checksum = CalcChecksum(szFN);

fun.m_SizeLo32 = gfi.nFileSizeLow;
hr = fun.Open();
//...error trap omitted, always get S_OK, but nothing updated, stepping
into code shows 0 records updated.

fun.Close();

Nov 13 '05 #2

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

Similar topics

2
by: MVA | last post by:
Hi all I have a database where in a table (tbl_Members), there are 2 date fields (DateOfBirth and DateJoined), and also 2 fields which upon entering the data in the form, it automatically works...
3
by: rrh | last post by:
I am trying to update a field in one table with data from another table. The problem I'm running into is I need to base the update on a range of data in the 2nd table. Table 1 has: date field...
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: ...
1
by: Mok | last post by:
Hello, I want to pull information from a table in sql server, bind it to a grid and update those values. I would like to know the best way to do it. I used the configure data adapter wizard and it...
2
by: devine | last post by:
Hi All, I am trying to send an automatic email when an update has been made. My update statement will updates 6 fields, and dependant on one of the fields, I would like to send an email using CDO....
3
by: ringer | last post by:
I am trying to add a functionality into a db I use for my checkbook that will help me plan for and save money for future large expenses. Into a table called tblFutureTransactions I want to enter...
4
by: dougmeece | last post by:
Morning Everyone... I have a table that needs to be append to and also updated. All the fields in the table are populated with data from the text boxes and combo boxes on a form. The Date...
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.