TBufDataset.inc:

- replaced Freemem by Reallocmem, Free by FreeAndNil

Database.inc:
  - Moved Active property from TSQLTransaction to TDBTransaction
  - Gives an error if the database of an active transaction is changed

Dataset.inc
  - Don't distribute events if FDisableControlsCount > 0
  - Replaced FActive by FState<>dsInactive
  - Set EOF after append

db.pp:
  - Removed duplicate definition of TAlignment
  - Moved Active property from TSQLTransaction to TDBTransaction
  - Replaced FActive by FState<>dsInactive
  - Gives an error if the database of an active transaction is changed

sqldb:
  - Moved Active property from TSQLTransaction to TDBTransaction
  - replaced Freemem by Reallocmem, Free by FreeAndNil

IBConnection:
  - Moved FSQLDAAllocated to the cursor

PQConnection:
  - Don't try to free the statement if a fatal error occured
This commit is contained in:
michael 2004-11-05 08:32:02 +00:00
parent 0909db20ec
commit cae7e81d73
8 changed files with 261 additions and 76 deletions

View File

@ -46,7 +46,7 @@ end;
procedure TBufDataset.FreeRecordBuffer(var Buffer: PChar);
begin
FreeMem(Buffer);
ReAllocMem(Buffer,0);
end;
procedure TBufDataset.InternalOpen;
@ -65,7 +65,7 @@ var i : integer;
begin
for i := 0 to FBRecordCount-1 do FreeRecord(FBBuffers[i]);
If FBRecordCount > 0 then freemem(FBBuffers);
If FBRecordCount > 0 then ReAllocMem(FBBuffers,0);
FBRecordcount := 0;
FBBuffercount := 0;
FBCurrentrecord := -1;

View File

