#1 2016-08-31 18:48:17

AOG
Member
Registered: 2014-02-24
Posts: 447

TvPlanit wiith the mORMot

@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

#2 2016-08-31 19:57:27

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 11,695
Website

Re: TvPlanit wiith the mORMot

Nice!
smile

Offline

#3 2016-09-01 05:53:59

AOG
Member
Registered: 2014-02-24
Posts: 447

Re: TvPlanit wiith the mORMot

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

#4 2016-09-01 08:17:25

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 11,695
Website

Re: TvPlanit wiith the mORMot

Offline

#5 2016-09-01 09:25:49

AOG
Member
Registered: 2014-02-24
Posts: 447

Re: TvPlanit wiith the mORMot

@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

Board footer

Powered by FluxBB