Page 1 of 1

Data Type Mapping bug?

Posted: Wed 13 Dec 2017 13:22
by Jane
Hello! I'm faced with strange behavior of Data Type Mapping. A simplified example from https://www.devart.com/litedac/docs/?da ... apping.htm :

Code: Select all

CREATE TABLE test
( 
 ID                INTEGER PRIMARY KEY AUTOINCREMENT,
 DELPHI_DTTM       DATETIME
);
INSERT INTO test(DELPHI_DTTM) VALUES (43079.0);
43079.0 is the date 10.12.2017 in TDateTime type (double).

Next, add a rule and execute the query:

Code: Select all

LiteQuery.DataTypeMap.Clear;
LiteQuery.DataTypeMap.AddDBTypeRule(liteDateTime, ftDate);
LiteQuery.SQL.Text := 'SELECT DELPHI_DTTM FROM test'
And we get the value = 01.01.1970
Why is that? How to get the correct date - 10.12.2017?

Re: Data Type Mapping bug?

Posted: Wed 13 Dec 2017 13:49
by LopperPenny
@Jons please use google translate.
I realized what the problem was with your code.
But I can not give a clear answer. Now.

Re: Data Type Mapping bug?

Posted: Wed 13 Dec 2017 13:50
by LopperPenny
I mean @Jane .Sorry!

Re: Data Type Mapping bug?

Posted: Thu 14 Dec 2017 05:42
by Jane
LopperPenny wrote:@Jons please use google translate.
I realized what the problem was with your code.
But I can not give a clear answer. Now.
Translated, sorry.
All my code is shown in the example. Where is the error?

Re: Data Type Mapping bug?

Posted: Thu 14 Dec 2017 09:44
by MaximG
According to the documentation ( http://www.sqlite.org/datatype3.html , Section "2.2. Date and Time Datatype" ), SQLite can store date and time in one of the three formats depending on the inserted value. When fetching data, LiteDAC automatically tries to determine the format in which the date and time value is stored. In your case, the date and time format is defined as Unix Time and an incorrect value is obtained. To avoid this error, set the property of Connection NativeDate = False :

Code: Select all

LiteConnection1.Options.NativeDate: = False;
In this case, LiteDAC will assume that the date and time are stored in Delphi format.

Re: Data Type Mapping bug?

Posted: Thu 14 Dec 2017 10:27
by Jane
MaximG wrote:According to the documentation ( http://www.sqlite.org/datatype3.html , Section "2.2. Date and Time Datatype" ), SQLite can store date and time in one of the three formats depending on the inserted value. When fetching data, LiteDAC automatically tries to determine the format in which the date and time value is stored. In your case, the date and time format is defined as Unix Time and an incorrect value is obtained. To avoid this error, set the property of Connection NativeDate = False :

Code: Select all

LiteConnection1.Options.NativeDate: = False;
In this case, LiteDAC will assume that the date and time are stored in Delphi format.
Thank you, so everything worked as it should.

Re: Data Type Mapping bug?

Posted: Thu 14 Dec 2017 10:52
by MaximG
Feel free to contact us if you have any further questions about LiteDAC.