* (Slightly modified) Patch from Ondrey to allow customizing TParams created in TSQLQuery and friends

git-svn-id: trunk@39323 -
This commit is contained in:
michael 2018-06-28 09:29:54 +00:00
parent 7a6bd69685
commit 01517dfab2

View File

@ -213,6 +213,8 @@ type
function ConstructUpdateSQL(Query: TCustomSQLQuery; Var ReturningClause : Boolean): string; virtual;
function ConstructDeleteSQL(Query: TCustomSQLQuery): string; virtual;
function ConstructRefreshSQL(Query: TCustomSQLQuery; UpdateKind : TUpdateKind): string; virtual;
// factory function used to create custom statements
function CreateCustomQuery(aOwner: TComponent): TCustomSQLQuery; virtual;
function InitialiseUpdateStatement(Query: TCustomSQLQuery; var qry: TCustomSQLQuery): TCustomSQLQuery;
procedure ApplyFieldUpdate(C : TSQLCursor; P: TSQLDBParam; F: TField; UseOldValue: Boolean); virtual;
// This is the call that updates a record, it used to be in TSQLQuery.
@ -509,6 +511,8 @@ type
procedure ApplyFilter;
Function AddFilter(SQLstr : string) : string;
protected
function CreateSQLStatement(aOwner: TComponent): TCustomSQLStatement; virtual;
Function CreateParams: TSQLDBParams; virtual;
Function RefreshLastInsertID(Field: TField): Boolean; virtual;
Function NeedRefreshRecord (UpdateKind: TUpdateKind): Boolean; virtual;
Function RefreshRecord (UpdateKind: TUpdateKind) : Boolean; virtual;
@ -1796,13 +1800,18 @@ begin
FStatements.Remove(S);
end;
function TSQLConnection.CreateCustomQuery(aOwner : TComponent) : TCustomSQLQuery;
begin
Result:=TCustomSQLQuery.Create(AOwner);
end;
function TSQLConnection.InitialiseUpdateStatement(Query : TCustomSQLQuery; var qry : TCustomSQLQuery): TCustomSQLQuery;
begin
if not assigned(qry) then
begin
qry := TCustomSQLQuery.Create(nil);
qry := TCustomSQLQuery(TComponentClass(Query.ClassType).Create(Nil));
qry.ParseSQL := False;
qry.DataBase := Self;
qry.Transaction := Query.SQLTransaction;
@ -2385,21 +2394,35 @@ Type
TQuerySQLStatement = Class(TCustomSQLStatement)
protected
FQuery : TCustomSQLQuery;
function CreateParams: TSQLDBParams; override;
Function CreateDataLink : TDataLink; override;
Function GetSchemaType : TSchemaType; override;
Function GetSchemaObjectName : String; override;
Function GetSchemaPattern: String; override;
procedure GetStatementInfo(var ASQL: String; out Info: TSQLStatementInfo); override;
procedure OnChangeSQL(Sender : TObject); override;
public
constructor Create(AOwner: TComponent); override;
end;
{ TQuerySQLStatement }
constructor TQuerySQLStatement.Create(AOwner: TComponent);
begin
FQuery:=TCustomSQLQuery(AOwner);
inherited Create(AOwner);
end;
function TQuerySQLStatement.CreateDataLink: TDataLink;
begin
Result:=TMasterParamsDataLink.Create(FQuery);
end;
function TQuerySQLStatement.CreateParams: TSQLDBParams;
begin
Result:=FQuery.CreateParams;
end;
function TQuerySQLStatement.GetSchemaType: TSchemaType;
begin
if Assigned(FQuery) then
@ -2459,16 +2482,17 @@ end;
{ TCustomSQLQuery }
constructor TCustomSQLQuery.Create(AOwner : TComponent);
Function TCustomSQLQuery.CreateSQLStatement(aOwner : TComponent) : TCustomSQLStatement;
Var
F : TQuerySQLStatement;
begin
Result:=TQuerySQLStatement.Create(Self);
end;
constructor TCustomSQLQuery.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
F:=TQuerySQLStatement.Create(Self);
F.FQuery:=Self;
FStatement:=F;
FStatement:=CreateSQLStatement(Self);
FInsertSQL := TStringList.Create;
FInsertSQL.OnChange := @OnChangeModifySQL;
@ -3117,6 +3141,11 @@ begin
UnPrepareStatement(Cursor);
end;
function TCustomSQLQuery.CreateParams: TSQLDBParams;
begin
Result:=TSQLDBParams.Create(Nil);
end;
function TCustomSQLQuery.LogEvent(EventType: TDBEventType): Boolean;
begin
Result:=Assigned(Database) and SQLConnection.LogEvent(EventType);