#1 2018-04-26 11:47:14

ASiwon
Member
From: Poland
Registered: 2015-01-30
Posts: 82

TableRowCount overloaded version

Hello,

is it possible to add to TSQLRest class new, overloaded version of TableRowCount function? In some cases I want to get count of rows in table which meets additional conditions. For my needs I made new version of TableRowCount function:

function TSQLRest.TableRowCount(Table: TSQLRecordClass; WhereClause: RawUTF8): Int64;
var T: TSQLTableJSON;
begin
  if (self=nil) or (Table=nil) then
    T := nil else
    T := ExecuteList([Table], Model.Props[Table].SQLFromSelectWhere('Count(*)', WhereClause));
  if T<>nil then
  try
    Result := T.GetAsInt64(1,0);
  finally
    T.Free;
  end else
    Result := -1;
end;

standard TableRowCount function could be changed to:

function TSQLRest.TableRowCount(Table: TSQLRecordClass): Int64;
begin
  Result := TableRowCount(Table, '');
end;

declarations for both functions could be:

    /// get the row count of a specified table
    // - returns -1 on error
    // - returns the row count of the table on success
    // - calls internaly the "SELECT Count(*) FROM TableName;" SQL statement
    function TableRowCount(Table: TSQLRecordClass): Int64; overload; virtual;
    /// get the row count of a specified table with additional where condition clause
    // - returns -1 on error
    // - returns the row count of the table matching where clause on success
    // - calls internaly the "SELECT Count(*) FROM TableName WHERE WhereClause;" SQL statement
    function TableRowCount(Table: TSQLRecordClass; WhereClause: RawUTF8): Int64; overload;

If this is possible please add this change to the mORMot source.


best regards
Adam Siwon

Offline

#2 2018-04-26 14:42:39

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: TableRowCount overloaded version

agreed.


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#3 2018-04-26 16:08:13

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

Re: TableRowCount overloaded version

It won't work with TSQLRestServerFullMemory.

Offline

#4 2018-04-28 20:43:55

ASiwon
Member
From: Poland
Registered: 2015-01-30
Posts: 82

Re: TableRowCount overloaded version

Hello,

could you explain it better? Maybe I'm working with older version of mORMot but for me this function work with TSQLRestServerFullMemory correctly. Of course it highly depends on condition in the where query section which is processed in TSQLRestStorageInMemory.EngineList function. If EngineList could correctly processes SQL query then function returns correct values. If not function returns as expected value -1. For simple conditions like PropertyName=Value it returns expected values.


best regards
Adam Siwon

Offline

Board footer

Powered by FluxBB