@ -287,10 +287,58 @@ end;
{ ---------------------------------------------------------------------
TDBTransaction
---------------------------------------------------------------------}
procedure TDBTransaction.SetActive(Value : boolean);
begin
if FActive and (not Value) then
EndTransaction
else if (not FActive) and Value then
if csLoading in ComponentState then
begin
FOpenAfterRead := true;
exit;
end
else
StartTransaction;
end;
procedure TDBTransaction.Loaded;
begin
inherited;
if FOpenAfterRead then SetActive(true);
end;
Procedure TDBTransaction.CheckActive;
begin
If not FActive Then
DatabaseError(STransNotActive,Self);
end;
Procedure TDBTransaction.CheckInActive;
begin
If FActive Then
DatabaseError(STransActive,Self);
end;
Procedure TDBTransaction.CloseTrans;
begin
FActive := false;
end;
Procedure TDBTransaction.OpenTrans;
begin
FActive := true;
end;
Procedure TDBTransaction.SetDatabase (Value : TDatabase);
begin
// CheckInactive;
CheckInactive;
If Value<>FDatabase then
begin
If Assigned(FDatabase) then
@ -390,7 +438,36 @@ end;
{
$Log$
Revision 1.7 2004-10-27 07:23:13 michael
Revision 1.8 2004-11-05 08:32:02 michael
TBufDataset.inc:
- replaced Freemem by Reallocmem, Free by FreeAndNil
Database.inc:
- Moved Active property from TSQLTransaction to TDBTransaction
- Gives an error if the database of an active transaction is changed
Dataset.inc
- Don't distribute events if FDisableControlsCount > 0
- Replaced FActive by FState<>dsInactive
- Set EOF after append
db.pp:
- Removed duplicate definition of TAlignment
- Moved Active property from TSQLTransaction to TDBTransaction
- Replaced FActive by FState<>dsInactive
- Gives an error if the database of an active transaction is changed
sqldb:
- Moved Active property from TSQLTransaction to TDBTransaction
- replaced Freemem by Reallocmem, Free by FreeAndNil
IBConnection:
- Moved FSQLDAAllocated to the cursor
PQConnection:
- Don't try to free the statement if a fatal error occured
Revision 1.7 2004/10/27 07:23:13 michael
+ Patch from Joost Van der Sluis to fix transactions
Revision 1.6 2004/09/26 16:55:24 michael

View File

@ -187,8 +187,9 @@ begin
end;
end;
// Distribute event to datasets;
for I := 0 to FDataSources.Count - 1 do
TDataSource(FDataSources[I]).ProcessEvent(Event, Info);
if FDisableControlsCount = 0 then
for I := 0 to FDataSources.Count - 1 do
TDataSource(FDataSources[I]).ProcessEvent(Event, Info);
end;
Procedure TDataset.DestroyFields;
@ -652,21 +653,27 @@ begin
dec(FDisableControlsCount);
end;
function TDataset.GetActive : boolean;
begin
result := FState <> dsInactive;
end;
Procedure TDataset.SetActive (Value : Boolean);
begin
If Value<>Factive then
If Value then
if csLoading in ComponentState then
begin
FOpenAfterRead := true;
exit;
end
else
DoInternalOpen
if value and (Fstate = dsInactive) then
begin
if csLoading in ComponentState then
begin
FOpenAfterRead := true;
exit;
end
else
DoInternalClose(True);
FActive:=Value;
DoInternalOpen;
end
else if not value and (Fstate <> dsinactive) then
DoInternalClose(True);
end;
procedure TDataset.Loaded;
@ -1126,7 +1133,8 @@ begin
GetPriorRecords;
FActiveRecord:=FRecordCount-1;
DoInsert;
SetBookmarkFlag(ActiveBuffer,bfEOF)
SetBookmarkFlag(ActiveBuffer,bfEOF);
FEOF := true;
end;
SetState(dsInsert);
try
@ -1733,7 +1741,36 @@ end;
{
$Log$
Revision 1.27 2004-10-27 07:23:13 michael
Revision 1.28 2004-11-05 08:32:02 michael
TBufDataset.inc:
- replaced Freemem by Reallocmem, Free by FreeAndNil
Database.inc:
- Moved Active property from TSQLTransaction to TDBTransaction
- Gives an error if the database of an active transaction is changed
Dataset.inc
- Don't distribute events if FDisableControlsCount > 0
- Replaced FActive by FState<>dsInactive
- Set EOF after append
db.pp:
- Removed duplicate definition of TAlignment
- Moved Active property from TSQLTransaction to TDBTransaction
- Replaced FActive by FState<>dsInactive
- Gives an error if the database of an active transaction is changed
sqldb:
- Moved Active property from TSQLTransaction to TDBTransaction
- replaced Freemem by Reallocmem, Free by FreeAndNil
IBConnection:
- Moved FSQLDAAllocated to the cursor
PQConnection:
- Don't try to free the statement if a fatal error occured
Revision 1.27 2004/10/27 07:23:13 michael
+ Patch from Joost Van der Sluis to fix transactions
Revision 1.26 2004/10/16 09:27:23 michael

View File

@ -171,8 +171,6 @@ type
TFieldSetTextEvent = procedure(Sender: TField; const Text: string) of object;
TFieldRef = ^TField;
TFieldChars = set of Char;
{ TAlignment may need to come from somewhere else }
TAlignMent = (taLeftjustify,taCenter,taRightJustify);
TField = class(TComponent)
Private
@ -773,7 +771,6 @@ type
TDataSet = class(TComponent)
Private
FActive: Boolean;
FOpenAfterRead : boolean;
FActiveRecord: Longint;
FAfterCancel: TDataSetNotifyEvent;
@ -841,6 +838,7 @@ type
Procedure ShiftBuffersForward;
Procedure ShiftBuffersBackward;
Function TryDoing (P : TDataOperation; Ev : TDatasetErrorEvent) : Boolean;
Function GetActive : boolean;
Procedure UnRegisterDataSource(ADatasource : TDatasource);
Procedure UpdateFieldDefs;
protected
@ -1023,7 +1021,7 @@ type
property Filter: string read FFilterText write SetFilterText;
property Filtered: Boolean read FFiltered write SetFiltered default False;
property FilterOptions: TFilterOptions read FFilterOptions write FFilterOptions;
property Active: Boolean read FActive write SetActive default False;
property Active: Boolean read GetActive write SetActive default False;
property AutoCalcFields: Boolean read FAutoCalcFields write FAutoCalcFields;
property BeforeOpen: TDataSetNotifyEvent read FBeforeOpen write FBeforeOpen;
property AfterOpen: TDataSetNotifyEvent read FAfterOpen write FAfterOpen;
@ -1201,22 +1199,33 @@ type
TDBTransactionClass = Class of TDBTransaction;
TDBTransaction = Class(TComponent)
Private
FDatabase : TDatabase;
FDataSets : TList;
FActive : boolean;
FDatabase : TDatabase;
FDataSets : TList;
FOpenAfterRead : boolean;
Procedure SetDatabase (Value : TDatabase);
Function GetDataSetCount : Longint;
Function GetDataset(Index : longint) : TDBDataset;
procedure RegisterDataset (DS : TDBDataset);
procedure UnRegisterDataset (DS : TDBDataset);
procedure RemoveDataSets;
procedure SetActive(Value : boolean);
Protected
procedure CloseTrans;
procedure openTrans;
Procedure CheckDatabase;
Procedure CheckActive;
Procedure CheckInactive;
procedure EndTransaction; virtual; abstract;
procedure StartTransaction; virtual; abstract;
procedure Loaded; override;
Public
constructor Create(AOwner: TComponent); override;
Destructor destroy; override;
procedure CloseDataSets;
Property DataBase : TDatabase Read FDatabase Write SetDatabase;
published
property Active : boolean read FActive write setactive;
end;
{ TDatabase }
@ -1583,7 +1592,36 @@ end.
{
$Log$
Revision 1.27 2004-10-27 07:23:13 michael
Revision 1.28 2004-11-05 08:32:02 michael
TBufDataset.inc:
- replaced Freemem by Reallocmem, Free by FreeAndNil
Database.inc:
- Moved Active property from TSQLTransaction to TDBTransaction
- Gives an error if the database of an active transaction is changed
Dataset.inc
- Don't distribute events if FDisableControlsCount > 0
- Replaced FActive by FState<>dsInactive
- Set EOF after append
db.pp:
- Removed duplicate definition of TAlignment
- Moved Active property from TSQLTransaction to TDBTransaction
- Replaced FActive by FState<>dsInactive
- Gives an error if the database of an active transaction is changed
sqldb:
- Moved Active property from TSQLTransaction to TDBTransaction
- replaced Freemem by Reallocmem, Free by FreeAndNil
IBConnection:
- Moved FSQLDAAllocated to the cursor
PQConnection:
- Don't try to free the statement if a fatal error occured
Revision 1.27 2004/10/27 07:23:13 michael
+ Patch from Joost Van der Sluis to fix transactions
Revision 1.26 2004/10/10 14:45:51 michael

View File

@ -34,6 +34,8 @@ Const
SErrNoStatement = 'SQL statement not set';
SErrTransAlreadyActive = 'Transaction already active';
SErrTransactionnSet = 'Transaction not set';
STransNotActive = 'Operation cannot be performed on an inactive transaction';
STransActive = 'Operation cannot be performed on an active transaction';
SFieldNotFound = 'Field not found : "%s"';
SInactiveDataset = 'Operation cannot be performed on an inactive dataset';
SInvalidDisplayValues = '"%s" are not valid boolean displayvalues';
@ -66,7 +68,36 @@ end.
{
$Log$
Revision 1.3 2004-10-27 07:23:13 michael
Revision 1.4 2004-11-05 08:32:02 michael
TBufDataset.inc:
- replaced Freemem by Reallocmem, Free by FreeAndNil
Database.inc:
- Moved Active property from TSQLTransaction to TDBTransaction
- Gives an error if the database of an active transaction is changed
Dataset.inc
- Don't distribute events if FDisableControlsCount > 0
- Replaced FActive by FState<>dsInactive
- Set EOF after append
db.pp:
- Removed duplicate definition of TAlignment
- Moved Active property from TSQLTransaction to TDBTransaction
- Replaced FActive by FState<>dsInactive
- Gives an error if the database of an active transaction is changed
sqldb:
- Moved Active property from TSQLTransaction to TDBTransaction
- replaced Freemem by Reallocmem, Free by FreeAndNil
IBConnection:
- Moved FSQLDAAllocated to the cursor
PQConnection:
- Don't try to free the statement if a fatal error occured
Revision 1.3 2004/10/27 07:23:13 michael
+ Patch from Joost Van der Sluis to fix transactions
Revision 1.2 2004/10/16 09:20:25 michael

View File

@ -17,9 +17,10 @@ type
TIBCursor = Class(TSQLHandle)
protected
Status : array [0..19] of ISC_STATUS;
Statement : pointer;
SQLDA : PXSQLDA;
Status : array [0..19] of ISC_STATUS;
Statement : pointer;
FSQLDAAllocated : integer;
SQLDA : PXSQLDA;
end;
TIBTrans = Class(TSQLHandle)
@ -35,7 +36,6 @@ type
TIBConnection = class (TSQLConnection)
private
FSQLDAAllocated : integer;
FSQLDatabaseHandle : pointer;
FStatus : array [0..19] of ISC_STATUS;
FFieldFlag : array [0..1023] of shortint;

View File

@ -300,6 +300,7 @@ procedure TPQConnection.FreeStatement(cursor : TSQLHandle);
begin
with cursor as TPQCursor do
if (PQresultStatus(res) <> PGRES_FATAL_ERROR) then //Don't try to do anything if the transaction has already encountered an error.
begin
if StatementType = stselect then
begin
@ -307,7 +308,7 @@ begin
if (PQresultStatus(res) <> PGRES_COMMAND_OK) then
begin
pqclear(res);
DatabaseError(SErrClearSelection + ' (PostgreSQL: ' + PQerrorMessage(tr) + ')',self);
DatabaseError(SErrClearSelection + ' (PostgreSQL: ' + PQerrorMessage(tr) + ')',self)
end
end;
pqclear(baseres);
@ -335,7 +336,7 @@ begin
if (PQresultStatus(res) <> PGRES_COMMAND_OK) then
begin
pqclear(res);
DatabaseError(SErrExecuteFailed + ' (PostgreSQL: ' + PQerrorMessage(tr) + ')',self)
DatabaseError(SErrExecuteFailed + ' (PostgreSQL: ' + PQerrorMessage(tr) + ')',self);
end;
end;
end;

View File

@ -111,26 +111,20 @@ type
private
FTrans : TSQLHandle;
FAction : TCommitRollbackAction;
FActive : boolean;
FOpenAfterRead : boolean;
procedure SetActive(Value : boolean);
protected
function GetHandle : Pointer; virtual;
procedure Loaded; override;
public
procedure Commit; virtual;
procedure CommitRetaining; virtual;
procedure Rollback; virtual;
procedure RollbackRetaining; virtual;
procedure StartTransaction; virtual;
procedure StartTransaction; override;
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
property Handle: Pointer read GetHandle;
procedure EndTransaction; override;
published
property Action : TCommitRollbackAction read FAction write FAction;
property Active : boolean read FActive write setactive;
property Database;
end;
@ -275,28 +269,6 @@ begin
end;
{ TSQLTransaction }
procedure TSQLTransaction.SetActive(Value : boolean);
begin
if FActive and (not Value) then
EndTransaction
else if (not FActive) and Value then
if csLoading in ComponentState then
begin
FOpenAfterRead := true;
exit;
end
else
StartTransaction;
end;
procedure TSQLTransaction.Loaded;
begin
inherited;
if FOpenAfterRead then SetActive(true);
end;
procedure TSQLTransaction.EndTransaction;
begin
@ -310,35 +282,35 @@ end;
procedure TSQLTransaction.Commit;
begin
if not FActive then Exit;
checkactive;
closedatasets;
if (Database as tsqlconnection).commit(FTrans) then
begin
FActive := false;
FTrans.free;
closeTrans;
FreeAndNil(FTrans);
end;
end;
procedure TSQLTransaction.CommitRetaining;
begin
if not FActive then Exit;
CheckActive;
(Database as tsqlconnection).commitRetaining(FTrans);
end;
procedure TSQLTransaction.Rollback;
begin
if not FActive then Exit;
CheckActive;
closedatasets;
if (Database as tsqlconnection).RollBack(FTrans) then
begin
FActive := false;
FTrans.free;
CloseTrans;
FreeAndNil(FTrans);
end;
end;
procedure TSQLTransaction.RollbackRetaining;
begin
if not FActive then Exit;
CheckActive;
(Database as tsqlconnection).RollBackRetaining(FTrans);
end;
@ -359,7 +331,7 @@ begin
Db.Open;
if not assigned(FTrans) then FTrans := Db.AllocateTransactionHandle;
if Db.StartdbTransaction(FTrans) then FActive := true;
if Db.StartdbTransaction(FTrans) then OpenTrans;
end;
constructor TSQLTransaction.Create(AOwner : TComponent);
@ -393,7 +365,7 @@ begin
if assigned(FCursor) then
begin
(Database as tsqlconnection).FreeStatement(FCursor);
FCursor.free;
FreeAndNil(FCursor);
end;
end;
@ -415,7 +387,7 @@ begin
sqltr := (transaction as tsqltransaction);
if not sqltr.Active then sqltr.StartTransaction;
if assigned(fcursor) then FCursor.free;
if assigned(fcursor) then FreeAndNil(fcursor);
FCursor := Db.AllocateCursorHandle;
for x := 0 to FSQL.Count - 1 do
@ -501,7 +473,7 @@ begin
if DefaultFields then
DestroyFields;
FIsEOF := False;
FRecordSize := 0;
// FRecordSize := 0;
FOpen:=False;
inherited internalclose;
end;
@ -595,7 +567,7 @@ destructor TSQLQuery.Destroy;
begin
if Active then Close;
// if assigned(FCursor) then FCursor.destroy;
FSQL.Free;
FreeAndNil(FSQL);
inherited Destroy;
end;
@ -658,7 +630,36 @@ end.
{
$Log$
Revision 1.6 2004-10-27 07:23:13 michael
Revision 1.7 2004-11-05 08:32:02 michael
TBufDataset.inc:
- replaced Freemem by Reallocmem, Free by FreeAndNil
Database.inc:
- Moved Active property from TSQLTransaction to TDBTransaction
- Gives an error if the database of an active transaction is changed
Dataset.inc
- Don't distribute events if FDisableControlsCount > 0
- Replaced FActive by FState<>dsInactive
- Set EOF after append
db.pp:
- Removed duplicate definition of TAlignment
- Moved Active property from TSQLTransaction to TDBTransaction
- Replaced FActive by FState<>dsInactive
- Gives an error if the database of an active transaction is changed
sqldb:
- Moved Active property from TSQLTransaction to TDBTransaction
- replaced Freemem by Reallocmem, Free by FreeAndNil
IBConnection:
- Moved FSQLDAAllocated to the cursor
PQConnection:
- Don't try to free the statement if a fatal error occured
Revision 1.6 2004/10/27 07:23:13 michael
+ Patch from Joost Van der Sluis to fix transactions
Revision 1.5 2004/10/10 14:45:52 michael