BDE.CreateQuery Method

Applies to TestComplete 15.47, last modified on January 20, 2023
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.

Description

The CreateQuery method creates an object of the IAQAQuery type (an analogue of the VCL TQuery type).

Note: This method requires the Borland Database Engine to be installed on your computer.

Declaration

BDE.CreateQuery()

Result An IAQAQuery object

Applies To

The method is applied to the following object:

Result Value

An object of the IAQAQuery type.

Remarks

The IAQAQuery object provides the same functionality as the TQuery object in VCL applications. It implements the same methods and properties, under the same names. See the VCL documentation for TQuery.

Once the IAQAQuery object is created, you can use it to call queries. To do this:

  • Specify the database which the query addresses (the DatabaseName property).
  • Specify the SQL expression of the query (the SQL property).
  • If necessary, specify parameters for the query (the Params property).
  • Execute the query using the Open or ExecSQL methods.

Example

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 p, w;
  // Create a new IAQAQuery object
  w = BDE.CreateQuery();
  // Specify the database alias or the path to the table file (DBDEMOS is the alias of the folder <Borland Shared>\Data)
  w.DatabaseName = "DBDEMOS";
  // Create the parameter
  p = w.Params.CreateParam(ftString, "Param_State", ptInput);
  // Specify the SQL expression
  w.SQL = "SELECT VendorName FROM Vendors WHERE State = :Param_State";
  p.AsString = "CA";
  // Execute the query
  w.Open();
  // Move to the first record
  w.First();
  while (! w.EOF)
  {
    // Insert the field value into the test log
    Log.Message(w.FieldByName("VendorName").AsString);
    // Move to the next record
    w.Next();
  }
}

Python

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

VBScript

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

DelphiScript

procedure TestProc;
var
  p, w: OleVariant;
begin
  // Create a new IAQAQuery object
  w := BDE.CreateQuery;
  with w 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';
    // Create the parameter
    p := Params.CreateParam(ftString, 'Param_State', ptInput);
    // Specify the SQL expression
    SQL := 'SELECT VendorName FROM Vendors WHERE State = :Param_State';
    p.AsString := 'CA';
  end;
  // Execute the query
  w.Open;
  // Move to the first record
  w.First;
  while not aqConvert.VarToBool(w.EOF) do
  begin
    // Insert the field value into the test log
    Log.Message(w.FieldByName('VendorName').AsString);
    // Move to the next record
    w.Next;
  end;
end;

C++Script, C#Script

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

See Also

BDE.CreateTable
BDE.CreateStoredProc

Highlight search results