cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass persistent variable to SQL Query in Keyword Test Data-Driven Loop

Contributor

How to pass persistent variable to SQL Query in Keyword Test Data-Driven Loop

How can I  pass the value in Project.Variables.lastAfscId to bus_uid = as show below the SQL Query Text in the keyword test.

 

select subscription_uid from bus_subscription where bus_uid = Project.Variables.lastAfscId

 

 

8 REPLIES 8
Community Hero

Re: How to pass persistent variable to SQL Query in Keyword Test Data-Driven Loop

Does that query work for you if you hard code a value for bus_uid instead?

Contributor

Re: How to pass persistent variable to SQL Query in Keyword Test Data-Driven Loop

The query works with hard coded bus_uid. I don't know how to pass the variable to the query.

Highlighted
Community Hero

Re: How to pass persistent variable to SQL Query in Keyword Test Data-Driven Loop

Okay, I just wanted to make sure that we know the query is good.  Something similar to the code in your first post should work.  What happens when you try the variable?

Community Hero

Re: How to pass persistent variable to SQL Query in Keyword Test Data-Driven Loop

When setting up an SQL query for a data driven loop in Keyword test, you can't use variables within the query currently.  What I usually end up doing is using script code, create the loop there (where I can then define the query with a variable) and then call a keyword test from within that script loop, passing in any parmaetres that may be needed.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Contributor

Re: How to pass persistent variable to SQL Query in Keyword Test Data-Driven Loop

I try different way but does not work. what is  the syntax for the variable in query?

 

Select Subscription_UID from Bus_Subscription where bus_uid = Project.Variables.lastAfscId;

Select Subscription_UID from Bus_Subscription where bus_uid = "Project.Variables.lastAfscId";

Select Subscription_UID from Bus_Subscription where bus_uid = "'Project.Variables.lastAfscId'";

 

 

 

Contributor

Re: How to pass persistent variable to SQL Query in Keyword Test Data-Driven Loop

That is what I end up doing. Thought if there is a way to pass variable to query in keyword will be much simpler. thanks for the response.

Occasional Contributor

Re: How to pass persistent variable to SQL Query in Keyword Test Data-Driven Loop

Hi @lingling_chiang,

 

please try assigning the query into a variable by concatinating the project variable(as shown below) and then use the variable to run the query and please do let me know if it solves the problem or not.

strQuery = "Select Subscription_UID from Bus_Subscription where bus_uid = '"+Project.Variables.lastAfscId+"';"
Recordset.Open(strQuery, ConnectionObject);

Kind Regards,

Sathsish Kumar K

Community Leader

Re: How to pass persistent variable to SQL Query in Keyword Test Data-Driven Loop

What connection methods are you using ?

 

Syntax for ADO is slightly different.  If you want to pass a parameter, you need to denote it with a "?" 

e.g.

 

function ADOExample(productid, productType){
ADOCommand.CommandText = "Select [ProductDescription] from [Products] where ProductID =? AND ProcuctType=?"; ADOCommand.Parameters.Item(0) = productid; ADOCommand.Parameters.Item(1) = productType;
//All the other goodies involved in setting up an ADOCommand
return ADOCommand.Execute(); } function GetProducts(){ for(var i = 0; someconstraint; i++){ var recordset=ADOExample(i,"Books"); //Do stuff } }

-------------------------------------------------
Standard syntax disclaimers apply
Regards,
New Here?
Join us and watch the welcome video:
Join the September Hub-bub to show off, learn and win