You are not logged in.
Pages: 1
UpdateFrom method will not update RowCount if passed json content is empty.
Here is an example:
TempTable := TSQLTableJSON.Create('', '[{Field1:"Test"}, {Field1:"Test2"}]');
TempTable.UpdateFrom('[]', Refreshed, nil);
Offline
> It returns an error in this case, so RowCount is not set.
I understand that, but isn't that an error? I think it should replace previous content, but it exits and previous content is kept.
Consider this:
1) TempTable := TSQLTableJSON.Create('', '[]');
2) TempTable.UpdateFrom('[{Field1:"Test"}, {Field1:"Test2"}]'', Refreshed, nil);
3) TempTable.UpdateFrom('[]', Refreshed, nil);
1) TempTable is empty
2) TempTable has two rows
3) TempTable has two rows (same content from 2)
Last edited by igors233 (2016-05-19 11:25:21)
Offline
The content is expected to come from a mORMot server, which would never return '[]' but the field names, in non-expanded JSON format.
It is easy in your code to check for '[]' as input, if you need another behavior.
If you need to parse some JSON input, use TDocVariantData or the other JSON serialization of class or record/arrays of the framework.
Offline
> The content is expected to come from a mORMot server, which would never return '[]' but the field names, in non-expanded JSON format.
That does sounds like the way I'm using it, I have TSQLRecord that I:
1) create with CreateAndFillPrepare (that returns some records)
2) that FillTable is transferred to created TSQLTableJSON and it's content is filled with SQlRecord.FillTable.GetJSONValues(True).
3) TSQLTableJSON is associated with TSQLTableToGrid
4) User changes some (where) conditions which in effect calls SQlRecord.FillPrepare
5) Results are feed back to same TSQLTableJSON and retrieved in same way (SQlRecord.FillTable.GetJSONValues(True))
if FillPrepare returns no results, then GetJsonValues(True), returns [], if I use GetJsonValues(False) then {"FieldCount":0} is returned but it has same effect on UpdateFrom, RowCount is not changed.
> It is easy in your code to check for '[]' as input, if you need another behavior.
I know, but I think this is inconsistent/confusing behaviour, if you pass to UpdateFrom an emptycontent, no matter how you got it (ORM, interface service, local code) it should reflect that there are no records.
I do know I can create every time TSQLTableJSON and TSQLTableToGrid but
1) I don't like to destroy/allocate objects if it's not necessary
2) it looses column, sort and fields setting (that user has changed) so I need to add additional code to restore it every time
Offline
Pages: 1