BUG: Jet Truncates DBTIMESTAMP Fraction Element Without Warning (294164)



The information in this article applies to:

  • Microsoft OLE DB Provider for Jet 4.0

This article was previously published under Q294164

SYMPTOMS

When you use the DBTIMESTAMP structure to update a Date/Time field in a Microsoft Access table, the fraction element of the structure may be truncated or ignored without warning or error.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

The Date/Time field is mapped to DBTYPE_DATE by design. However, when you use DBTIMESTAMP to obtain more information, the update operation completes successfully and returns S_OK status. This should return an error message, or at least a warning.

Steps to Reproduce Behavior

  1. Create an Access 2000 database named "Test.mdb" with a table named "TestTable".
  2. Name one of the fields of this table "date_time" and make it type DATE/TIME.
  3. Run the code below.NOTE: Modify the Path_to_your_database entry to reflect your database path when setting the DBPROP_INIT_DATASOURCE property in the code.
    #define _ATL_STATIC_REGISTRY 
    #define _ATL_DEBUG_QI   // For debug output of ATL X COM.
    #define _ATL_DEBUG_INTERFACES
    
    #include <atldbcli.h>
    #include <iostream.h>
    
    #define RETURNHR(hr) if(FAILED((HRESULT)hr)) { AtlTraceErrorRecords((HRESULT)hr); return E_FAIL; }
    
    // The user record looks like this.
    class CcmdTest 
    {
    public:
       // Data elements.
       DBTIMESTAMP m_datetime;
       ULONG m_status;
    
       BEGIN_COLUMN_MAP(CcmdTest)
    	COLUMN_ENTRY_STATUS(1, m_datetime,m_status)
       END_COLUMN_MAP()
    };
    
    
    class CcmdTestRetrieval
    {
    public:
       // Data elements.
       DBTIMESTAMP m_datetime;
       ULONG m_status;
       
       BEGIN_COLUMN_MAP(CcmdTestRetrieval)
          COLUMN_ENTRY_STATUS(1,m_datetime,m_status)
          END_COLUMN_MAP()
          // output binding map
    };
    
    
    int main(void)
    {
       HRESULT hr;
       CDataSource connection;
       CSession session;
       CCommand<CAccessor<CcmdTest> > cmdTest;            // Update the data.
       CCommand<CAccessor< CcmdTestRetrieval> > cmdTest2; // Retrieve the data.
       
       // Connect the database, session, and accessors.
       CoInitialize(NULL);
       CDBPropSet dbinit(DBPROPSET_DBINIT);
       dbinit.AddProperty(DBPROP_AUTH_CACHE_AUTHINFO, true);
       dbinit.AddProperty(DBPROP_AUTH_ENCRYPT_PASSWORD, false);
       dbinit.AddProperty(DBPROP_AUTH_MASK_PASSWORD, false);
       dbinit.AddProperty(DBPROP_AUTH_PASSWORD, OLESTR(""));
       dbinit.AddProperty(DBPROP_AUTH_USERID, OLESTR("Admin"));
       dbinit.AddProperty(DBPROP_INIT_DATASOURCE, OLESTR("Path_to_your_database\\Test.mdb"));
       dbinit.AddProperty(DBPROP_INIT_MODE, (long)16);
       dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);
       dbinit.AddProperty(DBPROP_INIT_PROVIDERSTRING, OLESTR(""));
       dbinit.AddProperty(DBPROP_INIT_LCID, (long)1033);
       dbinit.AddProperty(DBPROP_AUTH_CACHE_AUTHINFO, true);
       
       hr = connection.Open(_T("Microsoft.Jet.OLEDB.4.0"), &dbinit);
       RETURNHR(hr);
       
       // Create the session.
       hr = session.Open(connection);
       RETURNHR(hr);
       
       // Get updatable rowset.
       CDBPropSet rsProps(DBPROPSET_ROWSET);
       rsProps.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE);
       rsProps.AddProperty(DBPROP_IRowsetChange, true);
       rsProps.AddProperty(DBPROP_IRowsetUpdate, true);
       rsProps.AddProperty(DBPROP_IRowsetScroll, true);
       
       hr = cmdTest.Open(session, "Select date_time from TestTable2", &rsProps);
       RETURNHR(hr);
       
       hr = cmdTest.MoveFirst();
       RETURNHR(hr);
       
       // Set the structure to update the date/time field.
       DBTIMESTAMP tm;
    
       tm.day      = 20;
       tm.fraction = 1000;
       tm.hour     = 2;
       tm.minute   = 20;
       tm.month    = 7;
       tm.second   = 30;
       tm.year     = 2000;
       
       cmdTest.m_datetime = tm;	
       cmdTest.m_status  = DBSTATUS_S_OK;
    
       hr = cmdTest.SetData();
       hr = cmdTest.Update();
       
       cmdTest.Close();
       cmdTest.ReleaseCommand();
       
       // Retrieve the data.
       hr = cmdTest2.Open(session, "Select date_time from TestTable");
       RETURNHR(hr);
       
       hr = cmdTest2.MoveFirst();
       RETURNHR(hr);
    
       // Now check cmdTest2 in the watch window. 
       // You will find the fraction element of m_datetime is set to 0. 
    
       cmdTest2.Close();
       cmdTest2.ReleaseCommand();
       session.Close( );
       connection.Close();
    
       return S_OK;
    }
    					

Modification Type:MajorLast Reviewed:7/19/2001
Keywords:kbbug kbDSupport kbJET KB294164