View Issue Details

IDProjectCategoryView StatusLast Update
0033917FPCDatabasepublic2018-08-15 19:09
ReporterOndrej Pokorny Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionno change required 
Summary0033917: TSQLQuery.CreateParams - override param class
DescriptionI need to create custom Params in TSQLQuery because I need to define my own TParam. There is the TParams.ParamClass virtual method, but there is no virtual method to override in TSQLQuery that would allow to define what TParams will be created.

The attached patch implements it.
TagsNo tags attached.
Fixed in Revision39323.
FPCOldBugId
FPCTarget
Attached Files

Activities

Ondrej Pokorny

2018-06-27 19:17

developer  

TSQLQuery.CreateParams-01.patch (2,205 bytes)   
Index: packages/fcl-db/src/sqldb/sqldb.pp
===================================================================
--- packages/fcl-db/src/sqldb/sqldb.pp	(revision 39317)
+++ packages/fcl-db/src/sqldb/sqldb.pp	(working copy)
@@ -509,6 +509,7 @@
     procedure ApplyFilter;
     Function AddFilter(SQLstr : string) : string;
   protected
+    Function CreateParams: TSQLDBParams; virtual;
     Function RefreshLastInsertID(Field: TField): Boolean; virtual;
     Function NeedRefreshRecord (UpdateKind: TUpdateKind): Boolean; virtual;
     Function RefreshRecord (UpdateKind: TUpdateKind) : Boolean; virtual;
@@ -2385,6 +2386,7 @@
   TQuerySQLStatement = Class(TCustomSQLStatement)
   protected
     FQuery : TCustomSQLQuery;
+    function CreateParams: TSQLDBParams; override;
     Function CreateDataLink : TDataLink; override;
     Function GetSchemaType : TSchemaType; override;
     Function GetSchemaObjectName : String; override;
@@ -2391,15 +2393,28 @@
     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
@@ -2467,7 +2482,6 @@
 begin
   inherited Create(AOwner);
   F:=TQuerySQLStatement.Create(Self);
-  F.FQuery:=Self;
   FStatement:=F;
 
   FInsertSQL := TStringList.Create;
@@ -3117,6 +3131,11 @@
     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);

Ondrej Pokorny

2018-06-27 20:52

developer   ~0109086

This one is not really needed, I found a better way. Sorry for the noise.

Michael Van Canneyt

2018-06-28 10:15

administrator   ~0109096

I admit I was puzzled by your request.
The ParamClass was introduced exactly to enable you do define your own TParams, it's already used in SQLDB :)

Glad you worked it out.

Michael Van Canneyt

2018-06-28 11:30

administrator   ~0109103

Applied the patch, slightly modified.

Ondrej Pokorny

2018-08-15 19:09

developer   ~0110061

Thank you!

Issue History

Date Modified Username Field Change
2018-06-27 19:17 Ondrej Pokorny New Issue
2018-06-27 19:17 Ondrej Pokorny File Added: TSQLQuery.CreateParams-01.patch
2018-06-27 20:52 Ondrej Pokorny Note Added: 0109086
2018-06-27 21:38 Michael Van Canneyt Assigned To => Michael Van Canneyt
2018-06-27 21:38 Michael Van Canneyt Status new => assigned
2018-06-28 10:15 Michael Van Canneyt Note Added: 0109096
2018-06-28 10:15 Michael Van Canneyt Status assigned => resolved
2018-06-28 10:15 Michael Van Canneyt Resolution open => no change required
2018-06-28 11:30 Michael Van Canneyt Fixed in Revision => 39323.
2018-06-28 11:30 Michael Van Canneyt Note Added: 0109103
2018-08-15 19:09 Ondrej Pokorny Note Added: 0110061
2018-08-15 19:09 Ondrej Pokorny Status resolved => closed