473,778 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 CFileUpdateByNa meAccessor

{

public:

void ClearRecord()

{

memset(&this->m_DriveName, 0, offsetof(CFileU pdateByNameAcce ssor,
m_TextType) + sizeof(m_TextTy pe));

}

wchar_t m_DriveName[DRIVEBUFSIZE];

wchar_t m_DirName[DIRECTORYBUFSIZ E];

wchar_t m_FileName[FILEBUFSIZE];

LONG m_Checksum;

LONG m_SizeLo32;

DATE m_CreationDateT ime;

DATE m_LastAccessDat eTime;

DATE m_ModificationD ateTime;

DATE m_SSLastUpdate;

LONG m_TextType;

BEGIN_PARAM_MAP (CFileUpdateByN ameAccessor)

COLUMN_ENTRY_TY PE(1, DBTYPE_DATE, m_CreationDateT ime)

COLUMN_ENTRY_TY PE(2, DBTYPE_DATE, m_ModificationD ateTime)

COLUMN_ENTRY_TY PE(3, DBTYPE_DATE, m_LastAccessDat eTime)

COLUMN_ENTRY_TY PE(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(CFileUpdateB yNameAccessor, L"\

UPDATE Files \

SET \

CreationDateTim e = (?), \

ModificationDat eTime = (?), \

LastAccessDateT ime = (?), \

SSLastUpdate = (?), \

Checksum = (?), \

SizeLo32 = (?), \

TextType = (?) \

WHERE \

Files.FileID in \

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

where drives.name = (?) and \

directories.nam e = (?) and \

files.name = (?) and \

drives.driveid = directories.dri veid and \

files.directory id = directories.dir ectoryid)")

};

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

bool CMyDB::FileTime ToDBDate(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

&nBytesConverte d, //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_D EFAULT //default conversion

);

if(FAILED(hr))

{

LogDBError(__WF ILE__, __LINE__, hr);

return false;

}

assert(nBytesCo nverted);

assert(SUCCEEDE D(dbStatus));

return true;

}

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

wcsncpy(fun.m_D riveName, szFN, (pDir - szFN));

wcsncpy(fun.m_D irName, pDir, (pFile - pDir));

wcsncpy(fun.m_F ileName, pFile, wcslen(pFile));

//here we get the file dates and times as FILETIME structs
if(!GetFileAttr ibutesExW(szFN, GetFileExInfoSt andard, &gfi))

return E_INVALIDARG;
FILETIME ft = {0,};

SYSTEMTIME st = {0,};

GetSystemTime(& st);

SystemTimeToFil eTime(&st, &ft);

//convert the FILETIMEs to db DATE per fxn above

FileTimeToDBDat e(&ft, &fun.m_SSLastUp date);

FileTimeToDBDat e(&gfi.ftCreati onTime, &fun.m_Creation DateTime);

FileTimeToDBDat e(&gfi.ftLastAc cessTime, &fun.m_LastAcce ssDateTime);

FileTimeToDBDat e(&gfi.ftLastWr iteTime, &fun.m_Modifica tionDateTime);

fun.m_Checksum = CalcChecksum(sz FN);

fun.m_SizeLo32 = gfi.nFileSizeLo w;
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 3601
Sorry, that is CRowset::Insert (), not Add()

RDeW

"Riley DeWiley" <ri***********@ gmail.com> wrote in message
news:Wf******** ************@se anet.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 CFileUpdateByNa meAccessor

