* * *

Author Topic: [SOLVED] Too Many Database Components?  (Read 1480 times)

Landslyde

  • Full Member
  • ***
  • Posts: 163
[SOLVED] Too Many Database Components?
« on: May 31, 2018, 03:27:43 pm »
I hate to bother everyone (again), but I'd rather ask before I start tearing apart a lot of work and messing stuff up.

I have two forms that use the same database. There will be several more by the time i finish, but just two for now.

On one form, the main one, I have three grids. On it I have:
  • 3 DataSources
  • 3 SQLQueries
  • 1 SQLite3Connection
  • 1 SQLTransaction
That works perfectly.
On the second form, I added (yet again):
  • 1 DataSource
  • 1 SQLQuery
  • 1 SQLite3Connection
  • 1 SQLTransaction
When I switch between forms, I'm finiding all of this is tangling up on me, causing the database to keep locking up. So when I started disconnecting them through code, my grids stopped displaying data until I clicked the Refresh button.

I don't need those other data components on the second form, right? I've already seen that, by adding the main form to the uses of the second form, I can access the main form's data components. Everything works right now, but the grids going blank is kinda ugly  :D
« Last Edit: May 31, 2018, 04:39:55 pm by Landslyde »
Linux Mint 19
Lazarus 1.8.4
FPC 3.0.4

af0815

  • Full Member
  • ***
  • Posts: 158
Re: Too Many Database Components?
« Reply #1 on: May 31, 2018, 03:54:14 pm »
Why 2 Connections and transaction ?

Put the connection and the transaction in a Datamodule (eg. spezialized Form) and connect the Queries on both forms to it.

If you use 2 connection it looks like 2 user for the DB and produce locking.
regards
Andreas

Landslyde

  • Full Member
  • ***
  • Posts: 163
Re: Too Many Database Components?
« Reply #2 on: May 31, 2018, 04:08:30 pm »
Why 2 Connections and transaction ?

Put the connection and the transaction in a Datamodule (eg. spezialized Form) and connect the Queries on both forms to it.

If you use 2 connection it looks like 2 user for the DB and produce locking.

So just pull off the connection and transaction and put them in a datamodule? I'll try that. I'd shied away from using a datamodule because it gave me a lot of trouble yesterday as I set up a Master/Detail configuration. That's why I stuck all my components on the main form. But when I started coding the second form earlier, I dropped the needed four components on it too. That's when things got goofy. I'll do as you said. Thanks a lot, af0815.
« Last Edit: May 31, 2018, 09:25:44 pm by Landslyde »
Linux Mint 19
Lazarus 1.8.4
FPC 3.0.4

af0815

  • Full Member
  • ***
  • Posts: 158
Re: Too Many Database Components?
« Reply #3 on: May 31, 2018, 04:28:05 pm »
Where the connection and the transaction reside is meaningless. Your trouble is, you build two connetions to the database. If you use differenet DB it is ok.

See https://stackoverflow.com/questions/10325683/can-i-read-and-write-to-a-sqlite-database-concurrently-from-multiple-connections for some explenation.
 
In short, for each sqlite-DB only one Connection/transaction. Normally there is no problem with a Datamodule, but it is only for non visual componnets. The second is, look for the right creation order of your forms (DM is like a form). I think your problem was the order of creating the forms. Normally problems coming if the Form with the visual components are created first and cannot bound to the later created components on the Datamodule.

 
regards
Andreas

Landslyde

  • Full Member
  • ***
  • Posts: 163
Re: Too Many Database Components?
« Reply #4 on: May 31, 2018, 04:39:34 pm »
Thank you for your very clear answer, af0815. You've helped me a lot. Thanks.
Linux Mint 19
Lazarus 1.8.4
FPC 3.0.4

mangakissa

  • Hero Member
  • *****
  • Posts: 829
Re: [SOLVED] Too Many Database Components?
« Reply #5 on: June 01, 2018, 08:56:10 am »
look at the demo I attached
Lazarus 1.84 (32b) / FPC 3.0.4
Windows 10

Landslyde

  • Full Member
  • ***
  • Posts: 163
Re: [SOLVED] Too Many Database Components?
« Reply #6 on: June 01, 2018, 03:59:38 pm »
Hi mangakissa. Thanks for sharing. What you showed me is what I've been trying to do for the past 2 or 3 days. Here are my efforts:

https://ufile.io/jfk1o

I cldn't put it here, even after removing the program file. I'm sure my work's crude compared to what most here can do, but I'm trying. The Edit page isn't wired up. The Financial side has nothing yet. This is something my girlfriend asked me to do for her. Take a look and tell me what and where I can improve on. I'm open to constructive criticism and good advice that'll further my knowledge and understanding.

Thanks.
Linux Mint 19
Lazarus 1.8.4
FPC 3.0.4

mangakissa

  • Hero Member
  • *****
  • Posts: 829
Re: [SOLVED] Too Many Database Components?
« Reply #7 on: June 01, 2018, 09:30:32 pm »
I can't download your file. But if you take only the *.pas, *.lfm and lpi file in a zip you can upload here to share it for other members
Lazarus 1.84 (32b) / FPC 3.0.4
Windows 10

Landslyde

  • Full Member
  • ***
  • Posts: 163
Re: [SOLVED] Too Many Database Components?
« Reply #8 on: June 01, 2018, 09:39:09 pm »
Here they are. Like I said, my work's crude compared to what most here can do. But it's a beginning  ;)

Comments and advice are welcome. Thanks.
« Last Edit: June 02, 2018, 03:02:03 am by Landslyde »
Linux Mint 19
Lazarus 1.8.4
FPC 3.0.4

taazz

  • Hero Member
  • *****
  • Posts: 5336
Re: [SOLVED] Too Many Database Components?
« Reply #9 on: June 02, 2018, 02:52:46 am »
Here they are. Like I said, my work's crude compared to what most here can do. But it's a beginning  ;)

Comments and advice are welcome. Thanks.
I'm going to take a closer look at your code later tonight. A fast observation, you did not include the project1.lpr file, not a big deal for this one, for now consider it just a FYI, this is a needed file, lpi on the other hand not so much.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Landslyde

  • Full Member
  • ***
  • Posts: 163
Re: [SOLVED] Too Many Database Components?
« Reply #10 on: June 02, 2018, 03:01:37 am »
Hi taazz. Here's the needed files. Sorry about that  :D
Linux Mint 19
Lazarus 1.8.4
FPC 3.0.4

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus