Mysql and PB queries
Posted: Tue Nov 17, 2015 12:18 pm
I would like to confirm but it seems to me that it is not possible to have 2 active queries, or more, for the same database connection.
Thank you.
Thank you.
http://www.purebasic.com
https://www.purebasic.fr/english/
Considering the fact that this has absolutely nothing to do with PB...Lima wrote:Considering the fact that PB has this limitation I ask if there's any info on what will be new in the next version.
AFAIK, this is basically the essential issue with most database drivers. There are algorithms and procedures to mitigate such behavior, though, depending which one in particular you use.Multiple threads cannot send a query to the MySQL server at the same time on the same connection
Code: Select all
; First, connect to a database with an employee table
;
If DatabaseQuery(#Database, "SELECT code,name FROM Tableauthors") ; Get all the records in the 'authors' table
While NextDatabaseRow(#Database) ; Loop for each records
Debug GetDatabaseString(#Database, 0) ; Display the content of the first field (Code)
; At this point I want the books that this author wrote
; I need
DatabaseQuery(#Database, "SELECT books FROM TableBooks where code="="+GetDatabaseString(#Database, 0))
While NextDatabaseRow(#Database)
Debug GetDatabaseString(#Database, 0)
Wend
; I use this in another language
Wend
FinishDatabaseQuery(#Database)
I understand what you require. First of all, be advised there is no native PB support for MySQL .Lima wrote:What is written is not possible in PB. The example is only to illustrate
Lima wrote:Code: Select all
; First, connect to a database with an employee table ; If DatabaseQuery(#Database, "SELECT code,name FROM Tableauthors") ; Get all the records in the 'authors' table While NextDatabaseRow(#Database) ; Loop for each records Debug GetDatabaseString(#Database, 0) ; Display the content of the first field (Code) ; At this point I want the books that this author wrote ; I need DatabaseQuery(#Database, "SELECT books FROM TableBooks where code="="+GetDatabaseString(#Database, 0)) While NextDatabaseRow(#Database) Debug GetDatabaseString(#Database, 0) Wend ; I use this in another language Wend FinishDatabaseQuery(#Database)
What is written is not possible in PB. The example is only to illustrate
Thank you
EndIf
Code: Select all
DBQuery1=OpenDatabase(#PB_Any, blah blah)
DBQuery2=OpenDatabase(#PB_Any, blah blah)
If DatabaseQuery(#DBQuery1, "SELECT code,name FROM Tableauthors") ; Get all the records in the 'authors' table
While NextDatabaseRow(#DBQuery1) ; Loop for each records
Debug GetDatabaseString(#DBQuery1, 0) ; Display the content of the first field (Code)
; At this point I want the books that this author wrote
; I need
DatabaseQuery(#DBQuery2, "SELECT books FROM TableBooks where code="="+GetDatabaseString(#DBQuery1, 0))
While NextDatabaseRow(#DBQuery2)
Debug GetDatabaseString(#DBQuery2, 0)
Wend
FinishDatabaseQuery(#DBQuery2)
Wend
FinishDatabaseQuery(#DBQuery1)
Code: Select all
SELECT Tablebooks.books AS books, Tableauthors.authors as authors FROM Tablebooks
LEFT JOIN Tableauthors ON Tablebooks.auid = Tableauthors.auid AND (Tablebooks.genre = 'war' )
WHERE ( Tableauthors.status = 'alive' AND Tablebooks.type = 'new')