Knowledge Base Article

Home Page > Knowledge Base > Rapise

Article Executing SQL Database Queries from Rapise

by Adam S on Friday, March 8, 2013

Sometimes when you are running Rapise tests you need to run direct database queries to prepare the data in the test application, or you need to make queries against the database to verify that some user interactions left the data in a specific state.

The sample script below illustrates how you can call database queries directly from the Rapise scripting editor:

function ExecuteQueries()
{
  DP = "SQLOLEDB";
  DS = "MySQLServer";
  DB = "NORTHWIND";

  adOpenForwardOnly = 0;
  adLockReadOnly = 1;
  adCmdText = 1;
  try
  {
    var objRs = new ActiveXObject("ADODB.Recordset");
  }
  catch (e)
  {
    alert("ADODB namespace not found.");
    exit(0);
  }

  strConn =  "Provider="         +DP+
            ";Initial Catalog="  +DB+
            ";Data Source="      +DS+
            ";Integrated Security=SSPI;"
  strComm = "SELECT ProductID,ProductName,UnitPrice "+
            "FROM Products " +
            "WHERE CategoryID = 7"  // select Produce

  objRs.open(strComm,
             strConn,
             adOpenForwardOnly,
             adLockReadOnly,
             adCmdText);

  objRs.MoveFirst();
  while (objRs.EOF != true)
  {
    alert(objRs("ProductID")+"\t"
         +objRs("ProductName")+"\t"
         +objRs("UnitPrice"));
    objRs.MoveNext();
  }

  objRs.Close
  objRs = null;
}


function alert(str)
{
  WScript.Echo(str);
}
Attachments
Article Info
Last Updated: 3/8/2013
Article ID: KB39
# Views: 3048
Powered by KronoDesk v1.1.0.15 | © Copyright Inflectra Corporation 2011-2016 | Licensed to Inflectra Corporation.