Results 1 to 10 of 10

Thread: Problem with QSqlQuery and the .arg of a QString[SOLVED]

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Problem with QSqlQuery and the .arg of a QString[SOLVED]

    Hello,

    The next code works perfectly:

    Qt Code:
    1. //Note: CSQLUsers::AL_PUPIL is "1", an intenger
    2.  
    3. QSqlQuery data(QString("SELECT id FROM users WHERE iaccesslevel=%1 AND sname = 'Alex' ") .arg(CSQLUsers::AL_PUPIL), *pointer_my_database->GetDBPtr());
    4.  
    5. bool test1 = data.first();
    6. bool test2 = data.isValid();
    7. bool test3 = data.isSelect();
    To copy to clipboard, switch view to plain text mode 

    But, when I try to use the arguments of QString (something that works with integers or other sort of variables)

    Qt Code:
    1. //Note: CSQLUsers::AL_PUPIL is "1", an intenger
    2.  
    3. QString name = 'Alex';
    4. QSqlQuery data(QString("SELECT id FROM users WHERE iaccesslevel=%1 AND sname = %2 ") .arg(CSQLUsers::AL_PUPIL) .arg(name), *pointer_my_database->GetDBPtr());
    5.  
    6. bool test1 = data.first();
    7. bool test2 = data.isValid();
    8. bool test3 = data.isSelect();
    To copy to clipboard, switch view to plain text mode 

    the three booleans are false... why? the argument should be converted to QString properly and call the SQL :S

    thanks!
    Last edited by jano_alex_es; 5th May 2009 at 11:13. Reason: add "[solved]"

Tags for this Thread

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.