1

What is wrong with my code:

ExecSql('DELETE FROM STLac WHERE RegN=99 AND BegDate>= 2016-12-14');

This runs, but deletes ALL the rows in STLac for RegN, not just the rows with BegDate on or after 2016-12-14. Originally I had:

ExecSql('DELETE FROM STLac WHERE RegN=99 AND BegDate>= :myDdate,[myDate]);

which has the advantage I hoped of not being particular to the date format. So I tried the literal date should in the format SQLite likes. Either way I get all rows deleted, not just those on or after the specified date.

Scott S.

1
  • 2
    Sorry, but I had to calculate this: 2016-12-14 equals 1990, 1990 seconds past Unix epoch puts you at 1970-01-01 00:33:10 Commented Mar 24, 2017 at 22:59

2 Answers 2

4

Try double quote while putting date. As any value must be provided in between quotes until and unless that column is not int

ExecSql('DELETE FROM STLac WHERE RegN=99 AND BegDate>= "2016-12-14"');
0
2

SQLite does not have datetime format as such, so you have to figure out how date is actually represented in the table and change your query to provide the same format. First execute the "select" statement in some kind of management tool,

select * from STLac where RegN = 99 and BegDate >= '2016-12-14' --(or '2016.12.04' or something else)

which displays the result in the grid; when you see the expected rows, change it to "delete" query and copy into your Delphi program.

1
  • Thanks - I discovered the syntax error myself just before the two accepted answer were given. I hate the syntax issues with double quotes and all. Therefore i have tried to use parameters. Can delphi and SQLite not do this stuff for me? As mentioned in my original question, i had tried: ExecSql('DELETE FROM STLac WHERE RegN=99 AND BegDate>= :myDdate,[myDate]). Hoping that the myDate variable would be translated by Delphi and SQLite into the expected string format. I suppose this is another question though. - Scott Commented Mar 26, 2017 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.