Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2004-08

Access violation with IndexName property of TDbf

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Tony Maro

I'm not sure if this is a TDbf issue, or an FPC db issue, so I'm posting both places. I'm using CVS of FPC from about 1 hour ago.

Basically, whatever I do, if I try to set the "IndexName" or "IndexFieldNames" property of the TDbf I get an access violation.

Here's a sample:

var
   MyDbf: TDbf;
begin
  MyDbf := TDbf.Create(nil);
  MyDbf.FilePath := 'data/';
  { we want to use Visual dBase VII compatible tables }
  MyDbf.TableLevel := 7;
  MyDbf.Exclusive := True;
  MyDbf.TableName := 'customers.dbf';
  With MyDbf.FieldDefs do begin
   Add('Id', ftAutoInc, 0, True);
   Add('Name', ftString, 80, True);
  End;
  MyDbf.CreateTable;
  MyDbf.Open;
  MyDbf.AddIndex('custid', 'Id', [ixPrimary, ixUnique]);
  MyDbf.AddIndex('custname.ndx','Name', [ixCaseInsensitive]);
  MyDbf.Close;
  MyDbf.Free;
  MessageDlg('Created.', mtInformation,[mbOk],0);
  MyDBF := TDBf.Create(nil);
  MyDBF.FilePath := 'data/';
  MyDBF.TableLevel := 25;
  MyDBF.TableName := 'customers.dbf';
  MyDBF.Open;
  MyDBF.OpenIndexFile('custname.ndx');
  MyDBF.IndexName := 'custname';
  //MyDBF.IndexFieldNames := 'Name';   // doesn't work either
  //MyDBF.IndexName := 'custid'; // doesn't work EITHER...
  MyDbf.Close;
end;

And the obligatory backtrace:
(gdb) run
Starting program: /home/tony/Projects/testcrash/project1

Program received signal SIGSEGV, Segmentation fault. 0x0806a29c in DBF_TDBF_$__GETRECORD$PCHAR$TGETMODE$BOOLEAN () (gdb) bt full
#0 0x0806a29c in DBF_TDBF_$__GETRECORD$PCHAR$TGETMODE$BOOLEAN () No symbol table info available.
#1 0x08070de8 in DB_TDATASET_$__RESYNC$TRESYNCMODE () No symbol table info available.
#2 0x0806b252 in DBF_TDBF_$__RESYNC$TRESYNCMODE () No symbol table info available.
#3 0x0806cf63 in DBF_TDBF_$__SETINDEXNAME$ANSISTRING () No symbol table info available.
#4 0x0816dd29 in TFORM1__BUTTON1CLICK (SENDER=0x40440ea8, this=0x4043eae8) at unit1.pas:59
MYDBF = (TDBF *) 0x4057c014
#5 0x08102158 in TCONTROL__CLICK (this=0x40440ea8) at control.inc:1813 No locals.
#6 0x080d6b25 in TBUTTONCONTROL__CLICK (this=0x40440ea8) at buttoncontrol.inc:51
No locals.
#7 0x080ca201 in TCUSTOMBUTTON__CLICK (this=0x40440ea8) at buttons.inc:187 FORM = (TCUSTOMFORM *) 0x0
#8 0x080ca220 in TCUSTOMBUTTON__WMDEFAULTCLICKED (MESSAGE= {MSG = 1031, WPARAM = -1073746528, LPARAM = 26, RESULT = 1075674240, WPARA MLO = 60832, WPARAMHI = 49151, LPARAMLO = 26, LPARAMHI = 0, RESULTLO = 31872, RE SULTHI = 16413}, this=0x40440ea8) at buttons.inc:199
No locals.

Reply by email

Tony Maro
to Tony Maro
Tony Maro wrote 5 lines
I'm not sure if this is a TDbf issue, or an FPC db issue, so I'm posting both places. I'm using CVS of FPC from about 1 hour ago. Basically, whatever I do, if I try to set the "IndexName" or "IndexFieldNames" property of the TDbf I get an access violation.

Found it...

This only occurs if there are no records yet. Here's why:

On or about dataset.inc: 1582
If (GetRecord(Fbuffers[FRecordCount-1],gmcurrent,True)grOk) and

Think of what happens if there's no records. It passes:

