TDASimpleQueryBuilder

Overview

TDASimpleQueryBuilder is an abstract base class that implements the basic functionality of the dynamic construction of SQL statements. One of its descendants, TDAQueryBuilder (returned by IDAConnection.GetQueryBuilder), is used to build UI dialogs.
The other descendant, TDASQL92QueryBuilder, is used by BuildSelectStatementForTable and BuildJoinedSelectStatementForTables to utilize the GenerateSelectSQL method.

Location


 

constructor Create  override

Creates a new instance.

constructor Create(Collection: TCollection)

Parameters:

  • Collection: owner

AddCrossJoin

Adds ATable to MainTable.JoinSourceTables (see TDAJoinDataTable).

procedure AddCrossJoin(ATable: string)

Parameters:

  • ATable: table name

AddGroupBy

Adds an ATable/AField pair as TDATableFieldCollectionItem to the GroupBy collection.

procedure AddGroupBy(ATable: string; AField: string)

Parameters:

  • ATable: table name
  • AField: field name

AddJoin (string, string, string, string, TDAJoinType)  overload

Adds a new item to MainTable.JoinSourceTables (see TDAJoinDataTable).

procedure AddJoin(AJoinTable: string; AJoinFieldName: string; AJoinToTableName: string; AJoinToFieldName: string; AJoinType: TDAJoinType)

Parameters:

  • AJoinTable: join table
  • AJoinFieldName: join field name
  • AJoinToTableName: join to table name
  • AJoinToFieldName: join to field name
  • AJoinType: type

AddJoin (string, array of string, string, array of string, TDAJoinType)  overload

Adds a new item for each AJoinToFieldNames to MainTable.JoinSourceTables (see TDAJoinDataTable).

procedure AddJoin(AJoinTable: string; AJoinFieldNames: array of string; AJoinToTableName: string; AJoinToFieldNames: array of string; AJoinType: TDAJoinType)

Parameters:

  • AJoinTable: join table
  • AJoinFieldNames: join field name
  • AJoinToTableName: join to table name
  • AJoinToFieldNames: join to field name
  • AJoinType: type

AddSelect

Adds an ATable/AField pair as TDATableFieldCollectionItem to the Select collection.

procedure AddSelect(ATable: string; AField: string)

Parameters:

  • ATable: table name
  • AField: field name

Assign  override

Copies data from a given source.

procedure Assign(Source: TPersistent)

Parameters:

  • Source: Instance whose properties will be copied

Clear  virtual

Clears all properties.

procedure Clear

ColumnMapping

Note: Assign does not modify ColumnMapping.

property ColumnMapping: TDAColumnMappingCollection read write

CreateFieldGenerator  protected virtual abstract

Creates TDABaseFieldGenerator.

function CreateFieldGenerator: TDABaseFieldGenerator

CreateGroupByClause  protected virtual

Generates the corresponding part of the SQL clause based on the content of GroupBy.

function CreateGroupByClause: string

CreateSelectClause  protected virtual

Generates the corresponding part of the SQL clause based on the content of Select and Options.

function CreateSelectClause: string

CreateTableClause  protected virtual abstract

Builds an SQL statement based on a specified table clause and returns it.

function CreateTableClause: string

CreateWhereBuilder  protected virtual abstract

Returns a new WHERE Builder object that will contain a WHERE statement of one of the following types: TDABinaryExpression, TDAUnaryExpression, TDAConstantExpression, TDAListExpression, TDAParameterExpression, TDAFieldExpression, TDANullExpression, TDAMacroExpression or TDABetweenExpression.

function CreateWhereBuilder: TDABaseSQLWhereBuilder

CreateWhereClause  virtual

Generates the corresponding part of the SQL clause.

function CreateWhereClause: string

FieldGenerator

Referense to TDABaseFieldGenerator that contains rules for generating field name

property FieldGenerator: TDABaseFieldGenerator read

GenerateFieldName  protected

Generates field name according to column mapping and quotation.

function GenerateFieldName(aTablename: string; aFieldName: string; aProcessMapping: Boolean): string

