Recent

Author Topic: How dows TSQLScript operate?  (Read 2712 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1592
How dows TSQLScript operate?
« on: October 23, 2023, 01:00:00 pm »
Does it send sqlstatements one by one, or at once?
I found that Firebird supports EXECUTE BLOCK, for example in the case of inserting multiple records.
It can be done with TSQLQuery with SQL statement like:

Code: SQL  [Select][+][-]
  1.      EXECUTE BLOCK AS BEGIN
  2.         INSERT INTO table1 (f1, f2) VALUES (1, 2);
  3.         INSERT INTO table1 (f1, f2) VALUES (11, 12);        
  4.         INSERT INTO table1 (f1, f2) VALUES (21, 22);
  5.         ....
  6.      END;
  7.  
But with TSQLQuery I have to drop EXECUTE BLOCK statement itself. So, TSQLScript.Script would be

Code: SQL  [Select][+][-]
  1.         INSERT INTO table1 (f1, f2) VALUES (1, 2);
  2.         INSERT INTO table1 (f1, f2) VALUES (11, 12);        
  3.         INSERT INTO table1 (f1, f2) VALUES (21, 22);
  4.         ....
  5.  

without EXECUTE BLOCK AS BEGIN and END.


If TSQLQuery sends each statement one by one, TSQLQuery using Execute Block would have merit in performance.

Zvoni

  • Hero Member
  • *****
  • Posts: 2961
Re: How dows TSQLScript operate?
« Reply #1 on: October 23, 2023, 01:51:26 pm »
?!?!??!
One shot instead of three....
Code: SQL  [Select][+][-]
  1. INSERT INTO table1 (f1, f2)
  2.         VALUES  (1, 2),
  3.                 (11, 12),
  4.                 (21, 22);
  5.  
  6.  
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

egsuh

  • Hero Member
  • *****
  • Posts: 1592
Re: How dows TSQLScript operate?
« Reply #2 on: October 24, 2023, 07:25:36 am »
I've shown multiple insertions as an example, but there could be mixed statements of insert, delete, etc.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8797
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How dows TSQLScript operate?
« Reply #3 on: October 24, 2023, 08:28:51 am »
The wiki is your friend.

Zvoni

  • Hero Member
  • *****
  • Posts: 2961
Re: How dows TSQLScript operate?
« Reply #4 on: October 24, 2023, 08:33:42 am »
I've shown multiple insertions as an example, but there could be mixed statements of insert, delete, etc.
Don't!!!
Don't mix Statements. Period.
You might start a nuclear rocket in North Korea......
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

egsuh

  • Hero Member
  • *****
  • Posts: 1592
Re: How dows TSQLScript operate?
« Reply #5 on: October 24, 2023, 09:55:52 am »
Quote
The wiki is your friend

That means it is sent to DB server at once. Good news.

Quote
You might start a nuclear rocket in North Korea......

I may find out how to control them :D

rvk

  • Hero Member
  • *****
  • Posts: 6703
Re: How dows TSQLScript operate?
« Reply #6 on: October 24, 2023, 10:42:02 am »
Quote
The wiki is your friend
That means it is sent to DB server at once. Good news.
What makes you think that?

Look at the source (procedure TCustomSQLScript.ProcessStatement in fcl-db/src/base/sqlscript.pp).

https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/fcl-db/src/base/sqlscript.pp

https://www.freepascal.org/docs-html/fcl/sqldb/tsqlscript.html


egsuh

  • Hero Member
  • *****
  • Posts: 1592
Re: How dows TSQLScript operate?
« Reply #7 on: October 24, 2023, 11:54:48 am »
So it executes statements one by one using TSQLQuery. EXECUTE BLOCK in TSQLQuery is better option.

 

TinyPortal © 2005-2018