Results 1 to 6 of 6

Thread: SQL Question

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default SQL Question

    Hi,

    I'm trying to open a connection to a DB.
    This DB has two tables that I want to query some information.
    My question is: Have I to make two connections using two "QSqlDatabase" opening the same DB but different table?

    Second question is: I have created a ODBC driver (I'm using Windows), when opening the ODBC driver,where have I to tell it the name of the driver?

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQL Question

    Quote Originally Posted by ^NyAw^ View Post
    This DB has two tables that I want to query some information.
    My question is: Have I to make two connections using two "QSqlDatabase" opening the same DB but different table?
    You don't need the second connection, unless you want to have concurrent transactions.

    Quote Originally Posted by ^NyAw^ View Post
    Second question is: I have created a ODBC driver (I'm using Windows), when opening the ODBC driver,where have I to tell it the name of the driver?
    In the setDatabaseName():
    Qt Code:
    1. db = QSqlDatabase::addDatabase("QODBC");
    2. db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb");
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SQL Question

    Hi,

    Thanks, I have understood it now.

    Do anyone knows if using Microsoft SQL 2005, the connections are permanent? So if not, is a good way to maintain them opened by using a QTimer that query something every X seconds?

    Thanks,
    Òscar Llarch i Galán

  4. #4
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SQL Question

    Hi,

    I have another question:

    I have a connection to a SQL Server using ODBC:
    Qt Code:
    1. m_qBD = QSqlDatabase::addDatabase("QODBC","database1");
    2. m_qBD.setHostName("localhost");
    3. m_qBD.setDatabaseName("SQLServerODBC"); //Name of the ODBC driver that I have created
    4. m_qBD.setUserName("user");
    5. m_qBD.setPassword("passwd");
    To copy to clipboard, switch view to plain text mode 

    The DBServer have 2 Databases ("db1" and "db2").
    The "db1" have 2 tables "table1" and "table2".
    The "table1" has a filed called "field1".

    How I get the information of the "field1"?
    My problem is that the connection to the server is done, but don't how to open the Database "db1".

    Thanks,
    Òscar Llarch i Galán

  5. #5
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SQL Question

    Hi,

    On creation of ODBC driver there is an option to select the default Database to be used.

    So I created 2 drivers, one for each Database.

    Thanks,
    Òscar Llarch i Galán

  6. #6
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SQL Question

    Hi,

    Finally found the correct way:
    When want to make a query you can tell wich database and table want to query:
    Qt Code:
    1. QString qQuery("select * from database1.table1");
    To copy to clipboard, switch view to plain text mode 
    So, don't need to create 2 drivers
    Òscar Llarch i Galán

Similar Threads

  1. Questions regarding setting up a Qt SQL Model/View
    By Methedrine in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2007, 10:26
  2. Poor performance with Qt 4.3 and Microsoft SQL Server
    By Korgen in forum Qt Programming
    Replies: 2
    Last Post: 23rd November 2007, 11:28
  3. Can I use the Sql Module without chanage .pro file?
    By fengtian.we in forum Qt Programming
    Replies: 9
    Last Post: 21st May 2007, 11:59
  4. Replies: 1
    Last Post: 15th March 2007, 21:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.