Recent

Author Topic: DBGrid causes Segmentation Fault  (Read 6323 times)

r.lukasiak

  • Full Member
  • ***
  • Posts: 138
DBGrid causes Segmentation Fault
« on: February 05, 2018, 06:28:53 am »
Hi everybody!

I'm using Lazarus 1.8.0 on Gentoo Linux.
I'm making some app using SQLdb and Postgresql. I put DBGrid on the form, execute simple query like SELECT * FROM Table and Run the app, DBGrid shows results but whenever I touch it (scroll up/down, click on any row) I get
Code: Pascal  [Select][+][-]
  1. Project app raised exception class 'External: SIGSEGV'.
Few months ago I was making the same on Lazarus 1.6.4 and everything was fine. When I open the old app on 1.8.0, everything is ok. When I open the new app on 1.6.4, I get the same problem. Only app made from 0 on 1.6.4 doesn't cause any problems.
I also tried Lazarus 1.8.0 with Ubuntu, with the same problem. It looks like the 1.8.0 version is a problem, but I can't figure out why.
Has anyone had this issue? Any clues?

greetings,
Robert

Paul Reeves

  • New member
  • *
  • Posts: 8
Re: DBGrid causes Segmentation Fault
« Reply #1 on: February 18, 2019, 03:06:01 pm »
I'm running into the same problem with 1.8.4 on opensuse leap 42.3

Anyone got any ideas on how to fix this?

zeljko

  • Hero Member
  • *****
  • Posts: 1591
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: DBGrid causes Segmentation Fault
« Reply #2 on: February 18, 2019, 03:15:40 pm »
Anyone tested with 2.0 or trunk ?

Paul Reeves

  • New member
  • *
  • Posts: 8
Re: DBGrid causes Segmentation Fault
« Reply #3 on: February 18, 2019, 05:32:00 pm »
I just tried with 2.0.0. Same problem.

It is fairly vanilla code - just a button to connect to the db and execute a query.

The components are just an ibconnection, sqltransaction, sqlquery, datasource and dbgrid, all hooked up with default settings. The query executes fine. I can move from column to column on the first row, but as soon as I try to leave the first row with either the mouse or the keyboard - Wham! app disappears.

Paul Reeves

  • New member
  • *
  • Posts: 8
Re: DBGrid causes Segmentation Fault
« Reply #4 on: February 18, 2019, 09:54:05 pm »
I tried the same code under windows with Lazarus 2.0 with yet again the same results.

In the assembler window I have this:

00000001001FD136 e865fdffff               callq  0x1001fcea0 <DB$_$TDATASOURCE_$__$$_DISTRIBUTEEVENT$TDATAEVENT$INT64>

which seems to be called in procedure

  TDataSource.ProcessEvent(Event : TDataEvent; Info : Ptrint);

but the debugger doesn't actually stop on a line of code.

I set breakpoints on the three calls to ProcessEvent and none of them get hit.


Paul Reeves

  • New member
  • *
  • Posts: 8
Re: DBGrid causes Segmentation Fault
« Reply #5 on: February 20, 2019, 03:04:53 pm »
Nevermind. I replaced the SQLdb components with UIB and the grid worked fine.

It looks as if the problem is in the interaction between SQLdb and either the TDataset or TDatasource.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: DBGrid causes Segmentation Fault
« Reply #6 on: February 20, 2019, 05:32:37 pm »
Nevermind. I replaced the SQLdb components with UIB and the grid worked fine.
It looks as if the problem is in the interaction between SQLdb and either the TDataset or TDatasource.
SQLdb components are much more used by Free Pascal and Lazarus audience than UIB's.
We'd appreciate if you could provide a small sample with the error for a future bug report.

Paul Reeves

  • New member
  • *
  • Posts: 8
Re: DBGrid causes Segmentation Fault
« Reply #7 on: February 21, 2019, 01:37:00 pm »
I don't do much visual development with Lazarus (it is usually non-gui based stuff), so I chose the SQLDB components precisely because they were already available. I didn't want to go to the trouble of installing UIB as an additional package.

Anyway, I've attached the app. It is very simple. The only requirement is that there needs to be one additional connection to the database, perhaps by isql, or flamerobin or whatever.

As I mentioned previously, after changing the components for the UIB equivalents everything 'just works'. It is possible that I might have changed some obscure setting while changing the components, but even then, the app should not crash when using SQLDB.


Paul

Soner

  • Sr. Member
  • ****
  • Posts: 305
Re: DBGrid causes Segmentation Fault
« Reply #8 on: February 21, 2019, 04:24:38 pm »
Now It tested it with my example application and with new application created with Lazarus 2. There is no problem.
My system:
Lazarus 2.0.1.r60452 (Lazarus 2.0-fixes)
fpc 3.0.4-64Bit
Windows 10 Pro 64 Bit
Firebird 2.5 64Bit

