Recent

Author Topic: [SOLVED] SQLDB Cannot add second record to SQLite table  (Read 2743 times)

Martin Lowry

  • New Member
  • *
  • Posts: 17
[SOLVED] SQLDB Cannot add second record to SQLite table
« on: March 05, 2022, 01:23:05 pm »
Hi,

For a few days now I've been struggling with this. I have a single record SQLite3 table linked to a form through a TSQLQuery and controlled using a TDBNavigator. When '+' is clicked on the navigator to add a second record the new record is created using TDataset.Insert and prepared for data entry. All goes well until it's time to Post the record. The app then crashes and breaks whilst updating the indices at TDoubleLinkedBufIndex.InsertRecordBeforeCurrentRecord() in BufDataset.pas at line 1916. It looks as though FCurrentRecBuf[IndNr].prior is undefined when perhaps it should be nil or a valid pointer. If instead I explicitly call TDataset.Append to create the record everything works and the record is successfully added to the table even though InsertRecordBeforeCurrentRecord() is still called. Can't see where the problem is but it seems that somewhere in the if ... else... or DoAppend subprocedure of TDataset.DoInsertAppend() the index records are not initialised correctly for Insert to succeed.

Yes, I now have a workaround but it's unfortunate that I have to build additional functionality instead of using a standard component. Can anybody explain what is happening and provide a fix?

Cheers!
« Last Edit: March 15, 2022, 12:28:14 am by Martin Lowry »

LacaK

  • Hero Member
  • *****
  • Posts: 703
Re: SQLDB Cannot add second record to SQLite table
« Reply #1 on: March 05, 2022, 05:28:22 pm »
Hi,
which version of Lazarus/Free Pascal so you use?
Can you provide small example project, which demonstrates this crash?

Martin Lowry

  • New Member
  • *
  • Posts: 17
Re: SQLDB Cannot add second record to SQLite table
« Reply #2 on: March 08, 2022, 10:04:44 pm »
Hi LacaK,
Hi,
which version of Lazarus/Free Pascal so you use?
Can you provide small example project, which demonstrates this crash?

Currently using Lazarus 2.0.10 (r63526) with FPC 3.2.0.
Trying to produce a demo but failing to reproduce the issue. Meanwhile it still persists in my application. At the bottom of the trace it halts in system.move with what looks to be an invalid non-nil source pointer. Don't know where to go next.


Zvoni

  • Hero Member
  • *****
  • Posts: 3365
Re: SQLDB Cannot add second record to SQLite table
« Reply #3 on: March 09, 2022, 08:09:30 am »
Try Append instead of Insert?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

LacaK

  • Hero Member
  • *****
  • Posts: 703
Re: SQLDB Cannot add second record to SQLite table
« Reply #4 on: March 09, 2022, 10:24:52 am »
Currently using Lazarus 2.0.10 (r63526) with FPC 3.2.0.
Trying to produce a demo but failing to reproduce the issue.
Can you try Lazarus 2.2.0 with FPC 3.2.2 ?
Without reproducible example there is less chance that bug will be fixed (if there is one)

Martin Lowry

  • New Member
  • *
  • Posts: 17
Re: SQLDB Cannot add second record to SQLite table
« Reply #5 on: March 09, 2022, 12:18:53 pm »
@Zvoni  Please re-read my initial post.

Zvoni

  • Hero Member
  • *****
  • Posts: 3365
Re: SQLDB Cannot add second record to SQLite table
« Reply #6 on: March 09, 2022, 01:31:54 pm »
@Zvoni  Please re-read my initial post.
Sorry, missed it in that wall of text
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Martin Lowry

  • New Member
  • *
  • Posts: 17
[SOLVED] SQLDB Cannot add second record to SQLite table
« Reply #7 on: March 14, 2022, 05:21:12 pm »
Hi,

Finally figured out what was happening. As predictable it was in my own code not FCL. I'd managed to make the final query field datasize greater than that in its associated FieldDef ultimately leading to the index buffer pointer being overwritten.

PS. How do I mark this as solved?


dseligo

  • Hero Member
  • *****
  • Posts: 1683
Re: [SOLVED] SQLDB Cannot add second record to SQLite table
« Reply #8 on: March 14, 2022, 06:03:38 pm »
PS. How do I mark this as solved?

Change subject of your first post - put '[SOLVED]' in front of it.

 

TinyPortal © 2005-2018