Lazarus

Programming => Databases => Topic started by: Landslyde on May 31, 2018, 03:27:43 pm

Title: [SOLVED] Too Many Database Components?
Post by: Landslyde 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:
That works perfectly.
On the second form, I added (yet again):
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
Title: Re: Too Many Database Components?
Post by: af0815 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.
Title: Re: Too Many Database Components?
Post by: Landslyde 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.
Title: Re: Too Many Database Components?
Post by: af0815 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.

 
Title: Re: Too Many Database Components?
Post by: Landslyde on May 31, 2018, 04:39:34 pm
Thank you for your very clear answer, af0815. You've helped me a lot. Thanks.
Title: Re: [SOLVED] Too Many Database Components?
Post by: mangakissa on June 01, 2018, 08:56:10 am
look at the demo I attached
Title: Re: [SOLVED] Too Many Database Components?
Post by: Landslyde 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.
Title: Re: [SOLVED] Too Many Database Components?
Post by: mangakissa 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
Title: Re: [SOLVED] Too Many Database Components?
Post by: Landslyde 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.
Title: Re: [SOLVED] Too Many Database Components?
Post by: taazz 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.
Title: Re: [SOLVED] Too Many Database Components?
Post by: Landslyde on June 02, 2018, 03:01:37 am
Hi taazz. Here's the needed files. Sorry about that  :D