mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 02:49:21 +02:00
* Removed unnecessary "as" calls, added class-type checks in SetDatabase
git-svn-id: trunk@8861 -
This commit is contained in:
parent
072c0fcf0e
commit
3e2b2b3aa5
@ -39,6 +39,7 @@ Resourcestring
|
|||||||
SErrIndexBasedOnInvField = 'Field "%s" is an invalid field type to base index on.';
|
SErrIndexBasedOnInvField = 'Field "%s" is an invalid field type to base index on.';
|
||||||
SErrIndexBasedOnUnkField = 'Index based on unknown field "%s".';
|
SErrIndexBasedOnUnkField = 'Index based on unknown field "%s".';
|
||||||
SErrConnTransactionnSet = 'Transaction of connection not set';
|
SErrConnTransactionnSet = 'Transaction of connection not set';
|
||||||
|
SErrNotASQLConnection = '"%s" is not a TSQLConnection';
|
||||||
STransNotActive = 'Operation cannot be performed on an inactive transaction';
|
STransNotActive = 'Operation cannot be performed on an inactive transaction';
|
||||||
STransActive = 'Operation cannot be performed on an active transaction';
|
STransActive = 'Operation cannot be performed on an active transaction';
|
||||||
SFieldNotFound = 'Field not found : "%s"';
|
SFieldNotFound = 'Field not found : "%s"';
|
||||||
|
@ -644,7 +644,7 @@ end;
|
|||||||
|
|
||||||
function TSQLTransaction.GetHandle: pointer;
|
function TSQLTransaction.GetHandle: pointer;
|
||||||
begin
|
begin
|
||||||
Result := (Database as tsqlconnection).GetTransactionHandle(FTrans);
|
Result := TSQLConnection(Database).GetTransactionHandle(FTrans);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSQLTransaction.Commit;
|
procedure TSQLTransaction.Commit;
|
||||||
@ -652,7 +652,7 @@ begin
|
|||||||
if active then
|
if active then
|
||||||
begin
|
begin
|
||||||
closedatasets;
|
closedatasets;
|
||||||
if (Database as tsqlconnection).commit(FTrans) then
|
if TSQLConnection(Database).commit(FTrans) then
|
||||||
begin
|
begin
|
||||||
closeTrans;
|
closeTrans;
|
||||||
FreeAndNil(FTrans);
|
FreeAndNil(FTrans);
|
||||||
@ -663,7 +663,7 @@ end;
|
|||||||
procedure TSQLTransaction.CommitRetaining;
|
procedure TSQLTransaction.CommitRetaining;
|
||||||
begin
|
begin
|
||||||
if active then
|
if active then
|
||||||
(Database as tsqlconnection).commitRetaining(FTrans);
|
TSQLConnection(Database).commitRetaining(FTrans);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSQLTransaction.Rollback;
|
procedure TSQLTransaction.Rollback;
|
||||||
@ -671,7 +671,7 @@ begin
|
|||||||
if active then
|
if active then
|
||||||
begin
|
begin
|
||||||
closedatasets;
|
closedatasets;
|
||||||
if (Database as tsqlconnection).RollBack(FTrans) then
|
if TSQLConnection(Database).RollBack(FTrans) then
|
||||||
begin
|
begin
|
||||||
CloseTrans;
|
CloseTrans;
|
||||||
FreeAndNil(FTrans);
|
FreeAndNil(FTrans);
|
||||||
@ -682,7 +682,7 @@ end;
|
|||||||
procedure TSQLTransaction.RollbackRetaining;
|
procedure TSQLTransaction.RollbackRetaining;
|
||||||
begin
|
begin
|
||||||
if active then
|
if active then
|
||||||
(Database as tsqlconnection).RollBackRetaining(FTrans);
|
TSQLConnection(Database).RollBackRetaining(FTrans);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSQLTransaction.StartTransaction;
|
procedure TSQLTransaction.StartTransaction;
|
||||||
@ -693,7 +693,7 @@ begin
|
|||||||
if Active then
|
if Active then
|
||||||
DatabaseError(SErrTransAlreadyActive);
|
DatabaseError(SErrTransAlreadyActive);
|
||||||
|
|
||||||
db := (Database as tsqlconnection);
|
db := TSQLConnection(Database);
|
||||||
|
|
||||||
if Db = nil then
|
if Db = nil then
|
||||||
DatabaseError(SErrDatabasenAssigned);
|
DatabaseError(SErrDatabasenAssigned);
|
||||||
@ -723,9 +723,11 @@ Procedure TSQLTransaction.SetDatabase(Value : TDatabase);
|
|||||||
begin
|
begin
|
||||||
If Value<>Database then
|
If Value<>Database then
|
||||||
begin
|
begin
|
||||||
|
if assigned(value) and not (Value is TSQLConnection) then
|
||||||
|
DatabaseErrorFmt(SErrNotASQLConnection,[value.Name],self);
|
||||||
CheckInactive;
|
CheckInactive;
|
||||||
If Assigned(Database) then
|
If Assigned(Database) then
|
||||||
with Database as TSqlConnection do
|
with TSQLConnection(DataBase) do
|
||||||
if Transaction = self then Transaction := nil;
|
if Transaction = self then Transaction := nil;
|
||||||
inherited SetDatabase(Value);
|
inherited SetDatabase(Value);
|
||||||
end;
|
end;
|
||||||
@ -741,7 +743,7 @@ begin
|
|||||||
if (FSQL <> nil) then
|
if (FSQL <> nil) then
|
||||||
begin
|
begin
|
||||||
if assigned(DataBase) then
|
if assigned(DataBase) then
|
||||||
ConnOptions := (DataBase as TSQLConnection).ConnOptions
|
ConnOptions := TSQLConnection(DataBase).ConnOptions
|
||||||
else
|
else
|
||||||
ConnOptions := [sqEscapeRepeat,sqEscapeSlash];
|
ConnOptions := [sqEscapeRepeat,sqEscapeSlash];
|
||||||
Fparams.ParseSQL(FSQL.Text,True, sqEscapeSlash in ConnOptions, sqEscapeRepeat in ConnOptions,psInterbase);
|
Fparams.ParseSQL(FSQL.Text,True, sqEscapeSlash in ConnOptions, sqEscapeRepeat in ConnOptions,psInterbase);
|
||||||
@ -770,9 +772,11 @@ var db : tsqlconnection;
|
|||||||
begin
|
begin
|
||||||
if (Database <> Value) then
|
if (Database <> Value) then
|
||||||
begin
|
begin
|
||||||
|
if assigned(value) and not (Value is TSQLConnection) then
|
||||||
|
DatabaseErrorFmt(SErrNotASQLConnection,[value.Name],self);
|
||||||
UnPrepare;
|
UnPrepare;
|
||||||
if assigned(FCursor) then (Database as TSQLConnection).DeAllocateCursorHandle(FCursor);
|
if assigned(FCursor) then TSQLConnection(DataBase).DeAllocateCursorHandle(FCursor);
|
||||||
db := value as tsqlconnection;
|
db := TSQLConnection(Value);
|
||||||
inherited setdatabase(value);
|
inherited setdatabase(value);
|
||||||
if assigned(value) and (Transaction = nil) and (Assigned(db.Transaction)) then
|
if assigned(value) and (Transaction = nil) and (Assigned(db.Transaction)) then
|
||||||
transaction := Db.Transaction;
|
transaction := Db.Transaction;
|
||||||
@ -804,7 +808,7 @@ var S : String;
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
FreeFldBuffers;
|
FreeFldBuffers;
|
||||||
(Database as tsqlconnection).UnPrepareStatement(FCursor);
|
TSQLConnection(Database).UnPrepareStatement(FCursor);
|
||||||
FIsEOF := False;
|
FIsEOF := False;
|
||||||
inherited internalclose;
|
inherited internalclose;
|
||||||
|
|
||||||
@ -812,7 +816,7 @@ begin
|
|||||||
|
|
||||||
if ServerFiltered then s := AddFilter(s);
|
if ServerFiltered then s := AddFilter(s);
|
||||||
|
|
||||||
(Database as tsqlconnection).PrepareStatement(Fcursor,(transaction as tsqltransaction),S,FParams);
|
TSQLConnection(Database).PrepareStatement(Fcursor,(transaction as tsqltransaction),S,FParams);
|
||||||
|
|
||||||
Execute;
|
Execute;
|
||||||
inherited InternalOpen;
|
inherited InternalOpen;
|
||||||
@ -857,7 +861,7 @@ var
|
|||||||
begin
|
begin
|
||||||
if not IsPrepared then
|
if not IsPrepared then
|
||||||
begin
|
begin
|
||||||
db := (Database as tsqlconnection);
|
db := TSQLConnection(Database);
|
||||||
sqltr := (transaction as tsqltransaction);
|
sqltr := (transaction as tsqltransaction);
|
||||||
if not assigned(Db) then
|
if not assigned(Db) then
|
||||||
DatabaseError(SErrDatabasenAssigned);
|
DatabaseError(SErrDatabasenAssigned);
|
||||||
@ -895,13 +899,13 @@ procedure TCustomSQLQuery.UnPrepare;
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
CheckInactive;
|
CheckInactive;
|
||||||
if IsPrepared then with Database as TSQLConnection do
|
if IsPrepared then with TSQLConnection(DataBase) do
|
||||||
UnPrepareStatement(FCursor);
|
UnPrepareStatement(FCursor);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomSQLQuery.FreeFldBuffers;
|
procedure TCustomSQLQuery.FreeFldBuffers;
|
||||||
begin
|
begin
|
||||||
if assigned(FCursor) then (Database as tsqlconnection).FreeFldBuffers(FCursor);
|
if assigned(FCursor) then TSQLConnection(Database).FreeFldBuffers(FCursor);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomSQLQuery.Fetch : boolean;
|
function TCustomSQLQuery.Fetch : boolean;
|
||||||
@ -909,7 +913,7 @@ begin
|
|||||||
if not (Fcursor.FStatementType in [stSelect]) then
|
if not (Fcursor.FStatementType in [stSelect]) then
|
||||||
Exit;
|
Exit;
|
||||||
|
|
||||||
if not FIsEof then FIsEOF := not (Database as tsqlconnection).Fetch(Fcursor);
|
if not FIsEof then FIsEOF := not TSQLConnection(Database).Fetch(Fcursor);
|
||||||
Result := not FIsEOF;
|
Result := not FIsEOF;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -917,13 +921,13 @@ 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);
|
TSQLConnection(Database).execute(Fcursor,Transaction as tsqltransaction, FParams);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomSQLQuery.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 := TSQLConnection(Database).LoadField(FCursor,FieldDef,buffer, Createblob)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomSQLQuery.RowsAffected: TRowsCount;
|
function TCustomSQLQuery.RowsAffected: TRowsCount;
|
||||||
@ -931,7 +935,7 @@ begin
|
|||||||
Result := -1;
|
Result := -1;
|
||||||
if not Assigned(Database) then Exit;
|
if not Assigned(Database) then Exit;
|
||||||
//assert(Database is TSQLConnection);
|
//assert(Database is TSQLConnection);
|
||||||
Result := (Database as TSQLConnection).RowsAffected(FCursor);
|
Result := TSQLConnection(Database).RowsAffected(FCursor);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomSQLQuery.InternalAddRecord(Buffer: Pointer; AAppend: Boolean);
|
procedure TCustomSQLQuery.InternalAddRecord(Buffer: Pointer; AAppend: Boolean);
|
||||||
@ -943,7 +947,7 @@ 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
|
||||||
if (not IsPrepared) and (assigned(database)) and (assigned(FCursor)) then (database as TSQLconnection).UnPrepareStatement(FCursor);
|
if (not IsPrepared) and (assigned(database)) and (assigned(FCursor)) then TSQLConnection(database).UnPrepareStatement(FCursor);
|
||||||
if DefaultFields then
|
if DefaultFields then
|
||||||
DestroyFields;
|
DestroyFields;
|
||||||
FIsEOF := False;
|
FIsEOF := False;
|
||||||
@ -964,7 +968,7 @@ begin
|
|||||||
try
|
try
|
||||||
FieldDefs.Clear;
|
FieldDefs.Clear;
|
||||||
|
|
||||||
(Database as tsqlconnection).AddFieldDefs(fcursor,FieldDefs);
|
TSQLConnection(Database).AddFieldDefs(fcursor,FieldDefs);
|
||||||
finally
|
finally
|
||||||
FLoadingFieldDefs := False;
|
FLoadingFieldDefs := False;
|
||||||
FCursor.FInitFieldDef := false;
|
FCursor.FInitFieldDef := false;
|
||||||
@ -995,7 +999,7 @@ begin
|
|||||||
FWhereStartPos := 0;
|
FWhereStartPos := 0;
|
||||||
FWhereStopPos := 0;
|
FWhereStopPos := 0;
|
||||||
|
|
||||||
ConnOptions := (DataBase as TSQLConnection).ConnOptions;
|
ConnOptions := TSQLConnection(DataBase).ConnOptions;
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
begin
|
begin
|
||||||
@ -1031,7 +1035,7 @@ begin
|
|||||||
|
|
||||||
case ParsePart of
|
case ParsePart of
|
||||||
ppStart : begin
|
ppStart : begin
|
||||||
FCursor.FStatementType := (Database as tsqlconnection).StrToStatementType(s);
|
FCursor.FStatementType := TSQLConnection(Database).StrToStatementType(s);
|
||||||
if FCursor.FStatementType = stSelect then ParsePart := ppSelect
|
if FCursor.FStatementType = stSelect then ParsePart := ppSelect
|
||||||
else break;
|
else break;
|
||||||
if not FParseSQL then break;
|
if not FParseSQL then break;
|
||||||
@ -1199,7 +1203,7 @@ begin
|
|||||||
finally
|
finally
|
||||||
// FCursor has to be assigned, or else the prepare went wrong before PrepareStatment was
|
// FCursor has to be assigned, or else the prepare went wrong before PrepareStatment was
|
||||||
// called, so UnPrepareStatement shoudn't be called either
|
// called, so UnPrepareStatement shoudn't be called either
|
||||||
if (not IsPrepared) and (assigned(database)) and (assigned(FCursor)) then (database as TSQLConnection).UnPrepareStatement(Fcursor);
|
if (not IsPrepared) and (assigned(database)) and (assigned(FCursor)) then TSQLConnection(database).UnPrepareStatement(Fcursor);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1234,7 +1238,7 @@ destructor TCustomSQLQuery.Destroy;
|
|||||||
begin
|
begin
|
||||||
if Active then Close;
|
if Active then Close;
|
||||||
UnPrepare;
|
UnPrepare;
|
||||||
if assigned(FCursor) then (Database as TSQLConnection).DeAllocateCursorHandle(FCursor);
|
if assigned(FCursor) then TSQLConnection(Database).DeAllocateCursorHandle(FCursor);
|
||||||
FreeAndNil(FMasterLink);
|
FreeAndNil(FMasterLink);
|
||||||
FreeAndNil(FParams);
|
FreeAndNil(FParams);
|
||||||
FreeAndNil(FSQL);
|
FreeAndNil(FSQL);
|
||||||
@ -1286,7 +1290,7 @@ Procedure TCustomSQLQuery.UpdateIndexDefs;
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
if assigned(DataBase) then
|
if assigned(DataBase) then
|
||||||
(DataBase as TSQLConnection).UpdateIndexDefs(FIndexDefs,FTableName);
|
TSQLConnection(DataBase).UpdateIndexDefs(FIndexDefs,FTableName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Procedure TCustomSQLQuery.ApplyRecUpdate(UpdateKind : TUpdateKind);
|
Procedure TCustomSQLQuery.ApplyRecUpdate(UpdateKind : TUpdateKind);
|
||||||
@ -1434,13 +1438,13 @@ procedure TCustomSQLQuery.SetSchemaInfo( SchemaType : TSchemaType; SchemaObjectN
|
|||||||
begin
|
begin
|
||||||
ReadOnly := True;
|
ReadOnly := True;
|
||||||
SQL.Clear;
|
SQL.Clear;
|
||||||
SQL.Add((DataBase as tsqlconnection).GetSchemaInfoSQL(SchemaType, SchemaObjectName, SchemaPattern));
|
SQL.Add(TSQLConnection(DataBase).GetSchemaInfoSQL(SchemaType, SchemaObjectName, SchemaPattern));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomSQLQuery.LoadBlobIntoBuffer(FieldDef: TFieldDef;
|
procedure TCustomSQLQuery.LoadBlobIntoBuffer(FieldDef: TFieldDef;
|
||||||
ABlobBuf: PBufBlobField);
|
ABlobBuf: PBufBlobField);
|
||||||
begin
|
begin
|
||||||
(DataBase as tsqlconnection).LoadBlobIntoBuffer(FieldDef, ABlobBuf, FCursor,(Transaction as tsqltransaction));
|
TSQLConnection(DataBase).LoadBlobIntoBuffer(FieldDef, ABlobBuf, FCursor,(Transaction as tsqltransaction));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomSQLQuery.GetStatementType : TStatementType;
|
function TCustomSQLQuery.GetStatementType : TStatementType;
|
||||||
|
Loading…
Reference in New Issue
Block a user