#1 mORMot 2 » TOrmTableDataSet.Locate multi-field value positioning » 2024-11-16 03:43:58

newsxy
Replies: 2

Hello!

I am using the TOrmTableDataSet.Locate method to locate records. When I specify a single field, it can correctly locate the record row. However, when I specify two fields for locating, it cannot correctly locate the record row.

Section    Ident
alipay      alipay_mchid
alipay      alipay_paymentrate

The following two lines of code both return True, and RecNo is always 1:

ds.Locate('Section;Ident', VararrayOf([Alipay, Alipay_MchId]), [loCaseInsensitive]);
ds.Locate('Section;Ident', VararrayOf([Alipay, Alipay_PaymentRate]), [loCaseInsensitive]);


I looked at the following code, and it seems that if the value of the first field matches successfully, it considers the location successful and does not proceed to compare the value of the second field. Shouldn't it be that both field values must match successfully for the location to be considered successful?

function TVirtualDataSet.Locate(const KeyFields: string;
  const KeyValues: variant; Options: TLocateOptions): boolean;
...
      found := SearchForField(StringToUtf8(KeyFields), KeyValues, Options);
      if found > 0 then
      begin
        RecNo := found;
        exit;
      end;
...

If there is no issue with the above code, how should I correctly locate records using multiple field values? Thank you!

Board footer

Powered by FluxBB