Recent

Author Topic: Parameters for a TSQLScript run?  (Read 716 times)

Mario

  • New Member
  • *
  • Posts: 30
Parameters for a TSQLScript run?
« on: July 24, 2024, 10:57:29 am »
Hi,

I have a nice SQL script which does tons of stuff. I would like to have parameters in some of the statements, like in a regular TSQLQuery. Is there a simple way to do that?

I was thinking of something like this:

Code: Pascal  [Select][+][-]
  1. XScript.Script := ScriptText;
  2. XScript.SomethingSomething.ParamByName('foo', 42);
  3. XScript.Execute;

Is there something similar?

Mario

  • New Member
  • *
  • Posts: 30
Re: Parameters for a TSQLScript run?
« Reply #1 on: July 24, 2024, 02:40:54 pm »
Ok after some research and thought, I'll answer myself.

If you have SQL that is complex enough you want it in a script, and it needs parameters, you are better off installing a stored procedure in your SQL server, whatever its flavor. SQLite doesn't have stored procedures, but apparently you can fake them like this https://www.cafe-encounter.net/p3300/pretending-that-sqlite-has-stored-procedures-and-functions

Zvoni

  • Hero Member
  • *****
  • Posts: 2741
Re: Parameters for a TSQLScript run?
« Reply #2 on: July 24, 2024, 02:46:50 pm »
Looking at the the Inheritance-Tree of TSQLScript and its Methods and Properties, i think it's the wrong "tool" (Component) to use with Parameters.
1) TSQLScript is not returning a Result (Like for a SELECT)
2) It uses the Execute(Direct)-Method of its Database/Connection-Object, which in itself should only be used for non-Result Statements

i Think TSQLScript is useful for, say, reimporting a SQLDump.

All said: If you have (to use) Parameters, use TSQLQuery. Period!
Or as you said: Stored procedures if the DBMS supports it

EDIT: I was just reading that Link.
If you need help with registering your own Procedure/Function give a shout
« Last Edit: July 24, 2024, 02:50:33 pm 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

 

TinyPortal © 2005-2018