Then I tested with Paul Reeves example and it crashed with stackoverflow when i clicked in the dbgrid.
@Paul Reeves
I replaced your database with fb-example employee db and deactivated timer to look if timer cause this problem.

I upload my example that works on my computer, created with Lazarus from above.
I uses fb-employee database.
you need to define the alias in firebird configuration file from firebird folder, something like that:
employee = C:\Progs\Firebird_2_5-x64\examples\empbuild\EMPLOYEE.FDB

or set:
IBConnection1.DatabaseName:=C:\Progs\Firebird_2_5-x64\examples\empbuild\EMPLOYEE.FDB

Don't forget to enter here your fb-path.

« Last Edit: February 21, 2019, 04:27:06 pm by Soner »

Paul Reeves

  • New member
  • *
  • Posts: 8
Re: DBGrid causes Segmentation Fault
« Reply #9 on: February 22, 2019, 02:00:57 pm »
I disabled the timer on my version. Segfault.

I took a look at your sample. You used a different query. So I changed my query to the simplest possible - 'select * from mytable' against a table with just ten records. Segfault.

So there we have it. On my setup using SQLDb, I get a segfault whenver I click somewhere on a dbgrid. Switching components to UIB doesn't cause this crash.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: DBGrid causes Segmentation Fault
« Reply #10 on: February 22, 2019, 10:01:23 pm »
I don't do much visual development with Lazarus (it is usually non-gui based stuff), so I chose the SQLDB components precisely because they were already available. I didn't want to go to the trouble of installing UIB as an additional package.

Anyway, I've attached the app. It is very simple. The only requirement is that there needs to be one additional connection to the database, perhaps by isql, or flamerobin or whatever.

As I mentioned previously, after changing the components for the UIB equivalents everything 'just works'. It is possible that I might have changed some obscure setting while changing the components, but even then, the app should not crash when using SQLDB.
I can confirm the issue.

I have opened a bug report:
0035137: DBGrid causes Segmentation Fault (SQLdb with Firebird)
https://bugs.freepascal.org/view.php?id=35137

Soner

  • Sr. Member
  • ****
  • Posts: 305
Re: DBGrid causes Segmentation Fault
« Reply #11 on: February 23, 2019, 02:13:22 pm »
@Paul Reeves
Now, I know why your example crash and my example not.
Set in your example SqlQuery.DataSource property empty and your example works, without crash.

I am not using SQLDB-Components but I think this property is for something else.

Soner

  • Sr. Member
  • ****
  • Posts: 305
Re: DBGrid causes Segmentation Fault
« Reply #12 on: February 23, 2019, 02:22:12 pm »
In delphi documentations says TQuery.Datasource is for reading the paramater values from other dataset, but you set here same datasource and the result is stackerror.
i can't explain it good with my poor english read delphi doc then you understand it better.
There is nothing in Lazarus/Fpc/-documentation about this property.

Edit:
Sorry, you can read in fpc documentation same:
https://www.freepascal.org/docs-html/fcl/db/tdataset.datasource.html

I think there is no bug, is it using error.
« Last Edit: February 23, 2019, 02:25:40 pm by Soner »

Paul Reeves

  • New member
  • *
  • Posts: 8
Re: DBGrid causes Segmentation Fault
« Reply #13 on: February 23, 2019, 05:34:54 pm »
Thanks - you are correct. The query.datasource property should not be set in this instance. That is definitely my mistake. I haven't done any gui based db development in years.

But I think this is a bug anyway. The app is just blown out of the water. It is impossible to debug this problem, otherwise I would have done so.

If there is a circular reference between the query object and the datasource that should be caught, perhaps at design time, shouldn't it? I'm trying to imagine how that could be a feature, especially in this case when the original query takes no parameters.

Soner

  • Sr. Member
  • ****
  • Posts: 305
Re: DBGrid causes Segmentation Fault
« Reply #14 on: February 23, 2019, 08:42:06 pm »
But I think this is a bug anyway. The app is just blown out of the water. It is impossible to debug this problem, otherwise I would have done so.
You can debug lcl (lazarus-libs) or fcl (fp-libs) when you compile lazarus and fpc in development mode.
Sqldb-components belongs to fcl so you need to recompile fcl also in debug mode.
You can also compile all lcl-libraries, that  required from your application when you add -gw2  to projects custom options.
look at screenshot.


If there is a circular reference between the query object and the datasource that should be caught, perhaps at design time, shouldn't it? I'm trying to imagine how that could be a feature, especially in this case when the original query takes no parameters.
It is for TSQLQuery impossible to detect if the datasource component is for results or for paramater values.
I think to many controls make a system slow, it is good how it is.
Sometimes it is good to read the documentation especially for the functions you are using.

When you use db-components with form designer, then never forget to set active property for connections and querries to false before saving. Maybe the user have their databases in other folders and in this case they get at application start exception.

good luck.

 

TinyPortal © 2005-2018