Data Type Mapping bug?

Discussion of open issues, suggestions and bugs regarding LiteDAC (SQLite Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Jane
Posts: 3
Joined: Wed 13 Dec 2017 13:19

Data Type Mapping bug?

Post by Jane » Wed 13 Dec 2017 13:22

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?
Last edited by Jane on Thu 14 Dec 2017 05:40, edited 1 time in total.

LopperPenny
Posts: 3
Joined: Wed 13 Dec 2017 13:32

Re: Data Type Mapping bug?

Post by LopperPenny » Wed 13 Dec 2017 13:49

@Jons please use google translate.
I realized what the problem was with your code.
But I can not give a clear answer. Now.

LopperPenny
Posts: 3
Joined: Wed 13 Dec 2017 13:32

Re: Data Type Mapping bug?

Post by LopperPenny » Wed 13 Dec 2017 13:50

I mean @Jane .Sorry!

Jane
Posts: 3
Joined: Wed 13 Dec 2017 13:19

Re: Data Type Mapping bug?

Post by Jane » Thu 14 Dec 2017 05:42

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?

MaximG
Devart Team
Posts: 1019
Joined: Mon 06 Jul 2015 11:34

Re: Data Type Mapping bug?

Post by MaximG » Thu 14 Dec 2017 09:44

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.

Jane
Posts: 3
Joined: Wed 13 Dec 2017 13:19

Re: Data Type Mapping bug?

Post by Jane » Thu 14 Dec 2017 10:27

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.

MaximG
Devart Team
Posts: 1019
Joined: Mon 06 Jul 2015 11:34

Re: Data Type Mapping bug?

Post by MaximG » Thu 14 Dec 2017 10:52

Feel free to contact us if you have any further questions about LiteDAC.

Post Reply