More than one database query at a time

Just starting out? Need help? Post your questions and find answers here.
jcoleuk
User
User
Posts: 12
Joined: Mon Apr 18, 2005 5:20 pm
Location: UK

More than one database query at a time

Post by jcoleuk »

How can I do something like this:

Code: Select all

  If DatabaseQuery("SELECT...") = 0
    MessageRequester("Error", "DB ERROR: "+DatabaseError())
  Else
  
    While NextDatabaseRow()

      DatabaseQuery("SELECT...") = 0
      ; Second database query!
    
    Wend
    
  EndIf
I need to be able to run a query using data retrieved for each row of the first query, can this be done in PureB? I can do it in PHP.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1286
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

Open 2 instances to your database

Code: Select all

OpenDatabase(0,"myDatabase"...
OpenDatabase(1,"myDatabase"...

  UseDatabase(0)
  If DatabaseQuery("SELECT...") = 0
    MessageRequester("Error", "DB ERROR: "+DatabaseError())
    Else
 
    While NextDatabaseRow()
      UseDatabase(1)

      DatabaseQuery("SELECT...") = 0
      ; Second database query!

      UseDatabase(0)
    Wend
   
  EndIf 
Image Image
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Threads ..
Fred
Administrator
Administrator
Posts: 18406
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

With PB4, each database commands has a database number as well.
jcoleuk
User
User
Posts: 12
Joined: Mon Apr 18, 2005 5:20 pm
Location: UK

Post by jcoleuk »

Thanks Paul I used your method and it's worked great.

I'm a bit worried about the number of calls to the database I'm having to do, but I'll sort that out later.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1286
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

Are you not able to get the desired data by joining tables in your query?
jcoleuk
User
User
Posts: 12
Joined: Mon Apr 18, 2005 5:20 pm
Location: UK

Post by jcoleuk »

I know that it can be done, I just don't know how to do it, yet. But I'll work it out before I release my program.
Post Reply