Hi again,
I think that the best way and more reusable to do this is using the IAQAADOQuery. You can find more details here: ADO.CreateADOQuery. Example
This code works for me but there are some considerations:
- This have been designed expecting a query that return only one row and one column. If the query returns more than one row or column will write a warning in your test log.
- myQuery should be something like: "select Name from Users where email = 'a@a.com'"
- If you prefer you can store the connectionString ina a Project.Variables..., or maybe the query can be inside the function and pass only the select and the parameters.. up to you
Function perform_Query (myQuery)
' Create a query
Set Qry = ADO.CreateADOQuery
' Specify the connection string
Qry.ConnectionString = "you can obtain this connection String from my last message in this same post"
' Specify the SQL expression
Qry.SQL = myQuery
' Execute the query
Qry.Open
' Process results and insert data into the test log
Qry.First
i=0
While Not Qry.EOF
Log.Message aqConvert.VarToStr(Qry.Field(0).FieldName) + ": " + aqConvert.VarToStr(Qry.Field(0).Value)
if myQueryResult = "" then
myQueryResult = aqConvert.VarToStr(Qry.Field(0).Value)
end if
Qry.Next
i=i+1
Wend
if(Qry.FieldCount > 1) then
Log.Warning("Query with more than one Column")
end if
if(i > 1) then
Log.Warning("Query with more than one result")
end if
' Closes the query
Qry.Close
perform_Query = myQueryResult
End Function
For Call this function there are many ways, something like that should work As Code:
Runner.CallMethod("MyScriptName.perform_Query("select pepe from user where email = 'a@a.com'")")
kind regards
Lage