#1 Re: mORMot 1 » UpdateField and WHERE clause » 2022-03-07 08:55:05

Had considered that approach but since there could be many affected records, 624 in one case of the DB I am currently working with have not proceeded. Have resolved by using the Execute method and inserting the SQL, works exactly as I need.

Thanks for a great product.

#2 Re: mORMot 1 » UpdateField and WHERE clause » 2022-03-07 02:11:25

Have determined only one field may be in the Where expression in both 1.18 and 2. Handy if all records with a single condition are to be changed however I need to have multiple conditions so will revert to CreateAndFillPrepare and loop through the selected results. Was hoping UpdateField would handle multiple conditions as it would be so much faster than looping.

Have also determined that the Where condition does not need the >=? either it just needs the field name.

implementation of UpdateField with arrays starts with:

  if (length(FieldValue)<>1) or (WhereFieldName='') or (length(WhereFieldValue)<>1) then
    exit;

#3 Re: mORMot 1 » UpdateField and WHERE clause » 2022-03-06 22:04:43

Many thanks for your assistance. Am currently running 1.18 so will update to Mormot2 if more than 1 fields not supported.

#4 mORMot 1 » UpdateField and WHERE clause » 2022-03-06 04:47:28

Chate
Replies: 7

Am trying to implement UpdateField on selected records in an SQLLite database. Have selected the required records with CreateAndFillPrepare then use the result, as a TSQLRecordClass, to Update a single field on many records.

The result is that all records in the DB are changed rather than just the ones selected. The declaration advises "Update one field in one or several members, depending on a WHERE clause".

May I ask how I insert that WHERE clause so the UpdateField works the way I want it to?

var
linksSelected: TSQLRecord;

.........

linksSelected :=
  LinkMstr.CreateAndFillPrepare(ORM_Database, '(' +
  ORMFLINKS_LINKLEVEL + '>=? AND ' + ORMFLINKS_LINKTGT + '>=?)',
  [minlevel, minID]);

  ORM_Database.UpdateField(linksSelected.RecordClass,
    ORMFLINKS_URFLAGS, 0, ORMFLINKS_URFLAGS, 1);


Mormot declaration
function UpdateField(Table: TSQLRecordClass; const WhereFieldName: RawUTF8; const WhereFieldValue: array of const; const FieldName: RawUTF8; const FieldValue: array of const): boolean; overload; virtual;
Update one field in one or several members, depending on a WHERE clause

Board footer

Powered by FluxBB