Recent

Author Topic: [SOLVED] Executing multiple sql statements in UpdateSQL (TSQLQuery)  (Read 446 times)

KoBraSoft

  • New Member
  • *
  • Posts: 24
Hi,
how to  execute multiple sql statements in UpdateSQL?
With this
Code: [Select]
UPDATE OR INSERT INTO ARTIKELGRUPPENDATEN (PREIS, ANZAHL, ID) VALUES (:PREIS1, :ANZAHL1, :ID1) MATCHING (ID);
UPDATE OR INSERT INTO ARTIKELGRUPPENDATEN (PREIS, ANZAHL, ID) VALUES (:PREIS10, :ANZAHL10, :ID10) MATCHING (ID);
UPDATE OR INSERT INTO ARTIKELGRUPPENDATEN (PREIS, ANZAHL, ID) VALUES (:PREIS100, :ANZAHL100, :ID100) MATCHING (ID);
in UpdateSQL i get
Code: [Select]
Token unknown - line 2, column 1
-UPDATE

It looks like ";" is being ignored.
Here is a similar topic:
https://forum.lazarus.freepascal.org/index.php/topic,15179.msg81218.html#msg81218
According this topic, it should work.
« Last Edit: December 21, 2025, 06:40:22 pm by KoBraSoft »

Sieben

  • Sr. Member
  • ****
  • Posts: 384
Re: Executing multiple sql statements in UpdateSQL (TSQQuery)
« Reply #1 on: December 21, 2025, 11:54:53 am »
You have to use the connection component to achieve that, TSQLQuery itself cannot execute multiple statements. TSQL3Connection for example has a method called ExecSQL that can. That said, all SQL statements of TSQLQuery are in the end processed by the corresponding TSQLConnection anyway.
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

CharlyTango

  • Full Member
  • ***
  • Posts: 177
Re: Executing multiple sql statements in UpdateSQL (TSQQuery)
« Reply #2 on: December 21, 2025, 12:16:33 pm »
I never used multiple SQL Statements on a TSQLQuery at once. Not even with UpdateSQL.

I solve such challenges with
Code: Pascal  [Select][+][-]
  1.   TSQLQuery.ExecSQL;                  //one statement at a time
  2.   TSQLConnector.ExecuteDirect();   //one statement at a time
  3.  
  4.   TSQLite3Connection.ExecuteDirect(); //every connection provides ExecuteDirect and one statement at a time
  5.  
  6.  
  7.   TSQLScript.ExecuteScript;  // all statements at once

I doubt if parameters work in TSQLScript
Lazarus stable, Win32/64

KoBraSoft

  • New Member
  • *
  • Posts: 24
Re: Executing multiple sql statements in UpdateSQL (TSQQuery)
« Reply #3 on: December 21, 2025, 06:36:11 pm »
I solve such challenges with
Code: Pascal  [Select][+][-]
  1.   TSQLQuery.ExecSQL;                  //one statement at a time
  2.   TSQLConnector.ExecuteDirect();   //one statement at a time
  3.  
  4.   TSQLite3Connection.ExecuteDirect(); //every connection provides ExecuteDirect and one statement at a time
  5.  
I doubt if parameters work in TSQLScript
Yes, correct. Parameters does not work. But
Code: Pascal  [Select][+][-]
  1. (DataSet as TSQLQuery).FieldByName().AsString
 
instead of :parameter of in AfterPost does the job.

 

TinyPortal © 2005-2018