18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
returning an array from db.select producing odd results.
I have a sahi script as shown below:
However I now want to put this into a function so that I can pass in the sql query as shown below:
Any suggestions would be very helpful
Thank you
Donna
__setGlobal("WebServerUsername", "WebServer");
__setGlobal("WebServerPassword", "Password99");
__setGlobal("MicrosoftDriver", "com.microsoft.sqlserver.jdbc.SQLServerDriver");
__setGlobal("MicrosoftUrl", "jdbc:sqlserver://MACAAA081\\SQLEXPRESS;databaseName=AnimalTracking");
var db1 = _getDB(_getGlobal("MicrosoftDriver"), _getGlobal("MicrosoftUrl"), _getGlobal("WebServerUsername"), _getGlobal("WebServerPassword"));
var $rs2=[];
$rs2[0]=[];
_set($rs2, db1.select("SELECT TOP 1 BREED_NAME FROM CONFIG.CATTLE_BREEDS"));
_debug("boo:"+$rs2[0]["BREED_NAME"]);
Which works fine by returning "boo:Aberdeen Angus" in my Sahi console.However I now want to put this into a function so that I can pass in the sql query as shown below:
function adHocQueryMicrosoft($sqlString)
{
__setGlobal("WebServerUsername", "WebServer");
__setGlobal("WebServerPassword", "Password99");
__setGlobal("MicrosoftDriver", "com.microsoft.sqlserver.jdbc.SQLServerDriver");
__setGlobal("MicrosoftUrl", "jdbc:sqlserver://MACAAA081\\SQLEXPRESS;databaseName=AnimalTracking");
var db = _getDB(_getGlobal("MicrosoftDriver"), _getGlobal("MicrosoftUrl"), _getGlobal("WebServerUsername"), _getGlobal("WebServerPassword"));
var $rs=[];
$rs[0]=[];
_set($rs, db.select("SELECT BREED_NAME FROM CONFIG.CATTLE_BREEDS"));
_debug("hoo:"+$rs[0]["BREED_NAME"]);
}
The problem is when I call the function using
_include("includes/adhocQueryFunctions.sah");
adHocQueryMicrosoft("SELECT TOP 1 RETURN_VALUE = BREED_NAME FROM CONFIG.CATTLE_BREEDS");
The output I get in my Sahi console window is "hoo: undefined".Any suggestions would be very helpful
Thank you
Donna
Comments
Don't know why that's happening - seems that the _debug() statement is being run before the _set(), so I guess you could try moving the _debug() out of the function and calling it after.
For what it's worth, my approach is like this:
b2b_db_utils.sah confirm_manual_delivery_booking.sah Might be suitable for what you want to do.
Steve.
1) Write a function which makes the db connection and gets the row, extracts the column from the row and returns the column.
2) Invoke the above function from your scheduler function.
Rewriting the above case:
Cheers
Donna
var db =_getDB("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:DBName", "UID", "PWD");
var $rs=[];
$rs[0]=[];
_set($rs,db.select("SELECT TOP 1 * from DBTABLE where StartDate='2008-08-13 00:00:00.000'"));
_debug($rs[0]["EndDate"]);
Please suggest some solution this problem. Is there anything wrong with the script?
Please help me out
Regards
Deepak