Results 1 to 2 of 2

Thread: Unable to return query using Mysql bindvalue

  1. #1
    Join Date
    Dec 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Unable to return query using Mysql bindvalue

    Hello. I am currently runnning MySql 3.23 and have been unable to get the bindvalue syntax to work in my code.

    Qt Code:
    1. q3.prepare("SELECT MONTH(date), avg(speed) AS aspeed"
    2. "FROM vehicle_data"
    3. "WHERE size = 2 AND YEAR(date) = ? AND Location = ?"
    4. "GROUP BY( MONTH(date))"
    5. "VALUES(?,?)"
    6. );
    7. q3.bindValue(2010);
    8. q3.bindValue(bob5)
    To copy to clipboard, switch view to plain text mode 

    The same qurry works fine if I simply use a prepare statement such as

    Qt Code:
    1. qBeforeDate = beforeDate.toString("'SELECT MONTH(date), avg(speed) AS aspeed FROM vehicle_data WHERE size=2 AND YEAR(date) = ' yyyy ' GROUP BY(MONTH(date))'");
    2. yearHold2 = qBeforeDate;
    3. q2.prepare(yearHold2);
    To copy to clipboard, switch view to plain text mode 

    However this solution is not enough as I need to allow the qurry to be flexable enough to accept a user entered string and time (the second code block uses toString to fetch the user's selected year in this case).

    Is bindvalue the right way to go for this? or do I need attempt this by a different method such as string appending ( which looked messy) or inserting the user string somehow into the statement?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Unable to return query using Mysql bindvalue

    Your queries are not the same. Notice the last "VALUES(?,?)" in your first (q3) query. Delete that and it will work.

Similar Threads

  1. QTSQLITE, prepared query and bindValue()
    By YaK in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2009, 20:13
  2. Unable to fetch data when searching through select query
    By sinha.ashish in forum Qt Programming
    Replies: 3
    Last Post: 10th April 2008, 15:06
  3. Select query using mysql for searching
    By sinha.ashish in forum Qt Programming
    Replies: 4
    Last Post: 10th April 2008, 07:14
  4. INSERT query with MySQL problem
    By timmyg in forum Qt Programming
    Replies: 10
    Last Post: 20th March 2008, 22:52
  5. Mysql query question
    By twells55555 in forum Qt Programming
    Replies: 1
    Last Post: 30th June 2007, 00:41

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.