Results 1 to 3 of 3

Thread: qsqlquery interactive?

  1. #1
    Join Date
    Jul 2008
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default qsqlquery interactive?

    Hi!
    this time I'm struggling with queries in Qt.
    The problem is that I'm doing a program where the data to be received from the DB varies depending on what the user decides he needs.
    So I need to somehow make the SELECT-command interactive.
    So the thing is that my basic query look sth like this:

    SELECT ID FROM Table1 WHERE Name="bla1";

    but then it might be so that the query should look sth like

    SELECT ID FROM Table1 WHERE Name="bla1" INTERSECT
    SELECT ID FROM Table1 WHERE Name="bla2";

    or even like

    SELECT ID FROM Table1 WHERE Name="bla1" INTERSECT
    SELECT ID FROM Table1 WHERE Name="bla2" INTERSECT
    SELECT ID FROM Table1 WHERE Name="bla3" ;

    etc.

    it depends on what the user decides, so he can say I'm interested on the answer depending on the name being bla1, bla2 and bla3 etc.

    so is there a way to do this in Qt?
    so I know that in query.exec() one must state a query in advance.

    I hope I made myself somehow clear?
    thanks for any help

  2. #2
    Join Date
    Aug 2007
    Location
    Fresno - Colombia
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qsqlquery interactive?

    Use:

    Qt Code:
    1. query.prepare("SELECT ID FROM Table1 WHERE Name=:name");
    2. query.bindValue(":name", Widget->text());
    3. query.exec();
    To copy to clipboard, switch view to plain text mode 

    where Widget->text() is the control you have the text you need, for example a comboBox or a LineEdit.

    You must read the documentation.

  3. #3
    Join Date
    Jul 2008
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qsqlquery interactive?

    right, I meant sth different still, but I'll just manipulate the query using a string.
    I just thought there might be some kind of a function like
    Qt Code:
    1. QSqlQuery::intersect (QList<QSqlQuery>)
    To copy to clipboard, switch view to plain text mode 
    anyway thanks for answering!
    cheers
    Last edited by lamera; 7th September 2008 at 10:48.

Similar Threads

  1. QSqlQuery and QLineEdit
    By GuL in forum Newbie
    Replies: 25
    Last Post: 15th August 2008, 13:40
  2. QSqlQuery problem
    By MarkoSan in forum Qt Programming
    Replies: 11
    Last Post: 18th December 2007, 13:25
  3. QSqlQuery error
    By skuda in forum Qt Programming
    Replies: 2
    Last Post: 2nd November 2007, 08:43
  4. How can I get the number of columns in QSqlQuery.
    By fengtian.we in forum Qt Programming
    Replies: 1
    Last Post: 21st May 2007, 11:04
  5. Problems with QSqlQuery update
    By whoops.slo in forum Qt Programming
    Replies: 4
    Last Post: 28th August 2006, 07:17

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.