Parameters:

  • aTablename: table name
  • aFieldName: field name
  • aProcessMapping: Controls if GetMappingTableField is applied to aFieldName. true by default.

GenerateSelectClauseWithFieldNames  protected virtual

Generates Select part of SQL as a comma-separated list of required fields.

function GenerateSelectClauseWithFieldNames: string

GenerateSelectSQL  virtual

Compounds all parts into a valid SQL statement.

function GenerateSelectSQL: string

GroupBy

Returns the TCollection of the TDATableFieldCollectionItem. Its value is changed by AddGroupBy and Assign.

property GroupBy: TDAGroupByCollection read

intCreate  protected virtual

Performs initial initialization

procedure intCreate

MainTable

Represents the target data set (see TDAJoinDataTable, TDAJoinDataTable).

property MainTable: TDAQueryBuilderTable read

MaxRecords

This property allows to limit the count of rows of the request. Put it as -1 to receive all available records.

property MaxRecords: Integer read write

Options

Holds the set of TDAQueryBuilderOption.

property Options: TDAQueryBuilderOptions read write

QuoteFieldNameIfNeeded  protected

Quotes field name if is required.

function QuoteFieldNameIfNeeded(const aTableName: string; const aFieldName: string): string

Parameters:

  • aTableName: table name.
  • aFieldName: field name.

QuoteIdentifierIfNeeded  protected

If Connection is assigned, the method delegates the call to it. If IdentifierNeedsQuoting returns true, the call is delegated to QuoteIdentifier, otherwise the unchanged iIdentifier is returned.

function QuoteIdentifierIfNeeded(const iIdentifier: string): string

Parameters:

  • iIdentifier: identifier.

Select

Returns the TCollection of the TDATableFieldCollectionItem.
Its value is changed by AddSelect and Assign.

property Select: TDASelectCollection read

SelectSkip

Allows to suppress the given number of rows before starting to return output.

property SelectSkip: Integer read write

Validate  protected virtual

Raises an exception if MainTable.MasterTable is empty.

procedure Validate

Where

Returns the TDASQLWhereBuilder that is used to dynamically build the WHERE part of the SQL statement. Calls GetWhereBuilder, which in turn calls the abstract CreateWhereBuilder. The result is cached for subsequent calls.

property Where: TDABaseSQLWhereBuilder read

 

ColumnMapping

Note: Assign does not modify ColumnMapping.

property ColumnMapping: TDAColumnMappingCollection read write

FieldGenerator

Referense to TDABaseFieldGenerator that contains rules for generating field name

property FieldGenerator: TDABaseFieldGenerator read

GroupBy

Returns the TCollection of the TDATableFieldCollectionItem. Its value is changed by AddGroupBy and Assign.

property GroupBy: TDAGroupByCollection read

MainTable

Represents the target data set (see TDAJoinDataTable, TDAJoinDataTable).

property MainTable: TDAQueryBuilderTable read

MaxRecords

This property allows to limit the count of rows of the request. Put it as -1 to receive all available records.

property MaxRecords: Integer read write

Options

Holds the set of TDAQueryBuilderOption.

property Options: TDAQueryBuilderOptions read write

Select

Returns the TCollection of the TDATableFieldCollectionItem.
Its value is changed by AddSelect and Assign.

property Select: TDASelectCollection read

SelectSkip

Allows to suppress the given number of rows before starting to return output.

property SelectSkip: Integer read write

Where

Returns the TDASQLWhereBuilder that is used to dynamically build the WHERE part of the SQL statement. Calls GetWhereBuilder, which in turn calls the abstract CreateWhereBuilder. The result is cached for subsequent calls.

property Where: TDABaseSQLWhereBuilder read

 

constructor Create  override

Creates a new instance.

constructor Create(Collection: TCollection)

Parameters:

  • Collection: owner

AddCrossJoin

Adds ATable to MainTable.JoinSourceTables (see TDAJoinDataTable).

procedure AddCrossJoin(ATable: string)

Parameters:

  • ATable: table name

AddGroupBy

Adds an ATable/AField pair as TDATableFieldCollectionItem to the GroupBy collection.

