You are not logged in.
Pages: 1
@all.
For TvPlanit, a new datastore was made, based on the mORMot.
Just for the fun of it ... ;-)
Source:
https://github.com/LongDirtyAnimAlf/mORMotTvPlanit
Release:
https://github.com/LongDirtyAnimAlf/mOR … es/tag/1.0
Lazarus forum:
http://forum.lazarus.freepascal.org/ind … 20583.html
Offline
You're welcome.
Question: would it be an idea to include the (below) simple locate code into TSynSQLTableDataSet ?
TSynSQLTableDataSetWithLocate = class(TSynSQLTableDataSet)
public
function Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions) : boolean; override;
end;
function TSynSQLTableDataSetWithLocate.Locate(const KeyFields: string;
const KeyValues: Variant; Options: TLocateOptions): boolean;
function SearchForField(const aLookupFieldName:RawUTF8;aLookupValue:variant):boolean;
var
f,r: integer;
begin
result:=false;
f := Table.FieldIndex(aLookupFieldName);
if (f<0) then exit;
r := Table.SearchFieldEquals(VariantToString(aLookupValue),f);
result:=(r>0);
if result then RecNo:=r;
end;
var
i, l, h : Integer;
FieldList: TList;
begin
Result := inherited;
CheckActive;
if IsEmpty then exit;
Result:=True;
if VarIsArray(KeyValues) then
begin
FieldList := TList.Create;
try
GetFieldList(FieldList, KeyFields);
l := VarArrayLowBound(KeyValues, 1);
h := VarArrayHighBound(KeyValues, 1);
if (FieldList.Count = 1) and (l < h) then
begin
if SearchForField(KeyFields,KeyValues) then exit;
end
else for i := 0 to FieldList.Count - 1 do
begin
if SearchForField(TField(FieldList[i]).FieldName,KeyValues[l+i]) then exit;
end;
finally
FieldList.Free;
end;
end else
if SearchForField(KeyFields,KeyValues) then exit;
Result:=False;
end;
Offline
Please test http://synopse.info/fossil/info/80838cee2c
Offline
@Ab
Thanks ! Looks to be working as expected.
Another addition (delete) that would be nice, but I am very unsure about the correctness of my code.
I am using it, looks to be working, but doubts remain. Be you the judge !
procedure TSynSQLTableDataSet.Delete;
begin
CheckActive;
if IsEmpty then exit;
if State in [dsInsert] then
begin
Cancel;
end else begin
DataEvent(deCheckBrowseMode,0);
DoBeforeDelete;
DoBeforeScroll;
Table.DeleteRow(RecNo);
SetState(dsBrowse);
Resync([]);
DoAfterDelete;
DoAfterScroll;
end;
end;
Offline
Pages: 1