Results 1 to 5 of 5

Thread: Best practice to pass parameters to a QSqlQueryModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2013
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 2 Times in 2 Posts

    Default Re: Best practice to pass parameters to a QSqlQueryModel

    I think there is only 2 ways to perform a QSqlQuery anyways, you either use either.

    Qt Code:
    1. QString name = "John";
    2. QString lastname = "Smith";
    3.  
    4. QString sql = "SELECT * FROM people WHERE Name = '" + name + "' AND LastName = '" + lastname + "'";
    5. QSqlQuery.exec(sql);
    To copy to clipboard, switch view to plain text mode 
    or
    you can prepare a statement then exec it..
    Qt Code:
    1. QSqlQuery.prepare("SELECT * FROM people WHERE Name = :name and LastName = :lastname);
    2. QSqlQuery.bindValue(":name", name);
    3. QSqlQuery.bindValue(":lastname", lastname);
    4. QSqlQuery.exec();
    To copy to clipboard, switch view to plain text mode 

    Note* Please correct me if there is another way, but this gets the job done for me.
    I only use Prepare statements when inserting data other than text, like QByteArray / Data.
    Last edited by zerokewl; 7th September 2013 at 12:16.

  2. The following user says thank you to zerokewl for this useful post:

    toufic.dbouk (7th September 2013)

Similar Threads

  1. How to pass parameters to a .ui file in Qt?
    By TheIndependentAquarius in forum Qt Programming
    Replies: 7
    Last Post: 21st August 2012, 10:28
  2. Replies: 2
    Last Post: 12th June 2010, 02:21
  3. Replies: 4
    Last Post: 3rd May 2009, 18:32
  4. what's the better practice?
    By xyzt in forum Qt Programming
    Replies: 1
    Last Post: 22nd March 2008, 18:42
  5. Replies: 2
    Last Post: 16th August 2007, 00:20

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
  •  
Qt is a trademark of The Qt Company.