#1 2013-03-09 08:54:46

GetDB
Member
Registered: 2013-03-09
Posts: 1

A bug?

program Project1;
{$APPTYPE CONSOLE}
uses
  SysUtils,Windows
  , SynBigTable, SynCommons
  ;
var
  DB: TSynBigTableRecord;
  Rec: TSynTableData;
  i: Integer;
  FileName:string;
begin
  FileName:=ChangeFileExt(ParamStr(0), '.syn');
  DeleteFile(PChar( FileName));
  DB := TSynBigTableRecord.Create(FileName, 'Table');
  DB.AddField('Name', tftWinAnsi, [tfoIndex]);
  DB.AddField('Value', tftWinAnsi);
  DB.AddFieldUpdate;
  if DB.Count = 0 then
    for i := 1 to 50 do begin
      Rec.Init(db.Table);
      rec.Field['Name']:=Format( 'Name_%d',[i]);
      rec.Field['Value']:=format('Value%d',[i]);
      db.RecordAdd(Rec);
    end;
  db.Delete(1);
  DB.UpdateToFile();
  DB.free;
  
  DB := TSynBigTableRecord.Create(ChangeFileExt(ParamStr(0), '.syn'), 'Table');
  DB.free;

  writeln('OK');
  Readln;
end.

Is there something wrong?
this code raize an error。
if i change
DB.AddField('Name', tftWinAnsi, [tfoIndex]);
to
DB.AddField('Name', tftWinAnsi, []);
.
then there is no problem。

Last edited by GetDB (2013-03-09 09:06:35)

Offline

#2 2013-03-14 09:21:10

sh17
Member
Registered: 2011-08-09
Posts: 25

Re: A bug?

@ab
the exception throws here

---->        if OrderedIndex i>=OrderedIndexCount then

49 >= 49

constructor TSynTableFieldProperties.CreateFrom(var RD: TFileBufferReader);
var i: integer;
begin
  fOrderedIndexFindAdd := -1;
  RD.Read(Name);
  if not FieldNameValid(pointer(Name)) then
    RD.ErrorInvalidContent;
  RD.Read(@FieldType,SizeOf(FieldType));
  RD.Read(@Options,SizeOf(Options));
  if (FieldType>high(FieldType)) then
    RD.ErrorInvalidContent;
  OrderedIndexCount := RD.ReadVarUInt32Array(OrderedIndex);
  if OrderedIndexCount>0 then begin
    if tfoIndex in Options then begin
      SetLength(OrderedIndexReverse,OrderedIndexCount);
      for i := 0 to OrderedIndexCount-1 do
---->        if OrderedIndex[i]>=OrderedIndexCount then
          RD.ErrorInvalidContent else
          OrderedIndexReverse[OrderedIndex[i]] := i;
    end else
      RD.ErrorInvalidContent;
  end;
  // we allow a void OrderedIndex[] array from disk
end;

Offline

Board footer

Powered by FluxBB