You are not logged in.
Pages: 1
The following does not work as I expected:
Baby := TSQLBaby.Create;
Baby.name := 'Kurt';
Baby.Sex := sMale;
dt := encodeDate(2018,01,03);
Baby.BirthDate := dt;
Baby.Address := 'Lindesberg';
aClient.Add(Baby, true);
Baby.Free;
Baby := TSQLBaby.CreateAndFillPrepare( aClient, 'BirthDate = ?',[DateToSQL(dt)]);
while Baby.FillOne do
begin
Memo1.lines.Add(Format('>>>>>>>>>> %s - %s ',[Baby.Name, Baby.Address])+' // '+FormatDateTime('yyyy-mm-dd', Baby.BirthDate));
end;
BirthDate and dt is clearly the same date so why didn't I get a hit from the query?
Last edited by larand54 (2019-04-07 16:47:05)
Delphi-11, WIN10
Offline
Try DateTimeToSQL instead.
A related discussion is here: https://synopse.info/forum/viewtopic.php?id=4909
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
It doesn't matter if I change to DateTimeToSQL. Still no hit.
You only get hits when using :
Baby := TSQLBaby.CreateAndFillPrepare( aClient, 'BirthDate <> ?',[DateTimeToSQL(dt)]);
or whenever you use '<' or '>' but thats not what I want in this case. I want hits on a certain date.
Maybe this wont work with fpc and lazarus? But I thought it would.
I'm running on Windows10.
Still hope on some help or explanation
Delphi-11, WIN10
Offline
You could try this:
Baby := TSQLBaby.CreateAndFillPrepare( aClient, 'BirthDate>? and BirthDate<?',[DateTimeToSQL(StartOfTheDay(dt)),DateTimeToSQL(EndOfTheDay(dt))]);
Offline
I just tested that, but, sorry ... no hit.
Date seems to be a problem in mORMot.
Maybe it could also depend on SQLite3? I never had any such problems in Delphi with firedac and MSSQL.
Delphi-11, WIN10
Offline
If you use sqlitebrowser, what does the BirthDate column data show ?
Offline
I use SQLIteStudio 3.2.1
which gives the following output:
ID Name Address BirthDate Sex
310 Fredrik Stockholm 43259.5122240741 1
311 Kristina Lund 43294.5122242593 0
312 Kurt Lindesberg 43103 1
The last line is the line I searched for which is 2018-01-03.
Delphi-11, WIN10
Offline
There you go [replace > with >= and < with <= ... I hope this will work]:
Baby := TSQLBaby.CreateAndFillPrepare( aClient, 'BirthDate>=? and BirthDate<=?',[DateTimeToSQL(StartOfTheDay(dt)),DateTimeToSQL(EndOfTheDay(dt))]);
Offline
Sorry, but that didn't work either.
Can there be any more solutions to test?
Delphi-11, WIN10
Offline
In my sqlite-databases, a datetime looks like:
2017-10-26T15:47:14
In your case, its just a float (double). So DateTimeToSQL will not work. Try:
Baby := TSQLBaby.CreateAndFillPrepare( aClient, 'BirthDate>=? and BirthDate<=?',[Double(StartOfTheDay(dt)),Double(EndOfTheDay(dt))]);
Offline
Finally it worked
I could also reduce it to:
Baby := TSQLBaby.CreateAndFillPrepare( aClient, 'BirthDate=?',[double(dt)]);
So you may ask... Why all this about using DateToSQL and DateTimeToSQL when you should cast it to a double?
It has to be some other situations when you need to use them but when?
Thank's !
PS
Is there any Convention how to mark a thread solved here ?
DS
Delphi-11, WIN10
Offline
Finally it worked
I could also reduce it to:
Baby := TSQLBaby.CreateAndFillPrepare( aClient, 'BirthDate=?',[double(dt)]);
So you may ask... Why all this about using DateToSQL and DateTimeToSQL when you should cast it to a double?
It has to be some other situations when you need to use them but when?PS
Is there any Convention how to mark a thread solved here ?
DS
It's not very normal that the datetime values are stored as Double, what type is TSQLBaby.BirthDate? If it's defined as either TDateTime or TDate, and if the saving is done via mORMot, the field values stored to the db should be something like @AOG posted, in iso8601 format, by design of the framework, check the doc here.
I usually edit the forum post and add '[solved]' to the title.
Last edited by edwinsn (2019-04-07 03:44:13)
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
Ok, that solved some mystery about this. I have declared BirthDate as TDate and that result as FLOAT in SQLite3. When I changed to TDateTime I got TEXT in SQLite3.
Strange that TDate and TDateTime is not treated the same here.
That solved everything about this and if I had choosen TDateTime from the begining, this topic would not been created
Delphi-11, WIN10
Offline
Pages: 1