GetRecord(FBuffers[-1],...

Access Violation.

Don't ask me the proper way to fix it though.

-Tony Maro

Reply by email

Michael Van Canneyt
to Tony Maro
Tony Maro wrote 23 lines
Tony Maro wrote: > I'm not sure if this is a TDbf issue, or an FPC db issue, so I'm > posting both places. I'm using CVS of FPC from about 1 hour ago. > > Basically, whatever I do, if I try to set the "IndexName" or > "IndexFieldNames" property of the TDbf I get an access violation. Found it... This only occurs if there are no records yet. Here's why: On or about dataset.inc: 1582 If (GetRecord(Fbuffers[FRecordCount-1],gmcurrent,True)grOk) and Think of what happens if there's no records. It passes: GetRecord(FBuffers[-1],... Access Violation. Don't ask me the proper way to fix it though.

Seems like a lot of people are doing double work here :-)

I already had a fix for this from Micha Nelissen, but it hasn't been committed yet. Tonight I plan to commit all remaining patches.

But I'm afraid this is not yet the end of it. The TDataset buffering mechanism needs some serious work done... If I'm correct, Joost Van Der Sluis (?) also wanted to do some work on it.

Michael.

Reply by email

Joost van der Sluis
to Michael Van Canneyt
Seems like a lot of people are doing double work here :-)

Yep...

I already had a fix for this from Micha Nelissen, but it hasn't been committed yet. Tonight I plan to commit all remaining patches.

A Small IRC-Log:

--------
<neli>
http://www.freepascal.org/cgi-bin/viewcvs.cgi/fpc/fcl/db/dataset.inc.diff?r1=1.13&r2=1.14 [09:43] <neli> it was fixed at that time
[09:44] <TonyMaro> MMm....
[09:44] <neli>
http://www.freepascal.org/cgi-bin/viewcvs.cgi/fpc/fcl/db/dataset.inc.diff?r1=1.14&r2=1.15 [09:44] <neli> and it was "unfixed" at that time
--------

My fault. I had no internet connection at that time, so when i sent in the patch, i 'undid' Micha Nelissen his patch.

But that can be easilly resolved by applying Micha's patch again.

Joost van der Sluis.

Reply by email

Joost van der Sluis
to Michael Van Canneyt: Seems like a lot of people are doing double work here :-) I already had a fix for this…

Ok,

i've had it with the TDataset Buffers.

They work now but not as they should, resync is buggy and it's not very Delphi-compatible.

The main issue here is that there's no difference between TDataset and TClientDataset. In the FCL they are somewhat combined.

So i suggest that I try to re-style TDataset and add TClientDataset. TDataset with a buffer of 10 records as it is now, and a TClientDataset which buffers all records.

Also i want to implement the resync and refresh methods as they are in the interbase components of Delphi.

tDbf would be a descendent of TDataset and TIbQuery of TClientDataset.

But i want to suggest than no-one else touches TDataset until i'm done. To avoid double work.

Joost van der Sluis.

Reply by email

Michael Van Canneyt
to Joost van der Sluis
Joost van der Sluis wrote
Ok, i've had it with the TDataset Buffers.

:-) Join the club.

They work now but not as they should, resync is buggy and it's not very Delphi-compatible.

Well. It was modeled to be compatible with D3 code.

The main issue here is that there's no difference between TDataset and TClientDataset. In the FCL they are somewhat combined.

Not really, why ?

So i suggest that I try to re-style TDataset and add TClientDataset. TDataset with a buffer of 10 records as it is now, and a TClientDataset which buffers all records.

Stop. The 10 buffers are the default. Controls such as TDBGrid can increase the number of buffers so that the minimum number of buffers needed to draw the control are always in memory.

I.e. if the grid has 25 rows, then 25 buffers must be present at all times. That is why the buffer count must be variable.

Also i want to implement the resync and refresh methods as they are in the interbase components of Delphi.

And how is this ?

tDbf would be a descendent of TDataset and TIbQuery of TClientDataset.

Fine, this is what I suggested you do.

But: Don't call it TClientDataset, call it TBufDataset as I suggested. TClientDataset is MUCH more than just additional buffers:

It handles Delta's (buffered updates), local storage to file, additional indexing, aggregate fields, internal calc fields etc.

But i want to suggest than no-one else touches TDataset until i'm done. To avoid double work.

I have no problem with that. I want to apply one more patch tonight (for resync), and as of tomorrow, you may assume you have complete control over TDataset.

If you want, mail me in private to discuss some more. I have some additional ideas which I wanted to implement to make writing TDataset descendents more easy, while keeping the current TDataset. As it is now, it is quite cumbersome.

Michael.

Reply by email