Andi
Compile this program with the current xHarbour and you will see the
error on the date comparisons ..
Rick Lipkin
// AccessDB.prg
// creating an access database from code
// showing how date time field translates incorrectly
STATIC lOK
//-------------
Local catNewDB,xProvider,xConnect,cFile,aDir,dExe,cDefa,mStart
Local oCn,cSql,oErr,oRsUser,cLOGIN,Saying
Local cTitle,oWnd1,oBrw,oCol,nYear,dCreatedate
setmode( 25, 80 )
lOK := .F.
//-- get timestamp on .exe //
cFILE := HB_ARGV(0)
aDIR := DIRECTORY( cFILE )
// where .exe started from is default directory //
mSTART := RAT( "\", cFILE )
cDEFA := SUBSTR(cFILE,1,mSTART-1)
aDIR := NIL
SET DEFA to ( cDEFA )
SET DELETED on
SET CENTURY on
nYEAR := ( year( DATE() )-30 )
SET EPOCH to ( nYEAR )
Ferase( cDefa+"\Rick.mdb" )
xPROVIDER := "Microsoft.Jet.OLEDB.4.0"
xSOURCE := cDEFA+"\Rick.mdb"
xPASSWORD := "dec2011"
// create the adox object
Try
catNewDB := CreateObject("ADOX.Catalog")
Catch
? "Could not Create ADOX object"
wait
Return(.f.)
End try
// create the table Rick.mdb
Try
catNewDB:Create('Provider='+xProvider+';Data Source='+xSource+';Jet
OLEDB:Engine Type=5;Jet OLEDB:Database Password='+xPASSWORD )
Catch
? "Could not create the table "+xSource
wait
Return(.f.)
End Try
// global connection string
xCONNECT := 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Jet
OLEDB:Database Password='+xPASSWORD
Try
oCn := CREATEOBJECT( "ADODB.Connection" )
Catch
? "Could not create the ADO object for connection"
wait
End Try
TRY
oCn:Open( xCONNECT )
CATCH oErr
? "Could not open a Connection to Database "+xSource
wait
RETURN(.F.)
END TRY
cSQL := "CREATE TABLE USERINFO"
cSQL += "( "
cSQL += "[USEREID] char(18) NOT NULL, "
cSQL += "[USERID] char(8) NULL, "
cSQL += "[READONLY] char(1) NULL, "
cSQL += "[WRITEONLY] char(1) NULL, "
cSQL += "[SUPER] char(1) NULL, "
cSQL += "[LASTLOG] datetime NULL, "
cSQL += "[CREATEDATE] datetime NULL, "
cSQL += "[PASSWORD] char(10) NULL, "
cSQL += "CONSTRAINT PK_USERINFO PRIMARY KEY ( USEREID )"
cSQL += " )"
// create the table Userinfo
// with primary key
Try
oCn:Execute( cSQL )
Catch
? "Table USERINFO Failed"
wait
Return(.f.)
End try
oCn:Close()
oCn := nil
cLOGIN := upper(NetName(.T.))+space(8)
cLOGIN := SUBSTR(cLOGIN,1,8)
// open the Userinfo table record set
// append the first record
// could have also used a connection and the INSERT command
oRsUser := TOleAuto():New( "ADODB.Recordset" )
oRsUser:CursorType := 1 // opendkeyset
oRsUser:CursorLocation := 3 // local cache
oRsUser:LockType := 3 // lockoportunistic
// check for very first user
cSQL := "SELECT * FROM USERINFO"
TRY
oRsUser:Open( cSQL, xCONNECT )
CATCH oErr
? "Error in Opening USERINFO table here"
wait
RETURN(.F.)
END TRY
If oRsUser:eof
oRsUser:AddNew()
oRsUser:Fields("UserEid"):Value := "011111111111111111"
oRsUser:Fields("UserId"):Value := cLOGIN
oRsUser:Fields("ReadOnly"):Value := "Y"
oRsUser:Fields("WriteOnly"):Value := "Y"
oRsUser:Fields("Super"):Value := "Y"
oRsUser:Fields("CreateDate"):Value := dtoc(DATE())+" "+time()
oRsUser:Fields("LastLog"):Value := dtoc(DATE())+" "+time()
oRsUser:Fields("PassWord"):Value := "ADMIN"
oRsUser:Update()
Endif
dCreateDate := oRsUser:Fields("CreateDate"):Value
oRsUser:Close()
? dCreateDate
? ValType( dCreateDate )
wait
? (date()+3) - dCreateDate // errors here with current xHarbour
wait
Return(nil)