mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-24 20:49:16 +02:00
+ Patch from Luiz Americo to improve Master/DEtail handling
git-svn-id: trunk@1464 -
This commit is contained in:
parent
5abb9d68f6
commit
e082117d31
@ -107,9 +107,8 @@ type
|
|||||||
function GetSqliteHandle: Pointer; virtual; abstract;
|
function GetSqliteHandle: Pointer; virtual; abstract;
|
||||||
function GetSqliteVersion: String; virtual; abstract;
|
function GetSqliteVersion: String; virtual; abstract;
|
||||||
procedure BuildLinkedList; virtual; abstract;
|
procedure BuildLinkedList; virtual; abstract;
|
||||||
function SqliteReturnString: String; virtual; abstract;
|
|
||||||
function TableExists: Boolean;virtual;abstract;
|
|
||||||
procedure DisposeLinkedList;
|
procedure DisposeLinkedList;
|
||||||
|
procedure SetDetailFilter;
|
||||||
procedure MasterChanged(Sender: TObject);
|
procedure MasterChanged(Sender: TObject);
|
||||||
procedure MasterDisabled(Sender: TObject);
|
procedure MasterDisabled(Sender: TObject);
|
||||||
procedure SetMasterFields(Value:String);
|
procedure SetMasterFields(Value:String);
|
||||||
@ -161,6 +160,8 @@ type
|
|||||||
function QuickQuery(const ASql:String;const AStrList: TStrings):String;overload;
|
function QuickQuery(const ASql:String;const AStrList: TStrings):String;overload;
|
||||||
function QuickQuery(const ASql:String;const AStrList: TStrings;FillObjects:Boolean):String;virtual;abstract;overload;
|
function QuickQuery(const ASql:String;const AStrList: TStrings;FillObjects:Boolean):String;virtual;abstract;overload;
|
||||||
procedure RefetchData;
|
procedure RefetchData;
|
||||||
|
function SqliteReturnString: String; virtual;abstract;
|
||||||
|
function TableExists: Boolean;virtual;abstract;
|
||||||
function UpdatesPending: Boolean;
|
function UpdatesPending: Boolean;
|
||||||
{$ifdef DEBUGACTIVEBUFFER}
|
{$ifdef DEBUGACTIVEBUFFER}
|
||||||
procedure SetCurrentItem(Value:PDataRecord);
|
procedure SetCurrentItem(Value:PDataRecord);
|
||||||
@ -488,7 +489,7 @@ begin
|
|||||||
FCurrentItem^.BookmarkFlag := bfCurrent;
|
FCurrentItem^.BookmarkFlag := bfCurrent;
|
||||||
end
|
end
|
||||||
else if (Result = grError) and DoCheck then
|
else if (Result = grError) and DoCheck then
|
||||||
DatabaseError('SqliteDs - No records',Self);
|
DatabaseError('No records found',Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomSqliteDataset.GetRecordCount: Integer;
|
function TCustomSqliteDataset.GetRecordCount: Integer;
|
||||||
@ -655,11 +656,8 @@ begin
|
|||||||
if MasterSource <> nil then
|
if MasterSource <> nil then
|
||||||
begin
|
begin
|
||||||
FSql := 'Select * from '+FTableName+';'; // forced to obtain all fields
|
FSql := 'Select * from '+FTableName+';'; // forced to obtain all fields
|
||||||
FMasterLink.FieldNames:=MasterFields; //this should fill MasterLinks.Fields
|
FMasterLink.FieldNames:=FMasterLink.FieldNames; //workaround to fill MasterLinks.Fields
|
||||||
//todo: ignore if Fields.Count = 0 (OnMasterChanged will not be called) or
|
//if FMasterLink.Fields.Count = 0 MasterChanged will not be called anyway so ignore it
|
||||||
// raise a error?
|
|
||||||
//if (FMasterLink.Fields.Count = 0) and (MasterSource.DataSet.Active) then
|
|
||||||
// DatabaseError('Master Fields are not defined correctly');
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
FSqliteHandle:=GetSqliteHandle;
|
FSqliteHandle:=GetSqliteHandle;
|
||||||
@ -673,8 +671,13 @@ begin
|
|||||||
BindFields(True);
|
BindFields(True);
|
||||||
|
|
||||||
UpdateIndexFields;
|
UpdateIndexFields;
|
||||||
if FMasterLink.Active and (FIndexFieldList.Count <> FMasterLink.Fields.Count) then
|
if FMasterLink.Active then
|
||||||
DatabaseError('MasterFields count doesnt match IndexFields count',Self);
|
begin
|
||||||
|
if FIndexFieldList.Count <> FMasterLink.Fields.Count then
|
||||||
|
DatabaseError('MasterFields count doesn''t match IndexFields count',Self);
|
||||||
|
//Set FSql considering MasterSource active record
|
||||||
|
SetDetailFilter;
|
||||||
|
end;
|
||||||
|
|
||||||
// Get PrimaryKeyNo if available
|
// Get PrimaryKeyNo if available
|
||||||
if Fields.FindField(FPrimaryKey) <> nil then
|
if Fields.FindField(FPrimaryKey) <> nil then
|
||||||
@ -858,7 +861,7 @@ end;
|
|||||||
|
|
||||||
// Specific functions
|
// Specific functions
|
||||||
|
|
||||||
procedure TCustomSqliteDataset.MasterChanged(Sender: TObject);
|
procedure TCustomSqliteDataset.SetDetailFilter;
|
||||||
function GetSqlStr(AField:TField):String;
|
function GetSqlStr(AField:TField):String;
|
||||||
begin
|
begin
|
||||||
case AField.DataType of
|
case AField.DataType of
|
||||||
@ -886,6 +889,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
FSql:='Select * from '+FTableName+AFilter;
|
FSql:='Select * from '+FTableName+AFilter;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomSqliteDataset.MasterChanged(Sender: TObject);
|
||||||
|
begin
|
||||||
|
SetDetailFilter;
|
||||||
{$ifdef DEBUG}
|
{$ifdef DEBUG}
|
||||||
writeln('Sql used to filter detail dataset:');
|
writeln('Sql used to filter detail dataset:');
|
||||||
writeln(FSql);
|
writeln(FSql);
|
||||||
@ -901,9 +909,13 @@ end;
|
|||||||
|
|
||||||
procedure TCustomSqliteDataset.SetMasterFields(Value: String);
|
procedure TCustomSqliteDataset.SetMasterFields(Value: String);
|
||||||
begin
|
begin
|
||||||
if Active then
|
|
||||||
DatabaseError('It''s not allowed to set MasterFields property in a open dataset',Self);
|
|
||||||
FMasterLink.FieldNames:=Value;
|
FMasterLink.FieldNames:=Value;
|
||||||
|
if Active and FMasterLink.Active then
|
||||||
|
begin
|
||||||
|
UpdateIndexFields;
|
||||||
|
if (FIndexFieldList.Count <> FMasterLink.Fields.Count) then
|
||||||
|
DatabaseError('MasterFields count doesn''t match IndexFields count',Self);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomSqliteDataset.GetMasterFields: String;
|
function TCustomSqliteDataset.GetMasterFields: String;
|
||||||
@ -914,9 +926,9 @@ end;
|
|||||||
|
|
||||||
procedure TCustomSqliteDataset.UpdateIndexFields;
|
procedure TCustomSqliteDataset.UpdateIndexFields;
|
||||||
begin
|
begin
|
||||||
|
FIndexFieldList.Clear;
|
||||||
if FIndexFieldNames <> '' then
|
if FIndexFieldNames <> '' then
|
||||||
begin
|
begin
|
||||||
FIndexFieldList.Clear;
|
|
||||||
try
|
try
|
||||||
GetFieldList(FIndexFieldList, FIndexFieldNames);
|
GetFieldList(FIndexFieldList, FIndexFieldNames);
|
||||||
except
|
except
|
||||||
@ -967,6 +979,11 @@ var
|
|||||||
CounterFields,CounterItems,StatementsCounter:Integer;
|
CounterFields,CounterItems,StatementsCounter:Integer;
|
||||||
SqlTemp,KeyName,ASqlLine,TemplateStr:String;
|
SqlTemp,KeyName,ASqlLine,TemplateStr:String;
|
||||||
begin
|
begin
|
||||||
|
if not UpdatesPending then
|
||||||
|
begin
|
||||||
|
Result:=True;
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
Result:=False;
|
Result:=False;
|
||||||
if (FPrimaryKeyNo <> -1) and not FSqlMode then
|
if (FPrimaryKeyNo <> -1) and not FSqlMode then
|
||||||
begin
|
begin
|
||||||
@ -980,8 +997,6 @@ begin
|
|||||||
WriteLn('PrimaryKeyNo: ',FPrimaryKeyNo);
|
WriteLn('PrimaryKeyNo: ',FPrimaryKeyNo);
|
||||||
{$endif}
|
{$endif}
|
||||||
SqlTemp:='BEGIN TRANSACTION;';
|
SqlTemp:='BEGIN TRANSACTION;';
|
||||||
// In some situations (LCL apps) FBeginItems is inserted in FUpdatedItems
|
|
||||||
FUpdatedItems.Remove(FBeginItem);
|
|
||||||
// Update changed records
|
// Update changed records
|
||||||
if FUpdatedItems.Count > 0 then
|
if FUpdatedItems.Count > 0 then
|
||||||
TemplateStr:='UPDATE '+FTableName+' SET ';
|
TemplateStr:='UPDATE '+FTableName+' SET ';
|
||||||
@ -1176,8 +1191,10 @@ end;
|
|||||||
|
|
||||||
function TCustomSqliteDataset.UpdatesPending: Boolean;
|
function TCustomSqliteDataset.UpdatesPending: Boolean;
|
||||||
begin
|
begin
|
||||||
Result:= (FDeletedItems.Count > 0) or
|
//Sometimes FBeginItem is inserted in FUpdatedItems
|
||||||
(FAddedItems.Count > 0) or (FUpdatedItems.Count > 0);
|
FUpdatedItems.Remove(FBeginItem);
|
||||||
|
Result:= (FUpdatedItems.Count > 0) or
|
||||||
|
(FAddedItems.Count > 0) or (FDeletedItems.Count > 0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomSqliteDataset.QuickQuery(const ASql:String):String;
|
function TCustomSqliteDataset.QuickQuery(const ASql:String):String;
|
||||||
|
Loading…
Reference in New Issue
Block a user