Recent

Author Topic: [SOLVED]Unable to search SQLite3 database records in time period  (Read 887 times)

SNPI

  • Newbie
  • Posts: 5
[SOLVED]Unable to search SQLite3 database records in time period
« on: February 21, 2020, 08:38:13 am »
Hi guys!I want to search the records in a certain period of time on a date,but the following error message appears during searching operation.
Can anyone help me to modify the SQL code?Thanks in advance to all!


Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3. SQLQuery1.close;
  4. SQLQuery1.SQL.Clear;
  5. SQLQuery1.SQL.Add('select * from DATA where Date='''+Dateedit1.Text+'''and Time>='''+Timeedit1.Text+'''Time<='''+timeedit2.Text+'''');
  6.  SQLQuery1.ExecSQL;
  7.  SQLQuery1.Open;
  8. end;  
« Last Edit: February 21, 2020, 09:43:58 am by SNPI »

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: Unable to search SQLite3 database records in time period
« Reply #1 on: February 21, 2020, 09:00:11 am »
Nevermind, that you:
1) should use Parameters
2) should not use Keywords as Column-Names
3) use ExecSQL on a Query which returns Datasets
4) shouldn't separate Date and Time in separate columns
5) Pretty sure there is more......

On first look you're missing a blank  in front of your "and Time"
« Last Edit: February 21, 2020, 09:04:32 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

SNPI

  • Newbie
  • Posts: 5
Re: Unable to search SQLite3 database records in time period
« Reply #2 on: February 21, 2020, 09:17:43 am »
Nevermind, that you:
1) should use Parameters
2) should not use Keywords as Column-Names
3) use ExecSQL on a Query which returns Datasets
4) shouldn't separate Date and Time in separate columns
5) Pretty sure there is more......

On first look you're missing a blank  in front of your "and Time"
I did miss two blank.Zvoni,thanks a lot!
Code: Pascal  [Select][+][-]
  1. SQLQuery1.SQL.Add('select * from DATA where Date='''+Dateedit1.Text+''' and Time>='''+Timeedit1.Text+''' and Time<='''+timeedit2.Text+'''');

af0815

  • Hero Member
  • *****
  • Posts: 1291
Re: [SOLVED]Unable to search SQLite3 database records in time period
« Reply #3 on: February 21, 2020, 11:28:46 am »
If you use Parameters the SQl will more readable and safer. You must only change the params and can leave the sql untouched.
regards
Andreas

 

TinyPortal © 2005-2018