Recent

Author Topic: [SOLVED] SQLite SQL error  (Read 1320 times)

dodgebros

  • Full Member
  • ***
  • Posts: 169
[SOLVED] SQLite SQL error
« on: March 21, 2022, 04:09:34 pm »
Hi all, I get this error with the following code: SQLiteConnection1: near 'INSERT': syntax error

Code: Pascal  [Select][+][-]
  1. DataModule1.SQLQry_RptData.SQL.Add('INSERT INTO rpt_data (colx, coly, info) VALUES (:colx, :coly, :info)');
  2. DataModule1.SQLQry_RptData.Params.ParamByName('colx').AsString:= 'X';
  3. DataModule1.SQLQry_RptData.Params.ParamByName('coly').AsString:= 'Y';
  4. DataModule1.SQLQry_RptData.Params.ParamByName('info').AsString:= 'test info';
  5. DataModule1.SQLQry_RptData.ExecSQL;
  6. DataModule1.SQLTransaction1.Commit;
  7.  

What am I doing wrong?
TD

« Last Edit: March 21, 2022, 08:09:34 pm by dodgebros »

Zvoni

  • Hero Member
  • *****
  • Posts: 3270
Re: SQLite SQL error
« Reply #1 on: March 21, 2022, 04:27:29 pm »
Don't use the Add-Method.
Clear the SQL.Text beforehand and assign directly to SQL.Text
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

dodgebros

  • Full Member
  • ***
  • Posts: 169
Re: SQLite SQL error
« Reply #2 on: March 21, 2022, 08:07:24 pm »
That solved the problem, thank you very much!
TD

paweld

  • Hero Member
  • *****
  • Posts: 1568
Re: [SOLVED] SQLite SQL error
« Reply #3 on: March 22, 2022, 08:53:19 am »
Why not?
Just remember to clear SQL
Code: Pascal  [Select][+][-]
  1. SQLQuery1.SQL.Clear;
  2. SQLQuery1.SQL.Add(' ... ');
Best regards / Pozdrawiam
paweld

Zvoni

  • Hero Member
  • *****
  • Posts: 3270
Re: [SOLVED] SQLite SQL error
« Reply #4 on: March 22, 2022, 09:03:39 am »
Why not?
Just remember to clear SQL
Code: Pascal  [Select][+][-]
  1. SQLQuery1.SQL.Clear;
  2. SQLQuery1.SQL.Add(' ... ');
pawel,
yeah, but it's the reason i rather use the Text-Property than the Add-Method.
If i "forget" to "clear" the SQL, then it still gets its job done

The SQL-Property is a TStrings: https://www.freepascal.org/docs-html/rtl/classes/tstrings.text.html
Quote
When this property is set, the string will be cut into smaller strings, based on the positions of end-of-line markers in the string. Any previous content of the stringlist will be lost.
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

 

TinyPortal © 2005-2018