BDE.CreateQuery

Applies to TestComplete 14.60, last modified on April 22, 2021

The following code executes a database query from the script. The query returns the names of vendors in California. Its results are copied one by one to the test log.

JavaScript, JScript

function TestProc()
{
  var qry;
  // Create a new IAQAQuery object
  qry = BDE.CreateQuery();
  // Specify the database alias or the path to the table file (DBDEMOS is the alias of the folder <Borland Shared>\Data)
  qry.DatabaseName = "DBDEMOS";
  // Specify the SQL expression
  qry.SQL = "SELECT VendorName FROM Vendors WHERE State = :Param_State";
  // Specify the parameter value
  qry.ParamByName("Param_State").Value = "CA";
  // Execute the query
  qry.Open();
  // Move to the first record
  qry.First();
  while (! qry.EOF)
  {
    // Insert the field value into the test log
    Log.Message(qry.FieldByName("VendorName").AsString);
    // Move to the next record
    qry.Next();
  }
}

Python

def TestProc():
  # Create a new IAQAQuery object
  qry = BDE.CreateQuery()
  # Specify the database alias or the path to the table file (DBDEMOS is the alias of the folder <Borland Shared>\Data)
  qry.DatabaseName = "DBDEMOS"
  # Specify the SQL expression
  qry.SQL = "SELECT VendorName FROM Vendors WHERE State = :Param_State"
  # Specify the parameter value
  qry.ParamByName("Param_State").Value = "CA"
  # Execute the query
  qry.Open()
  # Move to the first record
  qry.First()
  while not qry.EOF:
    # Insert the field value into the test log
    Log.Message(qry.FieldByName("VendorName").AsString)
    # Move to the next record
    qry.Next()

VBScript

Sub TestProc
  ' Create a new IAQAQuery object
  Set qry = BDE.CreateQuery
  ' Specify the database alias or the path to the table file (DBDEMOS is the alias of the folder <Borland Shared>\Data)
  qry.DatabaseName = "DBDEMOS"
  ' Specify the SQL expression
  qry.SQL = "SELECT VendorName FROM Vendors WHERE State = :Param_State"
  ' Specify the parameter value
  qry.ParamByName("Param_State").Value = "CA"
  ' Execute the query
  qry.Open
  ' Move to the first record
  qry.First
  While Not qry.EOF
    ' Insert the field value into the test log
    Log.Message qry.FieldByName("VendorName").AsString
    ' Move to the next record
    qry.Next
  Wend
End Sub

DelphiScript

procedure TestProc;
var
  qry : OleVariant;
begin
  // Create a new IAQAQuery object
  qry := BDE.CreateQuery;
  with qry do
  begin
  // Specify the database alias or the path to the table file (DBDEMOS is the alias of the folder <Borland Shared>\Data)
  DatabaseName := 'DBDEMOS';
  // Specify the SQL expression
  SQL := 'SELECT VendorName FROM Vendors WHERE State = :Param_State';
  // Specify the parameter value
  qry.ParamByName('Param_State').Value := 'CA';
  end;
  // Execute the query
  qry.Open;
  // Move to the first record
  qry.First;
  while not aqConvert.VarToBool(qry.EOF) do
  begin
    // Insert the field value into the test log
    Log.Message(qry.FieldByName('VendorName').AsString);
    // Move to the next record
    qry.Next;
  end;
end;

C++Script, C#Script

function TestProc()
{
  var qry;
  // Create a new IAQAQuery object
  qry = BDE["CreateQuery"]();
  // Specify the database alias or the path to the table file (DBDEMOS is the alias of the folder <Borland Shared>\Data)
  qry["DatabaseName"] = "DBDEMOS";
  // Specify the SQL expression
  qry["SQL"] = "SELECT VendorName FROM Vendors WHERE State = :Param_State";
  // Specify the parameter value
  qry["ParamByName"]("Param_State")["Value"] = "CA";
  // Execute the query
  qry["Open"]();
  // Move to the first record
  qry["First"]();
  while (!qry["EOF"])
  {
    // Insert the field value into the test log
    Log["Message"](qry["FieldByName"]("VendorName")["AsString"]);
    // Move to the next record
    qry["Next"]();
  }
}

Highlight search results