Page 1 of 1
UniScript with parameters ?
Posted: Wed 14 Dec 2016 21:12
by Senad
Can UniScript contain parameters ?
I am trying to do :
CREATE LOGIN :p1 WITH PASSWORD = :p2 ;
but cant do it.
Re: UniScript with parameters ?
Posted: Thu 15 Dec 2016 11:12
by Senad
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..
Re: UniScript with parameters ?
Posted: Thu 15 Dec 2016 19:13
by FCS
Hi,
Try to use prepareSQL method before Execute.
Regards
Michal
Re: UniScript with parameters ?
Posted: Fri 16 Dec 2016 04:08
by Senad
Did that but I still get the error message .
Dont know why because the syntax should be correct.
Re: UniScript with parameters ?
Posted: Fri 16 Dec 2016 07:57
by azyk
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