More than 1 Database Query open at a time

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
swhite
Enthusiast
Enthusiast
Posts: 798
Joined: Thu May 21, 2009 6:56 pm

More than 1 Database Query open at a time

Post by swhite »

Hi

It would be useful to have more than one database query open at a time.

Thanks,
Simon
Simon White
dCipher Computing
User avatar
TI-994A
Addict
Addict
Posts: 2740
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: More than 1 Database Query open at a time

Post by TI-994A »

swhite wrote: Sat Oct 12, 2024 5:56 pmIt would be useful to have more than one database query open at a time.
Hi Simon. Is it not possible to do so now?
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: More than 1 Database Query open at a time

Post by jacdelad »

DatabaseError() and some other commands don't have parameters so it's impossible to know which call caused an error.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
TI-994A
Addict
Addict
Posts: 2740
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: More than 1 Database Query open at a time

Post by TI-994A »

jacdelad wrote: Sun Oct 13, 2024 7:14 amDatabaseError() and some other commands don't have parameters so it's impossible to know which call caused an error.
The DatabaseError() function simply retrieves the last database error. This is usually implemented in error handling and would be directly associated with a database operation. So, it's not totally impossible to determine the affected database.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: More than 1 Database Query open at a time

Post by jacdelad »

...that's what I meant.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
TI-994A
Addict
Addict
Posts: 2740
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: More than 1 Database Query open at a time

Post by TI-994A »

jacdelad wrote: Sun Oct 13, 2024 7:31 am ...that's what I meant.

I thought you meant that it is impossible.

jacdelad wrote: Sun Oct 13, 2024 7:14 am DatabaseError() and some other commands don't have parameters so it's impossible to know which call caused an error.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: More than 1 Database Query open at a time

Post by jacdelad »

It is impossible, because you can't know which call caused the error (given you do multiple calls at once, threaded). Sure, it is technically possible but you will run into problems.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
TI-994A
Addict
Addict
Posts: 2740
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: More than 1 Database Query open at a time

Post by TI-994A »

jacdelad wrote: Sun Oct 13, 2024 8:42 amIt is impossible, because you can't know which call caused the error (given you do multiple calls at once, threaded). Sure, it is technically possible but you will run into problems.
It would be very unwise to access common database connections from separate threads. Each thread should have its own database connection, and as such, they should work independently of the others. With such models, the DatabaseError() issue would also work independently.

Furthermore, asynchronous database connections should consider many other factors, like transaction isolation and concurrency control. Best to keep database management basic. :wink:

Nevertheless, I believe that this feature request is for nested queries, and not for concurrent connections. :lol:
Last edited by TI-994A on Sun Oct 13, 2024 12:58 pm, edited 1 time in total.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
infratec
Always Here
Always Here
Posts: 7618
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: More than 1 Database Query open at a time

Post by infratec »

Normally this is not needed.

You can solve it in a 'better' SQL command.
If you can not ..., open a second connection to the database.
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: More than 1 Database Query open at a time

Post by jacdelad »

I tried with threads, but it didn't work reliable. Even with only one query in a thread, to not block the main loop, it wasn't satisfying.
Never thought about nested queries, because, like infrared wrote, it usually shouldn't be needed.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
swhite
Enthusiast
Enthusiast
Posts: 798
Joined: Thu May 21, 2009 6:56 pm

Re: More than 1 Database Query open at a time

Post by swhite »

It appears to me that only one query per connection is possible. I am use to opening a connection to a database but then being able to open several queries. So I assumed I could do the same in PB but that is not the case. There are times when looping through several queries is needed to update other tables. An SQL statement to do this can be quite complex and hard to test all the edge cases. It is often easier to open several queries instead. Having said that perhaps I have not understood PB database design. In such a scenario should I being opening multiple connections to the database so that each connection can have its own query? Usually I try to minimize the connections to a database so I never thought of doing it this way before.

Simon
Simon White
dCipher Computing
User avatar
NicTheQuick
Addict
Addict
Posts: 1519
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: More than 1 Database Query open at a time

Post by NicTheQuick »

Opening several database cursors and doing queries to data that will be used in another query is never a good idea. If other users use the same database at the same time this can lead to inconsistency.
When you are working with multiple data and you need a complex query or even multiple ones, always start a transaction on your single database cursor and do all your stuff within that transaction, in the end do a commit. Only this way the database is able to be consistent afterwards.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Post Reply