Description
Creates a new 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 for scripts as a TQuery object does 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
DatabaseNameproperty). - Specify the SQL expression of the query (the
SQLproperty). - If necessary, specify parameters for the query (the
Paramsproperty). - Execute the query using the
OpenorExecSQLmethods.
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();
}
}
{
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
' 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;
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"]();
}
}
{
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"]();
}
}
