#1 2015-09-02 10:21:01

turrican
Member
From: Barcelona
Registered: 2015-06-05
Posts: 94
Website

Bug? with TObjectList<T>(TSQLRestServerDB.RetrieveList())

Hi,

TObjectList<T>(TSQLRestServerDB.RetrieveList()) seems broken (or I don't know to invoke these) .

This code fails :

uses
  System.SysUtils,
  mormot,
  mORMotSQLite3,
  mORMotDB,
  System.Generics.Collections,
  synsqlite3static;

type

  TUser = class(TSQLRecord)
    private
      fname: UTF8String;
      fgroupid: TID;
    published
      property IDGroup: TID read fgroupid write fgroupid;
      property Name: UTF8String read fname write fname;
  end;


var
  fSQLContext: TSQLRestServerDB;
  userlist: TObjectList<TUser>;
  user: TUser;
begin
  try
    { TODO -oUser -cConsole Main : Insert code here }
    fSQLContext:=TSQLRestServerDB.Create(TSQLModel.Create([TUser], 'root'),'prueba.db3');
    fSQLContext.CreateMissingTables;
    for user in TObjectList<TUser>(fSQLContext.RetrieveList(TUser, 'IDGroup=?', [4])) do
    begin
      writeln(user.Name);
    end;
    readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

This don't :

uses
  System.SysUtils,
  mormot,
  mORMotSQLite3,
  mORMotDB,
  System.Contnrs,
  synsqlite3static;

type

  TUser = class(TSQLRecord)
    private
      fname: UTF8String;
      fgroupid: TID;
    published
      property IDGroup: TID read fgroupid write fgroupid;
      property Name: UTF8String read fname write fname;
  end;


var
  fSQLContext: TSQLRestServerDB;
  user: Pointer;
begin
  try
    { TODO -oUser -cConsole Main : Insert code here }
    fSQLContext:=TSQLRestServerDB.Create(TSQLModel.Create([TUser], 'root'),'prueba.db3');
    fSQLContext.CreateMissingTables;
    for user in TObjectList(fSQLContext.RetrieveList(TUser, 'IDGroup=?', [4])) do
    begin
      writeln(TUser(user).Name);
    end;
    readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Offline

#2 2015-09-02 15:24:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Bug? with TObjectList<T>(TSQLRestServerDB.RetrieveList())

How does it fail?

Did you investigate a little?

Offline

#3 2015-09-02 15:46:55

turrican
Member
From: Barcelona
Registered: 2015-06-05
Posts: 94
Website

Re: Bug? with TObjectList<T>(TSQLRestServerDB.RetrieveList())

Source : Delphi XE8 Using Generics

Case : RetrieveList() returns nil list. Access violation while iterate list.

Inside code : Investigating a little I see the next method :

function TSQLRest.RetrieveList<T>(const FormatSQLWhere: RawUTF8; const BoundsSQLWhere: array of const; const aCustomFieldsCSV: RawUTF8): TObjectList<T>;

innacessible due a not defined constant in the compiler conditional :

{$ifdef ISDELPHI2010} 

So, the compiler calls another method instead

function RetrieveList(Table: TSQLRecordClass; const FieldNames, SQLWhere: string; const BoundsSQLWhere: array of const): TObjectList;

I don't know why this constant isn't defined in XE8...

Last edited by turrican (2015-09-02 15:47:36)

Offline

#4 2015-09-02 16:06:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Bug? with TObjectList<T>(TSQLRestServerDB.RetrieveList())

In Synopse.inc, there is:

    {$if CompilerVersion >= 21.0}
      {$define ISDELPHI2010}

So the conditional should be defined...

Offline

#5 2015-09-02 20:03:55

turrican
Member
From: Barcelona
Registered: 2015-06-05
Posts: 94
Website

Re: Bug? with TObjectList<T>(TSQLRestServerDB.RetrieveList())

Thanks, sorry for the inconveniences.

Offline

Board footer

Powered by FluxBB