procedure AddGroupBy(ATable: string; AField: string)

Parameters:

  • ATable: table name
  • AField: field name

AddJoin (string, string, string, string, TDAJoinType)  overload

Adds a new item to MainTable.JoinSourceTables (see TDAJoinDataTable).

procedure AddJoin(AJoinTable: string; AJoinFieldName: string; AJoinToTableName: string; AJoinToFieldName: string; AJoinType: TDAJoinType)

Parameters:

  • AJoinTable: join table
  • AJoinFieldName: join field name
  • AJoinToTableName: join to table name
  • AJoinToFieldName: join to field name
  • AJoinType: type

AddJoin (string, array of string, string, array of string, TDAJoinType)  overload

Adds a new item for each AJoinToFieldNames to MainTable.JoinSourceTables (see TDAJoinDataTable).

procedure AddJoin(AJoinTable: string; AJoinFieldNames: array of string; AJoinToTableName: string; AJoinToFieldNames: array of string; AJoinType: TDAJoinType)

Parameters:

  • AJoinTable: join table
  • AJoinFieldNames: join field name
  • AJoinToTableName: join to table name
  • AJoinToFieldNames: join to field name
  • AJoinType: type

AddSelect

Adds an ATable/AField pair as TDATableFieldCollectionItem to the Select collection.

procedure AddSelect(ATable: string; AField: string)

Parameters:

  • ATable: table name
  • AField: field name

Assign  override

Copies data from a given source.

procedure Assign(Source: TPersistent)

Parameters:

  • Source: Instance whose properties will be copied

Clear  virtual

Clears all properties.

procedure Clear

CreateFieldGenerator  protected virtual abstract

Creates TDABaseFieldGenerator.

function CreateFieldGenerator: TDABaseFieldGenerator

CreateGroupByClause  protected virtual

Generates the corresponding part of the SQL clause based on the content of GroupBy.

function CreateGroupByClause: string

CreateSelectClause  protected virtual

Generates the corresponding part of the SQL clause based on the content of Select and Options.

function CreateSelectClause: string

CreateTableClause  protected virtual abstract

Builds an SQL statement based on a specified table clause and returns it.

function CreateTableClause: string

CreateWhereBuilder  protected virtual abstract

Returns a new WHERE Builder object that will contain a WHERE statement of one of the following types: TDABinaryExpression, TDAUnaryExpression, TDAConstantExpression, TDAListExpression, TDAParameterExpression, TDAFieldExpression, TDANullExpression, TDAMacroExpression or TDABetweenExpression.

function CreateWhereBuilder: TDABaseSQLWhereBuilder

CreateWhereClause  virtual

Generates the corresponding part of the SQL clause.

function CreateWhereClause: string

GenerateFieldName  protected

Generates field name according to column mapping and quotation.

function GenerateFieldName(aTablename: string; aFieldName: string; aProcessMapping: Boolean): string

Parameters:

  • aTablename: table name
  • aFieldName: field name
  • aProcessMapping: Controls if GetMappingTableField is applied to aFieldName. true by default.

GenerateSelectClauseWithFieldNames  protected virtual

Generates Select part of SQL as a comma-separated list of required fields.

function GenerateSelectClauseWithFieldNames: string

GenerateSelectSQL  virtual

Compounds all parts into a valid SQL statement.

function GenerateSelectSQL: string

intCreate  protected virtual

Performs initial initialization

procedure intCreate

QuoteFieldNameIfNeeded  protected

Quotes field name if is required.

function QuoteFieldNameIfNeeded(const aTableName: string; const aFieldName: string): string

Parameters:

  • aTableName: table name.
  • aFieldName: field name.

QuoteIdentifierIfNeeded  protected

If Connection is assigned, the method delegates the call to it. If IdentifierNeedsQuoting returns true, the call is delegated to QuoteIdentifier, otherwise the unchanged iIdentifier is returned.

function QuoteIdentifierIfNeeded(const iIdentifier: string): string

Parameters:

  • iIdentifier: identifier.

Validate  protected virtual

Raises an exception if MainTable.MasterTable is empty.

procedure Validate