Browse Source

* Introduced TCustomSQLQuery, with properties in protected mode

git-svn-id: trunk@7364 -
michael 18 years ago
parent
commit
061bfa3301
1 changed files with 79 additions and 56 deletions
  1. 79 56
      packages/fcl-db/src/sqldb/sqldb.pp

+ 79 - 56
packages/fcl-db/src/sqldb/sqldb.pp

@@ -29,6 +29,7 @@ type TSchemaType = (stNoSchema, stTables, stSysTables, stProcedures, stColumns,
 type
 type
   TSQLConnection = class;
   TSQLConnection = class;
   TSQLTransaction = class;
   TSQLTransaction = class;
+  TCustomSQLQuery = class;
   TSQLQuery = class;
   TSQLQuery = class;
   TSQLScript = class;
   TSQLScript = class;
 
 
@@ -162,9 +163,9 @@ type
     property Params : TStringList read FParams write FParams;
     property Params : TStringList read FParams write FParams;
   end;
   end;
 
 
-{ TSQLQuery }
+{ TCustomSQLQuery }
 
 
-  TSQLQuery = class (Tbufdataset)
+  TCustomSQLQuery = class (Tbufdataset)
   private
   private
     FCursor              : TSQLCursor;
     FCursor              : TSQLCursor;
     FUpdateable          : boolean;
     FUpdateable          : boolean;
@@ -193,7 +194,7 @@ type
 
 
     FUpdateQry,
     FUpdateQry,
     FDeleteQry,
     FDeleteQry,
-    FInsertQry           : TSQLQuery;
+    FInsertQry           : TCustomSQLQuery;
 
 
     procedure FreeFldBuffers;
     procedure FreeFldBuffers;
     procedure InitUpdates(ASQL : string);
     procedure InitUpdates(ASQL : string);
@@ -240,13 +241,12 @@ type
     procedure SetSchemaInfo( SchemaType : TSchemaType; SchemaObjectName, SchemaPattern : string); virtual;
     procedure SetSchemaInfo( SchemaType : TSchemaType; SchemaObjectName, SchemaPattern : string); virtual;
     property Prepared : boolean read IsPrepared;
     property Prepared : boolean read IsPrepared;
     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
-  published
+  protected
+      
     // redeclared data set properties
     // redeclared data set properties
     property Active;
     property Active;
     property Filter;
     property Filter;
     property Filtered;
     property Filtered;
-    property ServerFilter: string read FServerFilterText write SetServerFilterText;
-    property ServerFiltered: Boolean read FServerFiltered write SetServerFiltered default False;
 //    property FilterOptions;
 //    property FilterOptions;
     property BeforeOpen;
     property BeforeOpen;
     property AfterOpen;
     property AfterOpen;
@@ -272,7 +272,8 @@ type
     property OnPostError;
     property OnPostError;
     property AutoCalcFields;
     property AutoCalcFields;
     property Database;
     property Database;
-
+  // protected
+//    property SchemaInfo : TSchemaInfo read FSchemaInfo default stNoSchema;
     property Transaction;
     property Transaction;
     property ReadOnly : Boolean read FReadOnly write SetReadOnly;
     property ReadOnly : Boolean read FReadOnly write SetReadOnly;
     property SQL : TStringlist read FSQL write FSQL;
     property SQL : TStringlist read FSQL write FSQL;
@@ -286,7 +287,29 @@ type
     property StatementType : TStatementType read GetStatementType;
     property StatementType : TStatementType read GetStatementType;
     property ParseSQL : Boolean read FParseSQL write SetParseSQL;
     property ParseSQL : Boolean read FParseSQL write SetParseSQL;
     Property DataSource : TDatasource Read GetDataSource Write SetDatasource;
     Property DataSource : TDatasource Read GetDataSource Write SetDatasource;
-//    property SchemaInfo : TSchemaInfo read FSchemaInfo default stNoSchema;
+    property ServerFilter: string read FServerFilterText write SetServerFilterText;
+    property ServerFiltered: Boolean read FServerFiltered write SetServerFiltered default False;
+  end;
+
+{ TSQLQuery }
+  TSQLQuery = Class(TCustomSQLQuery)
+  Published
+    //    property SchemaInfo default stNoSchema;
+    property Transaction;
+    property ReadOnly;
+    property SQL;
+    property UpdateSQL;
+    property InsertSQL;
+    property DeleteSQL;
+    property IndexDefs;
+    property Params;
+    property UpdateMode;
+    property UsePrimaryKeyAsKey;
+    property StatementType;
+    property ParseSQL;
+    Property DataSource;
+    property ServerFilter;
+    property ServerFiltered;
   end;
   end;
 
 
 { TSQLScript }
 { TSQLScript }
@@ -294,7 +317,7 @@ type
   TSQLScript = class (Tcomponent)
   TSQLScript = class (Tcomponent)
   private
   private
     FScript  : TStrings;
     FScript  : TStrings;
-    FQuery   : TSQLQuery;
+    FQuery   : TCustomSQLQuery;
     FDatabase : TDatabase;
     FDatabase : TDatabase;
     FTransaction : TDBTransaction;
     FTransaction : TDBTransaction;
   protected
   protected
@@ -476,13 +499,13 @@ end;
 
 
 procedure TSQLConnection.GetDBInfo(const SchemaType : TSchemaType; const SchemaObjectName, ReturnField : string; List: TStrings);
 procedure TSQLConnection.GetDBInfo(const SchemaType : TSchemaType; const SchemaObjectName, ReturnField : string; List: TStrings);
 
 
-var qry : TSQLQuery;
+var qry : TCustomSQLQuery;
 
 
 begin
 begin
   if not assigned(Transaction) then
   if not assigned(Transaction) then
     DatabaseError(SErrConnTransactionnSet);
     DatabaseError(SErrConnTransactionnSet);
 
 
-  qry := tsqlquery.Create(nil);
+  qry := TCustomSQLQuery.Create(nil);
   qry.transaction := Transaction;
   qry.transaction := Transaction;
   qry.database := Self;
   qry.database := Self;
   with qry do
   with qry do
@@ -668,8 +691,8 @@ begin
     end;
     end;
 end;
 end;
 
 
-{ TSQLQuery }
-procedure TSQLQuery.OnChangeSQL(Sender : TObject);
+{ TCustomSQLQuery }
+procedure TCustomSQLQuery.OnChangeSQL(Sender : TObject);
 
 
 var ConnOptions : TConnOptions;
 var ConnOptions : TConnOptions;
 
 
@@ -687,20 +710,20 @@ begin
     end;
     end;
 end;
 end;
 
 
-procedure TSQLQuery.OnChangeModifySQL(Sender : TObject);
+procedure TCustomSQLQuery.OnChangeModifySQL(Sender : TObject);
 
 
 begin
 begin
   CheckInactive;
   CheckInactive;
 end;
 end;
 
 
-Procedure TSQLQuery.SetTransaction(Value : TDBTransaction);
+Procedure TCustomSQLQuery.SetTransaction(Value : TDBTransaction);
 
 
 begin
 begin
   UnPrepare;
   UnPrepare;
   inherited;
   inherited;
 end;
 end;
 
 
-procedure TSQLQuery.SetDatabase(Value : TDatabase);
+procedure TCustomSQLQuery.SetDatabase(Value : TDatabase);
 
 
 var db : tsqlconnection;
 var db : tsqlconnection;
 
 
@@ -717,13 +740,13 @@ begin
     end;
     end;
 end;
 end;
 
 
-Function TSQLQuery.IsPrepared : Boolean;
+Function TCustomSQLQuery.IsPrepared : Boolean;
 
 
 begin
 begin
   Result := Assigned(FCursor) and FCursor.FPrepared;
   Result := Assigned(FCursor) and FCursor.FPrepared;
 end;
 end;
 
 
-Function TSQLQuery.AddFilter(SQLstr : string) : string;
+Function TCustomSQLQuery.AddFilter(SQLstr : string) : string;
 
 
 begin
 begin
   if FWhereStartPos = 0 then
   if FWhereStartPos = 0 then
@@ -735,7 +758,7 @@ begin
   Result := SQLstr;
   Result := SQLstr;
 end;
 end;
 
 
-procedure TSQLQuery.ApplyFilter;
+procedure TCustomSQLQuery.ApplyFilter;
 
 
 var S : String;
 var S : String;
 
 
@@ -756,7 +779,7 @@ begin
   First;
   First;
 end;
 end;
 
 
-Procedure TSQLQuery.SetActive (Value : Boolean);
+Procedure TCustomSQLQuery.SetActive (Value : Boolean);
 
 
 begin
 begin
   inherited SetActive(Value);
   inherited SetActive(Value);
@@ -766,7 +789,7 @@ begin
 end;
 end;
 
 
 
 
-procedure TSQLQuery.SetServerFiltered(Value: Boolean);
+procedure TCustomSQLQuery.SetServerFiltered(Value: Boolean);
 
 
 begin
 begin
   if Value and not FParseSQL then DatabaseErrorFmt(SNoParseSQL,['Filtering ']);
   if Value and not FParseSQL then DatabaseErrorFmt(SNoParseSQL,['Filtering ']);
@@ -777,7 +800,7 @@ begin
     end;
     end;
 end;
 end;
 
 
-procedure TSQLQuery.SetServerFilterText(const Value: string);
+procedure TCustomSQLQuery.SetServerFilterText(const Value: string);
 begin
 begin
   if Value <> ServerFilter then
   if Value <> ServerFilter then
     begin
     begin
@@ -786,7 +809,7 @@ begin
     end;
     end;
 end;
 end;
 
 
-procedure TSQLQuery.Prepare;
+procedure TCustomSQLQuery.Prepare;
 var
 var
   db    : tsqlconnection;
   db    : tsqlconnection;
   sqltr : tsqltransaction;
   sqltr : tsqltransaction;
@@ -828,7 +851,7 @@ begin
     end;
     end;
 end;
 end;
 
 
-procedure TSQLQuery.UnPrepare;
+procedure TCustomSQLQuery.UnPrepare;
 
 
 begin
 begin
   CheckInactive;
   CheckInactive;
@@ -836,12 +859,12 @@ begin
     UnPrepareStatement(FCursor);
     UnPrepareStatement(FCursor);
 end;
 end;
 
 
-procedure TSQLQuery.FreeFldBuffers;
+procedure TCustomSQLQuery.FreeFldBuffers;
 begin
 begin
   if assigned(FCursor) then (Database as tsqlconnection).FreeFldBuffers(FCursor);
   if assigned(FCursor) then (Database as tsqlconnection).FreeFldBuffers(FCursor);
 end;
 end;
 
 
-function TSQLQuery.Fetch : boolean;
+function TCustomSQLQuery.Fetch : boolean;
 begin
 begin
   if not (Fcursor.FStatementType in [stSelect]) then
   if not (Fcursor.FStatementType in [stSelect]) then
     Exit;
     Exit;
@@ -850,25 +873,25 @@ begin
   Result := not FIsEOF;
   Result := not FIsEOF;
 end;
 end;
 
 
-procedure TSQLQuery.Execute;
+procedure TCustomSQLQuery.Execute;
 begin
 begin
   If (FParams.Count>0) and Assigned(FMasterLink) then
   If (FParams.Count>0) and Assigned(FMasterLink) then
     FMasterLink.CopyParamsFromMaster(False);
     FMasterLink.CopyParamsFromMaster(False);
   (Database as tsqlconnection).execute(Fcursor,Transaction as tsqltransaction, FParams);
   (Database as tsqlconnection).execute(Fcursor,Transaction as tsqltransaction, FParams);
 end;
 end;
 
 
-function TSQLQuery.LoadField(FieldDef : TFieldDef;buffer : pointer; out CreateBlob : boolean) : boolean;
+function TCustomSQLQuery.LoadField(FieldDef : TFieldDef;buffer : pointer; out CreateBlob : boolean) : boolean;
 
 
 begin
 begin
   result := (Database as tSQLConnection).LoadField(FCursor,FieldDef,buffer, Createblob)
   result := (Database as tSQLConnection).LoadField(FCursor,FieldDef,buffer, Createblob)
 end;
 end;
 
 
-procedure TSQLQuery.InternalAddRecord(Buffer: Pointer; AAppend: Boolean);
+procedure TCustomSQLQuery.InternalAddRecord(Buffer: Pointer; AAppend: Boolean);
 begin
 begin
   // not implemented - sql dataset
   // not implemented - sql dataset
 end;
 end;
 
 
-procedure TSQLQuery.InternalClose;
+procedure TCustomSQLQuery.InternalClose;
 begin
 begin
   if StatementType = stSelect then FreeFldBuffers;
   if StatementType = stSelect then FreeFldBuffers;
 // Database and FCursor could be nil, for example if the database is not assigned, and .open is called
 // Database and FCursor could be nil, for example if the database is not assigned, and .open is called
@@ -883,7 +906,7 @@ begin
   inherited internalclose;
   inherited internalclose;
 end;
 end;
 
 
-procedure TSQLQuery.InternalInitFieldDefs;
+procedure TCustomSQLQuery.InternalInitFieldDefs;
 begin
 begin
   if FLoadingFieldDefs then
   if FLoadingFieldDefs then
     Exit;
     Exit;
@@ -900,7 +923,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure TSQLQuery.SQLParser(var ASQL : string);
+procedure TCustomSQLQuery.SQLParser(var ASQL : string);
 
 
 type TParsePart = (ppStart,ppSelect,ppWhere,ppFrom,ppOrder,ppComment,ppGroup,ppBogus);
 type TParsePart = (ppStart,ppSelect,ppWhere,ppFrom,ppOrder,ppComment,ppGroup,ppBogus);
 
 
@@ -1029,7 +1052,7 @@ begin
     end
     end
 end;
 end;
 
 
-procedure TSQLQuery.InitUpdates(ASQL : string);
+procedure TCustomSQLQuery.InitUpdates(ASQL : string);
 
 
 
 
 begin
 begin
@@ -1043,12 +1066,12 @@ begin
 
 
 end;
 end;
 
 
-procedure TSQLQuery.InternalOpen;
+procedure TCustomSQLQuery.InternalOpen;
 
 
-  procedure InitialiseModifyQuery(var qry : TSQLQuery; aSQL: TSTringList);
+  procedure InitialiseModifyQuery(var qry : TCustomSQLQuery; aSQL: TSTringList);
   
   
   begin
   begin
-    qry := TSQLQuery.Create(nil);
+    qry := TCustomSQLQuery.Create(nil);
     with qry do
     with qry do
       begin
       begin
       ParseSQL := False;
       ParseSQL := False;
@@ -1120,7 +1143,7 @@ end;
 
 
 // public part
 // public part
 
 
-procedure TSQLQuery.ExecSQL;
+procedure TCustomSQLQuery.ExecSQL;
 begin
 begin
   try
   try
     Prepare;
     Prepare;
@@ -1132,7 +1155,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-constructor TSQLQuery.Create(AOwner : TComponent);
+constructor TCustomSQLQuery.Create(AOwner : TComponent);
 begin
 begin
   inherited Create(AOwner);
   inherited Create(AOwner);
   FParams := TParams.create(self);
   FParams := TParams.create(self);
@@ -1159,7 +1182,7 @@ begin
   FUsePrimaryKeyAsKey := True;
   FUsePrimaryKeyAsKey := True;
 end;
 end;
 
 
-destructor TSQLQuery.Destroy;
+destructor TCustomSQLQuery.Destroy;
 begin
 begin
   if Active then Close;
   if Active then Close;
   UnPrepare;
   UnPrepare;
@@ -1174,7 +1197,7 @@ begin
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
-procedure TSQLQuery.SetReadOnly(AValue : Boolean);
+procedure TCustomSQLQuery.SetReadOnly(AValue : Boolean);
 
 
 begin
 begin
   CheckInactive;
   CheckInactive;
@@ -1186,7 +1209,7 @@ begin
   else FReadOnly := True;
   else FReadOnly := True;
 end;
 end;
 
 
-procedure TSQLQuery.SetParseSQL(AValue : Boolean);
+procedure TCustomSQLQuery.SetParseSQL(AValue : Boolean);
 
 
 begin
 begin
   CheckInactive;
   CheckInactive;
@@ -1200,7 +1223,7 @@ begin
     FParseSQL := True;
     FParseSQL := True;
 end;
 end;
 
 
-procedure TSQLQuery.SetUsePrimaryKeyAsKey(AValue : Boolean);
+procedure TCustomSQLQuery.SetUsePrimaryKeyAsKey(AValue : Boolean);
 
 
 begin
 begin
   if not Active then FusePrimaryKeyAsKey := AValue
   if not Active then FusePrimaryKeyAsKey := AValue
@@ -1211,14 +1234,14 @@ begin
     end;
     end;
 end;
 end;
 
 
-Procedure TSQLQuery.UpdateIndexDefs;
+Procedure TCustomSQLQuery.UpdateIndexDefs;
 
 
 begin
 begin
   if assigned(DataBase) then
   if assigned(DataBase) then
     (DataBase as TSQLConnection).UpdateIndexDefs(FIndexDefs,FTableName);
     (DataBase as TSQLConnection).UpdateIndexDefs(FIndexDefs,FTableName);
 end;
 end;
 
 
-Procedure TSQLQuery.ApplyRecUpdate(UpdateKind : TUpdateKind);
+Procedure TCustomSQLQuery.ApplyRecUpdate(UpdateKind : TUpdateKind);
 
 
   procedure UpdateWherePart(var sql_where : string;x : integer);
   procedure UpdateWherePart(var sql_where : string;x : integer);
 
 
@@ -1294,7 +1317,7 @@ Procedure TSQLQuery.ApplyRecUpdate(UpdateKind : TUpdateKind);
     result := 'delete from ' + FTableName + ' where ' + sql_where;
     result := 'delete from ' + FTableName + ' where ' + sql_where;
   end;
   end;
 
 
-var qry : tsqlquery;
+var qry : TCustomSQLQuery;
     x   : integer;
     x   : integer;
     Fld : TField;
     Fld : TField;
     
     
@@ -1330,7 +1353,7 @@ begin
 end;
 end;
 
 
 
 
-Function TSQLQuery.GetCanModify: Boolean;
+Function TCustomSQLQuery.GetCanModify: Boolean;
 
 
 begin
 begin
   // the test for assigned(FCursor) is needed for the case that the dataset isn't opened
   // the test for assigned(FCursor) is needed for the case that the dataset isn't opened
@@ -1340,25 +1363,25 @@ begin
     Result := False;
     Result := False;
 end;
 end;
 
 
-function TSQLQuery.GetIndexDefs : TIndexDefs;
+function TCustomSQLQuery.GetIndexDefs : TIndexDefs;
 
 
 begin
 begin
   Result := FIndexDefs;
   Result := FIndexDefs;
 end;
 end;
 
 
-procedure TSQLQuery.SetIndexDefs(AValue : TIndexDefs);
+procedure TCustomSQLQuery.SetIndexDefs(AValue : TIndexDefs);
 
 
 begin
 begin
   FIndexDefs := AValue;
   FIndexDefs := AValue;
 end;
 end;
 
 
-procedure TSQLQuery.SetUpdateMode(AValue : TUpdateMode);
+procedure TCustomSQLQuery.SetUpdateMode(AValue : TUpdateMode);
 
 
 begin
 begin
   FUpdateMode := AValue;
   FUpdateMode := AValue;
 end;
 end;
 
 
-procedure TSQLQuery.SetSchemaInfo( SchemaType : TSchemaType; SchemaObjectName, SchemaPattern : string);
+procedure TCustomSQLQuery.SetSchemaInfo( SchemaType : TSchemaType; SchemaObjectName, SchemaPattern : string);
 
 
 begin
 begin
   ReadOnly := True;
   ReadOnly := True;
@@ -1366,20 +1389,20 @@ begin
   SQL.Add((DataBase as tsqlconnection).GetSchemaInfoSQL(SchemaType, SchemaObjectName, SchemaPattern));
   SQL.Add((DataBase as tsqlconnection).GetSchemaInfoSQL(SchemaType, SchemaObjectName, SchemaPattern));
 end;
 end;
 
 
-procedure TSQLQuery.LoadBlobIntoBuffer(FieldDef: TFieldDef;
+procedure TCustomSQLQuery.LoadBlobIntoBuffer(FieldDef: TFieldDef;
   ABlobBuf: PBufBlobField);
   ABlobBuf: PBufBlobField);
 begin
 begin
   (DataBase as tsqlconnection).LoadBlobIntoBuffer(FieldDef, ABlobBuf, FCursor,(Transaction as tsqltransaction));
   (DataBase as tsqlconnection).LoadBlobIntoBuffer(FieldDef, ABlobBuf, FCursor,(Transaction as tsqltransaction));
 end;
 end;
 
 
-function TSQLQuery.GetStatementType : TStatementType;
+function TCustomSQLQuery.GetStatementType : TStatementType;
 
 
 begin
 begin
   if assigned(FCursor) then Result := FCursor.FStatementType
   if assigned(FCursor) then Result := FCursor.FStatementType
     else Result := stNone;
     else Result := stNone;
 end;
 end;
 
 
-Procedure TSQLQuery.SetDataSource(AVAlue : TDatasource);
+Procedure TCustomSQLQuery.SetDataSource(AVAlue : TDatasource);
 
 
 Var
 Var
   DS : TDatasource;
   DS : TDatasource;
@@ -1401,7 +1424,7 @@ begin
     end;
     end;
 end;
 end;
 
 
-Function TSQLQuery.GetDataSource : TDatasource;
+Function TCustomSQLQuery.GetDataSource : TDatasource;
 
 
 begin
 begin
   If Assigned(FMasterLink) then
   If Assigned(FMasterLink) then
@@ -1410,7 +1433,7 @@ begin
     Result:=Nil;
     Result:=Nil;
 end;
 end;
 
 
-procedure TSQLQuery.Notification(AComponent: TComponent; Operation: TOperation); 
+procedure TCustomSQLQuery.Notification(AComponent: TComponent; Operation: TOperation); 
 
 
 begin
 begin
   Inherited;
   Inherited;
@@ -1445,7 +1468,7 @@ constructor TSQLScript.Create(AOwner: TComponent);
 begin
 begin
   inherited Create(AOwner);
   inherited Create(AOwner);
   FScript := TStringList.Create;
   FScript := TStringList.Create;
-  FQuery := TSQLQuery.Create(nil);
+  FQuery := TCustomSQLQuery.Create(nil);
 end;
 end;
 
 
 destructor TSQLScript.Destroy;
 destructor TSQLScript.Destroy;