Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

SQLQuery Like problem



  • The following query give the expected result from DBBrowser for SQLite

    select ident, name, laty, lonx, state, country from airport where scenery_local_path like '%FOLDER NAME%' order by country, state ;
    

    With QT SQLQuery and C++, the following code

    quAddOns->prepare("select ident, name, laty, lonx, state, country from airport  where scenery_local_path like :AddOn order by :Sort ;")
    
     quAddOns->bindValue(":AddOn", "%FOLDER NAME%");
     quAddOns->bindValue(":Sort", "country, state" );
    
     quAddOns-exec();
    

    gives the correct number of result but don't sort !
    If I modify (without the :Sort bind value)

    quAddOns->prepare("select ident, name, laty, lonx, state, country from airport  where scenery_local_path like :AddOn order by country, state")
    

    gives the expected sorted results !

    If I try to insert single quote (as with DB Browser) or double quote, either inside the prepare string or in the value to bind, the result exec() is empty (but no error).

    I don't understand what I am doing wrong :(
    Suggestions are VERY welcome...

    Thanks


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    To the best of my knowledge, bind parameters doesn't apply to elements of the query like sort.

    That one you'll have to build the string with it.



  • @SGaist

    My bad ! I did not think to check the docs on that point !

    A big thanks
    Gérard


Log in to reply