You are not logged in.
Pages: 1
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
agreed.
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
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
Pages: 1