#1 2014-10-17 09:22:28

PEB
Member
Registered: 2014-10-17
Posts: 2

TSynBigTableRecord: tfoUnique problem

Hi,
Using a BigTableRecord file, created with a record whose property is 'tfoUnique', an error message appears when I try 'RecordAdd', on an already created file:

Error msg : "TSynTableFieldProperties.CheckConstraint call needed before mid.OrderdIndexUpdate"

Thanks a lot for any cue to fix this problem...

Sample code :

var
  Table: TSynBigTableRecord;
  rec1, rec2: TSynTableData;
begin
    // Creation of the disk file: ff.idx and adding of one record.
  Table := TSynBigTableRecord.Create('ff.idx','Table1');
  Table.AddField('name',tftUTF8,[tfoIndex]);
  Table.AddField('mid',tftInt32,[tfoIndex,tfoUnique]);
  Table.AddFieldUpdate;
  rec1.Init(Table.Table);
  rec1.Field['mid']:=1;
  rec1.Field['name']:='John';
  Table.RecordAdd(rec1);
  Table.UpdateToFile();
  Table.Free;

    // Opening of the same file for adding a second record
  Table := TSynBigTableRecord.Create('ff.idx','Table1');
  rec2.Init(Table.Table);
  rec2.Field['mid']:=2;
  rec2.Field['name']:='Jack';
  Table.RecordAdd(rec2); // -> Error arise here...
  Table.UpdateToFile();
  Table.Free;

  DeleteFile('D:\temp\ff.idx');

Offline

#2 2014-10-20 12:11:23

PEB
Member
Registered: 2014-10-17
Posts: 2

Re: TSynBigTableRecord: tfoUnique problem

Hello,
Without any solution to use tfoUnique I, temporarly, I delete option 'tfoUnique' and call a search to check for unique instance before adding a new record....

Have you any remarques about this choice ?

Thanks a lot for your great BigTable library...
PEB

Source :

var _prop: TSynTableFieldProperties;
    rec2: TSynTableData;
    _s: string;
    IDs: TIntegerDynArray;
    IDCount:integer;
begin
    //Table creation
  Table := TSynBigTableRecord.Create('ff.idx','Table1');
  Table.AddField('name',tftUTF8,[tfoIndex]);
  Table.AddField('mid',tftInt32,[tfoIndex]); // No explicite declaration of tfoUnique
  Table.AddFieldUpdate;
  rec1.Init(Table.Table);
  rec1.Field['mid']:=1;
  rec1.Field['name']:='John';
  Table.RecordAdd(rec1);
  Table.UpdateToFile();
  Table.Free;

    // Table edition
  Table := TSynBigTableRecord.Create('ff.idx','T1');
  try
    _prop := Table.Table['mid'];
    _prop.OrderedIndexNotSorted :=True;
    _prop.OrderedIndexRefresh;
    if not Table.Search(_prop, _prop.SBF(2), IDs, IDCount) // <-- Is there any instance of 'mid' = 2 ?
    then begin
      rec2.Init(Table.Table);
      rec2.Field['mid']:=2;
      rec2.Field['name']:='Jack';
      if Table.RecordAdd(rec2) = 0 then ShowMessage('Error on adding: 2, Jack');
    end
    else ShowMessage('Record with mid = 2 already exists...');
  finally
    Table.UpdateToFile();
    FreeAndNil(Table);
  end;
end;

Offline

#3 2019-11-18 20:45:37

gothbert
Member
Registered: 2017-11-08
Posts: 12

Re: TSynBigTableRecord: tfoUnique problem

Hi,

I am aware that I post a reply to a very old topic. Anyway, I have the same issue as the original poster.

In my case it is a simple table with three tftWinAnsi fields, one with a toUnique option. After initial creation of the table, all works fine. After restarting the program, adding a new record leads to the "TSynTableFieldProperties.CheckConstraint call needed before XXX.OrderedIndexUpdate" exception in TSynTableFieldProperties.OrderedIndexUpdate().

Obviously fOrderedIndexFindAdd did not get set. I have no clue what function to call prior to the OrderedIndexUpdate() to remedy this issue.

Any chance that there will be a fix for the issue?

I am happy to provide a minimal program to reproduce the exception if required.

Kind regards
Boris

Offline

Board footer

Powered by FluxBB