UniScript with parameters ?

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Senad
Posts: 34
Joined: Tue 10 Dec 2013 08:07

UniScript with parameters ?

Post by Senad » Wed 14 Dec 2016 21:12

Can UniScript contain parameters ?
I am trying to do :
CREATE LOGIN :p1 WITH PASSWORD = :p2 ;
but cant do it.

Senad
Posts: 34
Joined: Tue 10 Dec 2013 08:07

Re: UniScript with parameters ?

Post by Senad » Thu 15 Dec 2016 11:12

I just managed to find out that UniScript does not support parameters. You recommend using UNISql.
However,trying to use UniSQLwith :

DROP SCHEMA [ IF EXISTS ] :p1

will not work.

Code: Select all

Data_Module.UniSQL1.Params.ParamByName('p1').AsString := cxTextEdit1.Text;
Data_Module.UniSQL1.Execute;
I get the message : Incorrect syntax near '@P1..

FCS
Posts: 176
Joined: Sat 23 Feb 2013 18:46

Re: UniScript with parameters ?

Post by FCS » Thu 15 Dec 2016 19:13

Hi,

Try to use prepareSQL method before Execute.

Regards
Michal

Senad
Posts: 34
Joined: Tue 10 Dec 2013 08:07

Re: UniScript with parameters ?

Post by Senad » Fri 16 Dec 2016 04:08

Did that but I still get the error message .
Dont know why because the syntax should be correct.

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: UniScript with parameters ?

Post by azyk » Fri 16 Dec 2016 07:57

SQL Server does not support for the T-SQL commands CREATE LOGIN/DROP SCHEMA value transfer for LOGIN and PASSWORD/SCHEMA using SQL query parameters, therefore you get the Incorrect syntax near '@P1 error.

To solve the problem you can use UniDAC macros instead of parameters. For example, if you need to create user user1 with password ***** then the code using TUniScript can be the following:

Code: Select all

UniScript.SQL.Text := 'CREATE LOGIN &p1 WITH PASSWORD = &p2 ;';
UniScript.Macros[0].Value := 'user1';
UniScript.Macros[1].Value := '''*****''';
UniScript.Execute;
You can read more about UniDAC macros in our online documentation:
https://www.devart.com/unidac/docs/?unisql.htm

Post Reply