Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlQuery bug? Prepared statement with LIKE and wildcards
Forum Updated to NodeBB v4.3 + New Features

QSqlQuery bug? Prepared statement with LIKE and wildcards

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zerby
    wrote on last edited by
    #1

    Hello,

    I'm pretty sure I've found a bug in QSqlQuery, when using a prepared statement with LIKE, and binding a value to it with double wildcards (%). The first execution of the query returns proper results, but the second one always fails to return anything, eventhough the value bindings are idenctical.

    Example:

    @
    QSqlQuery testQuery(db);
    std::cout << "PREPARE: " << testQuery.prepare("SELECT product_id FROM products WHERE name LIKE :name") << std::endl;

    testQuery.bindValue(":name", "%Test%");
    
    std::cout << "EXEC: " << testQuery.exec&#40;&#41;;
    std::cout << " NEXT: " << testQuery.next(&#41; << std::endl;
    
    testQuery.bindValue(":name", "%Test%"&#41;;
    
    std::cout << "EXEC: " << testQuery.exec&#40;&#41;;
    std::cout << " NEXT: " << testQuery.next(&#41; << std::endl;
    

    @

    This always returns:

    @
    PREPARE: 1
    EXEC: 1 NEXT: 1
    EXEC: 1 NEXT: 0
    @

    Which shows that the prepare goes fine, and both times the exec call is successfull, but the second time no results are fetched, even though the queries are identical! Even if you comment out the second bindValue, the second exec call still returns no rows.

    EDIT: Also, if I run the code with no wildcards (%), both times the next() call returns true, so it seems indeed QSqlQuery has a bug when using double wildcards with bindValue.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved