Modify auto-generated SQL statements

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
MICHALA
Posts: 15
Joined: Tue 17 Jan 2017 18:35

Modify auto-generated SQL statements

Post by MICHALA » Thu 25 May 2017 07:49

How(and where) can I see and modify, in the runtime auto generated INSERT / UPDATE / DELETE statments?
Ignore, change, expand, add support for other tables?

Michal

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Modify auto-generated SQL statements

Post by azyk » Mon 29 May 2017 13:45

If the TUniQuery.SQLInsert.Text / TUniQuery.SQLUpdate.Text / TUniQuery.SQLDelete.Text property is empty, UniDAC automatically generates and executes INSERT/UPDATE/DELETE query only for the main table.

You can see the SQL query (but not modify) which UniDAC will execute when changing data using the BeforeUpdateExecute event handler. For example:

Code: Select all

procedure TForm1.UniQuery1BeforeUpdateExecute(Sender: TDataSet;
  StatementTypes: TStatementTypes; Params: TDAParams);
var
  SQLText: string;
  UpdateQuery: TComponent;
begin
  if stInsert in StatementTypes then begin
    UpdateQuery := TDBAccessUtils.GetUpdateQuery(TCustomDADataset(Sender));
    SQLText := TDBAccessUtils.GetSQL(UpdateQuery).Text;
    ...
  end;
You can create custom SQL queries to change data and then in run-time or design-time set them to the TUniQuery.SQLInsert.Text / TUniQuery.SQLUpdate.Text / TUniQuery.SQLDelete.Text property.

More details about dataset properties SQLInsert/SQLUpdate/SQLDelete in our online documentation: https://www.devart.com/unidac/docs/?dev ... embers.htm

Post Reply