* Removed unnecessary "as" calls, added class-type checks in SetDatabase

git-svn-id: trunk@8861 -
This commit is contained in:
joost 2007-10-20 12:16:24 +00:00
parent 072c0fcf0e
commit 3e2b2b3aa5
2 changed files with 33 additions and 28 deletions

View File

@ -39,6 +39,7 @@ Resourcestring
SErrIndexBasedOnInvField = 'Field "%s" is an invalid field type to base index on.';
SErrIndexBasedOnUnkField = 'Index based on unknown field "%s".';
SErrConnTransactionnSet = 'Transaction of connection not set';
SErrNotASQLConnection = '"%s" is not a TSQLConnection';
STransNotActive = 'Operation cannot be performed on an inactive transaction';
STransActive = 'Operation cannot be performed on an active transaction';
SFieldNotFound = 'Field not found : "%s"';

View File

@ -644,7 +644,7 @@ end;
function TSQLTransaction.GetHandle: pointer;
begin
Result := (Database as tsqlconnection).GetTransactionHandle(FTrans);
Result := TSQLConnection(Database).GetTransactionHandle(FTrans);
end;
procedure TSQLTransaction.Commit;
@ -652,7 +652,7 @@ begin
if active then
begin
closedatasets;
if (Database as tsqlconnection).commit(FTrans) then
if TSQLConnection(Database).commit(FTrans) then
begin
closeTrans;
FreeAndNil(FTrans);
@ -663,7 +663,7 @@ end;
procedure TSQLTransaction.CommitRetaining;
begin
if active then
(Database as tsqlconnection).commitRetaining(FTrans);
TSQLConnection(Database).commitRetaining(FTrans);
end;
procedure TSQLTransaction.Rollback;
@ -671,7 +671,7 @@ begin
if active then
begin
closedatasets;
if (Database as tsqlconnection).RollBack(FTrans) then
if TSQLConnection(Database).RollBack(FTrans) then
begin
CloseTrans;
FreeAndNil(FTrans);
@ -682,7 +682,7 @@ end;
procedure TSQLTransaction.RollbackRetaining;
begin
if active then
(Database as tsqlconnection).RollBackRetaining(FTrans);
TSQLConnection(Database).RollBackRetaining(FTrans);
end;
procedure TSQLTransaction.StartTransaction;
@ -693,7 +693,7 @@ begin
if Active then
DatabaseError(SErrTransAlreadyActive);
db := (Database as tsqlconnection);
db := TSQLConnection(Database);
if Db = nil then
DatabaseError(SErrDatabasenAssigned);
@ -723,9 +723,11 @@ Procedure TSQLTransaction.SetDatabase(Value : TDatabase);
begin
If Value<>Database then
begin
if assigned(value) and not (Value is TSQLConnection) then
DatabaseErrorFmt(SErrNotASQLConnection,[value.Name],self);
CheckInactive;
If Assigned(Database) then
with Database as TSqlConnection do
with TSQLConnection(DataBase) do
if Transaction = self then Transaction := nil;
inherited SetDatabase(Value);
end;
@ -741,7 +743,7 @@ begin
if (FSQL <> nil) then
begin
if assigned(DataBase) then
ConnOptions := (DataBase as TSQLConnection).ConnOptions
ConnOptions := TSQLConnection(DataBase).ConnOptions
else
ConnOptions := [sqEscapeRepeat,sqEscapeSlash];
Fparams.ParseSQL(FSQL.Text,True, sqEscapeSlash in ConnOptions, sqEscapeRepeat in ConnOptions,psInterbase);
@ -770,9 +772,11 @@ var db : tsqlconnection;
begin
if (Database <> Value) then
begin
if assigned(value) and not (Value is TSQLConnection) then
DatabaseErrorFmt(SErrNotASQLConnection,[value.Name],self);
UnPrepare;
if assigned(FCursor) then (Database as TSQLConnection).DeAllocateCursorHandle(FCursor);
db := value as tsqlconnection;
if assigned(FCursor) then TSQLConnection(DataBase).DeAllocateCursorHandle(FCursor);
db := TSQLConnection(Value);
inherited setdatabase(value);
if assigned(value) and (Transaction = nil) and (Assigned(db.Transaction)) then
transaction := Db.Transaction;
@ -804,7 +808,7 @@ var S : String;
begin
FreeFldBuffers;
(Database as tsqlconnection).UnPrepareStatement(FCursor);
TSQLConnection(Database).UnPrepareStatement(FCursor);
FIsEOF := False;
inherited internalclose;
@ -812,7 +816,7 @@ begin
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;
inherited InternalOpen;
@ -857,7 +861,7 @@ var
begin
if not IsPrepared then
begin
db := (Database as tsqlconnection);
db := TSQLConnection(Database);
sqltr := (transaction as tsqltransaction);
if not assigned(Db) then
DatabaseError(SErrDatabasenAssigned);
@ -895,13 +899,13 @@ procedure TCustomSQLQuery.UnPrepare;
begin
CheckInactive;
if IsPrepared then with Database as TSQLConnection do
if IsPrepared then with TSQLConnection(DataBase) do
UnPrepareStatement(FCursor);
end;
procedure TCustomSQLQuery.FreeFldBuffers;
begin
if assigned(FCursor) then (Database as tsqlconnection).FreeFldBuffers(FCursor);
if assigned(FCursor) then TSQLConnection(Database).FreeFldBuffers(FCursor);
end;
function TCustomSQLQuery.Fetch : boolean;
@ -909,7 +913,7 @@ begin
if not (Fcursor.FStatementType in [stSelect]) then
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;
end;
@ -917,13 +921,13 @@ procedure TCustomSQLQuery.Execute;
begin
If (FParams.Count>0) and Assigned(FMasterLink) then
FMasterLink.CopyParamsFromMaster(False);
(Database as tsqlconnection).execute(Fcursor,Transaction as tsqltransaction, FParams);
TSQLConnection(Database).execute(Fcursor,Transaction as tsqltransaction, FParams);
end;
function TCustomSQLQuery.LoadField(FieldDef : TFieldDef;buffer : pointer; out CreateBlob : boolean) : boolean;
begin
result := (Database as tSQLConnection).LoadField(FCursor,FieldDef,buffer, Createblob)
result := TSQLConnection(Database).LoadField(FCursor,FieldDef,buffer, Createblob)
end;
function TCustomSQLQuery.RowsAffected: TRowsCount;
@ -931,7 +935,7 @@ begin
Result := -1;
if not Assigned(Database) then Exit;
//assert(Database is TSQLConnection);
Result := (Database as TSQLConnection).RowsAffected(FCursor);
Result := TSQLConnection(Database).RowsAffected(FCursor);
end;
procedure TCustomSQLQuery.InternalAddRecord(Buffer: Pointer; AAppend: Boolean);
@ -943,7 +947,7 @@ procedure TCustomSQLQuery.InternalClose;
begin
if StatementType = stSelect then FreeFldBuffers;
// 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
DestroyFields;
FIsEOF := False;
@ -964,7 +968,7 @@ begin
try
FieldDefs.Clear;
(Database as tsqlconnection).AddFieldDefs(fcursor,FieldDefs);
TSQLConnection(Database).AddFieldDefs(fcursor,FieldDefs);
finally
FLoadingFieldDefs := False;
FCursor.FInitFieldDef := false;
@ -995,7 +999,7 @@ begin
FWhereStartPos := 0;
FWhereStopPos := 0;
ConnOptions := (DataBase as TSQLConnection).ConnOptions;
ConnOptions := TSQLConnection(DataBase).ConnOptions;
repeat
begin
@ -1031,7 +1035,7 @@ begin
case ParsePart of
ppStart : begin
FCursor.FStatementType := (Database as tsqlconnection).StrToStatementType(s);
FCursor.FStatementType := TSQLConnection(Database).StrToStatementType(s);
if FCursor.FStatementType = stSelect then ParsePart := ppSelect
else break;
if not FParseSQL then break;
@ -1199,7 +1203,7 @@ begin
finally
// FCursor has to be assigned, or else the prepare went wrong before PrepareStatment was
// 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;
@ -1234,7 +1238,7 @@ destructor TCustomSQLQuery.Destroy;
begin
if Active then Close;
UnPrepare;
if assigned(FCursor) then (Database as TSQLConnection).DeAllocateCursorHandle(FCursor);
if assigned(FCursor) then TSQLConnection(Database).DeAllocateCursorHandle(FCursor);
FreeAndNil(FMasterLink);
FreeAndNil(FParams);
FreeAndNil(FSQL);
@ -1286,7 +1290,7 @@ Procedure TCustomSQLQuery.UpdateIndexDefs;
begin
if assigned(DataBase) then
(DataBase as TSQLConnection).UpdateIndexDefs(FIndexDefs,FTableName);
TSQLConnection(DataBase).UpdateIndexDefs(FIndexDefs,FTableName);
end;
Procedure TCustomSQLQuery.ApplyRecUpdate(UpdateKind : TUpdateKind);
@ -1434,13 +1438,13 @@ procedure TCustomSQLQuery.SetSchemaInfo( SchemaType : TSchemaType; SchemaObjectN
begin
ReadOnly := True;
SQL.Clear;
SQL.Add((DataBase as tsqlconnection).GetSchemaInfoSQL(SchemaType, SchemaObjectName, SchemaPattern));
SQL.Add(TSQLConnection(DataBase).GetSchemaInfoSQL(SchemaType, SchemaObjectName, SchemaPattern));
end;
procedure TCustomSQLQuery.LoadBlobIntoBuffer(FieldDef: TFieldDef;
ABlobBuf: PBufBlobField);
begin
(DataBase as tsqlconnection).LoadBlobIntoBuffer(FieldDef, ABlobBuf, FCursor,(Transaction as tsqltransaction));
TSQLConnection(DataBase).LoadBlobIntoBuffer(FieldDef, ABlobBuf, FCursor,(Transaction as tsqltransaction));
end;
function TCustomSQLQuery.GetStatementType : TStatementType;