{

public:

void ClearRecord()

{

memset(&this->m_DriveName, 0, offsetof(CFileU pdateByNameAcce ssor,
m_TextType) + sizeof(m_TextTy pe));

}

wchar_t m_DriveName[DRIVEBUFSIZE];

wchar_t m_DirName[DIRECTORYBUFSIZ E];

wchar_t m_FileName[FILEBUFSIZE];

LONG m_Checksum;

LONG m_SizeLo32;

DATE m_CreationDateT ime;

DATE m_LastAccessDat eTime;

DATE m_ModificationD ateTime;

DATE m_SSLastUpdate;

LONG m_TextType;

BEGIN_PARAM_MAP (CFileUpdateByN ameAccessor)

COLUMN_ENTRY_TY PE(1, DBTYPE_DATE, m_CreationDateT ime)

COLUMN_ENTRY_TY PE(2, DBTYPE_DATE, m_ModificationD ateTime)

COLUMN_ENTRY_TY PE(3, DBTYPE_DATE, m_LastAccessDat eTime)

COLUMN_ENTRY_TY PE(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(CFileUpdateB yNameAccessor, L"\

UPDATE Files \

SET \

CreationDateTim e = (?), \

ModificationDat eTime = (?), \

LastAccessDateT ime = (?), \

SSLastUpdate = (?), \

Checksum = (?), \

SizeLo32 = (?), \

TextType = (?) \

WHERE \

Files.FileID in \

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

where drives.name = (?) and \

directories.nam e = (?) and \

files.name = (?) and \

drives.driveid = directories.dri veid and \

files.directory id = directories.dir ectoryid)")

};

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

bool CMyDB::FileTime ToDBDate(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

&nBytesConverte d, //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_D EFAULT //default conversion

);

if(FAILED(hr))

{

LogDBError(__WF ILE__, __LINE__, hr);

return false;

}

assert(nBytesCo nverted);

assert(SUCCEEDE D(dbStatus));

return true;

}

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

wcsncpy(fun.m_D riveName, szFN, (pDir - szFN));

wcsncpy(fun.m_D irName, pDir, (pFile - pDir));

wcsncpy(fun.m_F ileName, pFile, wcslen(pFile));

//here we get the file dates and times as FILETIME structs
if(!GetFileAttr ibutesExW(szFN, GetFileExInfoSt andard, &gfi))

return E_INVALIDARG;
FILETIME ft = {0,};

SYSTEMTIME st = {0,};

GetSystemTime(& st);

SystemTimeToFil eTime(&st, &ft);

//convert the FILETIMEs to db DATE per fxn above

FileTimeToDBDat e(&ft, &fun.m_SSLastUp date);

FileTimeToDBDat e(&gfi.ftCreati onTime, &fun.m_Creation DateTime);

FileTimeToDBDat e(&gfi.ftLastAc cessTime, &fun.m_LastAcce ssDateTime);

FileTimeToDBDat e(&gfi.ftLastWr iteTime, &fun.m_Modifica tionDateTime);

fun.m_Checksum = CalcChecksum(sz FN);

fun.m_SizeLo32 = gfi.nFileSizeLo w;
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
10389
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 out the Age (in years) and number of DaysJoined (in days). It works fine but it does not automatically update the Age or DaysJoined columns on opening the form. Can anyone make a suggestion as to how I could say, open up the Switchboard frm,...
3
6312
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 new field table 2 has: key field (autonumber)
9
4356
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 predecessor, I hasten to add) so that each day it creates a copy of the record for each company, changes the date to today's date, and prompts the user for any changes of ratings on that day. The resulting data table grows by approx 600 records per...
8
3724
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: "Date","P1","P2","P3","P4","P5","P6","P7","P8","P9","P10","P11","P12","P13","P14","P15","P16","P17","P18","P19","P20","P21" 1/1/2005,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21 1/2/2005,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
1
2777
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 came up with a crazy stored proc. As in this example I would only update and : CREATE PROCEDURE . ( @Description varchar(1000),
2
2850
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. Once the update is made, I am trying to re-query the database to retrieve all the fields that need to be included in the email, but it's just not working for me!! This my code to update <% Set Conn = Server.CreateObject("ADODB.Connection")...
3
4883
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 records for upcoming large expenses, the dollar amount needed, the date the money is needed, and the date I want to start saving. Then I want the db to automatically figure and deduct from my balance an amount of money from each paycheck to save for...
4
2408
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 Submitted defaults to 1/1/00 if the cboSubmittedBox field is "No". Otherwise it is selected from a calendar. The Date Entered field defaults to the current date. There are 3 sets of criteria that need to be checked for the update or append to take place. ...
2
2638
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 update the information which is stored in a SQL database. In testing we noticed that the form was updating correctly but the update mechanism was also updating the first record of the table in the sql database every time. No error messages are on...
0
10296
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10068
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7474
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.