#1 2022-07-13 15:05:21

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

TRestServerDB.orm.OneFieldValues needs RowID instead of ID

mormot.orm.rest, line 1154

    T := ExecuteList([Table], SqlFromSelect(Table.SqlTableName,
      'ID,' + FieldName, WhereClause, ''));

When using a TrestServerDB the ID needs to be RowID, and as it is now it returns an error
if instead of TrestServerDB, the procedure OneFieldValues  runs from a TRestStorageInMemory then the ID is OK

I have noticed it in other functions too: TRestStorageInMemory behaves differently with the RowID/ID that the TrestServerDB, both RowID and ID are accepted in TRestStorageInMemory but thιs is not allowed for TrestServerDB. TrestServerDB returns an error for ID and works only with RowID.

Last edited by dcoun (2022-07-13 15:06:17)

Offline

#2 2022-07-14 05:23:39

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 210

Re: TRestServerDB.orm.OneFieldValues needs RowID instead of ID

Isn't this just based on what the chosen database uses for the primary indexed column name in every table? For example, if you're using sqlite then yes you need to use RowID because that's the name of the indexed column, and you only have to do that anyway (AFAIK) if you bypass the ORM layer.

Last edited by pvn0 (2022-07-14 05:24:15)

Offline

#3 2022-07-14 06:44:40

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Re: TRestServerDB.orm.OneFieldValues needs RowID instead of ID

In the above situation, the "ID" exists in the mormot2's code and it does not work with any external database that uses sqlite as medium.
RowID works for both as I tested.

Offline

#4 2022-07-16 08:10:32

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Re: TRestServerDB.orm.OneFieldValues needs RowID instead of ID

By curiosity only:
Does the following function work for you, when using sqlite/TRestStorageInMemory database without the above correction(RowID instead of ID in line 1154 of mormot.orm.rest)?

    function OneFieldValues(Table: TOrmClass; const FieldName, WhereClause:  RawUtf8; Strings: TStrings; IDToIndex: PID = nil): boolean; overload;

Thank you in advance

Last edited by dcoun (2022-07-16 08:11:14)

Offline

#5 2022-07-16 08:30:09

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

Re: TRestServerDB.orm.OneFieldValues needs RowID instead of ID

Please try https://github.com/synopse/mORMot2/commit/22a51995

Note that this issue was passed under the radar: it was 'ID' even on mORMot 1 since years.
I guess this TStrings-oriented method was not very often used. smile

Offline

#6 2022-07-16 10:49:20

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Re: TRestServerDB.orm.OneFieldValues needs RowID instead of ID

Thank you @ab.
It is very helpful if using memory tables to fill automatically comboboxes even with using sqlite's operator || for combobox's options label
Just a line of code for each combo box

I just noticed that when using the operator || you have to named with 'AS' like in the following:

memserver.Orm.OneFieldValues(TOrmtable,'(code || " " || title) as title','SQL condition GROUP BY Rowid',list); 

And it fills RowID as Tobject too

Last edited by dcoun (2022-07-16 10:56:18)

Offline

Board footer

Powered by FluxBB