Recent

Author Topic: DBGrid error  (Read 4716 times)

mmelwin

  • New Member
  • *
  • Posts: 23
DBGrid error
« on: June 11, 2021, 07:31:36 am »
When I click on DBGrid while running a Locate on SQLQuery, the DBGrid crashes. Can I prevent this somehow? Disable / EnableControls doesn't help. I am attaching two screenshots, before and after Locate.

Handoko

  • Hero Member
  • *****
  • Posts: 4331
  • My goal: build my own game engine using Lazarus
Re: DBGrid error
« Reply #1 on: June 11, 2021, 08:31:17 am »
Only some screenshots does not help much. We need more information. Please provide more information to help us help you.

Version of the software (OS, Lazarus, database, etc) and steps to reproduce the issue. It will be extremely helpful if you can provide the compile-able source code, so we can inspect and debug it on our computer. If you're not willing to publicize the project, you can write a short demo that can let us to reproduce the problem.

You can use the Publish Project feature in the IDE:
Lazarus main menu > Project > Publish project

Or manually select and include the files:
Create a new folder, copy and paste all the necessary files (including the data file) except: the binary (exe file), *.bak, lib and backup folders. Compress the folder and send the zip to the forum.

mmelwin

  • New Member
  • *
  • Posts: 23
Re: DBGrid error
« Reply #2 on: June 11, 2021, 08:41:21 am »
Lazarus 2.0.12, FPC 3.2.0, OS Win10, PostgreSQL 13. I will prepare a demo.

mmelwin

  • New Member
  • *
  • Posts: 23
Re: DBGrid error
« Reply #3 on: June 11, 2021, 10:44:28 am »
Please click "Populate", wait a while, click "Locate" and quickly click in the DBGrid area.

The problem only occurs when the searched field is sorted descending.

For ease of use, the demo uses SQLite.

dseligo

  • Sr. Member
  • ****
  • Posts: 344
Re: DBGrid error
« Reply #4 on: June 11, 2021, 12:20:59 pm »
I tried your example and I can confirm the problem.

I then tried with ZeosDBO components and it works, but maybe because it locates row before I have a chance to click DBGrid.

Test project with ZeosDBO components is attached if you want to try it.

Handoko

  • Hero Member
  • *****
  • Posts: 4331
  • My goal: build my own game engine using Lazarus
Re: DBGrid error
« Reply #5 on: June 11, 2021, 12:30:33 pm »
I tested DEMO.7Z on Ubuntu Mate 20.10 using Lazarus 2.0.10 64-bit, could not reproduce the problem.

mmelwin

  • New Member
  • *
  • Posts: 23
Re: DBGrid error
« Reply #6 on: June 11, 2021, 02:28:15 pm »
I tried your example and I can confirm the problem.

I then tried with ZeosDBO components and it works, but maybe because it locates row before I have a chance to click DBGrid.

Test project with ZeosDBO components is attached if you want to try it.

Didn't you have a chance to click on DBGrid. Locate in Zeos is very fast because it loads the entire query result at once. SQLdb only loads the first few lines.

mmelwin

  • New Member
  • *
  • Posts: 23
Re: DBGrid error
« Reply #7 on: June 18, 2021, 07:41:14 am »
I still don't know how to prevent it. I don't want to switch to ZeosDBO.

Soner

  • Sr. Member
  • ****
  • Posts: 252
Re: DBGrid error
« Reply #8 on: June 18, 2021, 08:36:19 am »
I still don't know how to prevent it. I don't want to switch to ZeosDBO.
ZEOS loads all Data once, SQLDB didn't. As I said in other topic your program has no error.
But you can still force SQLDB loading all data once like in ZEOS, move the cursor after activating query to the last row:
Code: Pascal  [Select][+][-]
  1.  SQLQuery1.Active:=True;
  2.  SQLQuery1.Last;             // <--- ADD this line
  3.  

Edit:
Don't forget it can take a long time to load 400mb over the network especially when the network is bussy.
« Last Edit: June 18, 2021, 08:39:25 am by Soner »

mmelwin

  • New Member
  • *
  • Posts: 23
Re: DBGrid error
« Reply #9 on: June 18, 2021, 08:49:04 am »
I think I've found the problem. Out of memory.
Everything is fine after compiling to x64.
I just need to find some other solution, because I have several computers with Win XP 32bit :(

Handoko

  • Hero Member
  • *****
  • Posts: 4331
  • My goal: build my own game engine using Lazarus
Re: DBGrid error
« Reply #10 on: June 18, 2021, 03:03:12 pm »
I just need to find some other solution ...

I currently write a database program using Firebird. I need it to be more fault tolerance.

So the program should not open, use and share a single connection for the whole runtime. When needed, for example user clicks a button, it automatically creates and sets a database connection, runs the query, then closes and frees the connection immediately. It keeps the connection active as short as possible, if something bad happens the chances to 'damage' the database becomes lower.

For that reason, it cannot use TDBGrid. Instead it uses TStringGrid. For showing the data on the grid, it connects to the database, runs a query to read 20 items and closes the connection immediately. The form has a previous page and next page buttons. And you need to manually keep which page number is currently showing.

I tested the concept using some generated data (50k records), it seemed to work correctly and there wasn't any noticeable performance impact. Maybe you can use the trick, by loading only a small amount of the data (a page), it should use very little amount of memory.
« Last Edit: June 18, 2021, 06:18:29 pm by Handoko »

 

TinyPortal © 2005-2018