BDE.CreateQuery

Applies to TestComplete 15.70, last modified on December 17, 2024
Accessing databases by using the Borland Database Engine (BDE) is deprecated. Do not use it to create new tests. It will be removed from the product in one of the future releases. As an alternative, you can access databases by using the Microsoft Active Data Object (ADO). See Using ADO Components.

The following script sample executes a database query. The query returns the names of vendors in California. Its results are posted 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