QSqlQuery::isValid with MySql


  • Moderators

    I started to use MySql through Qt. In my table I have records which require update when some of the key numbers are already available in a relation. Therefore I have to use "CREATE" once and afterwards "UPDATE".

    With a query on "SELECT * FROM table WHERE VAL=..." I am checking the existance of the reocrd. I expected that the query would deliver with isValid() == true for existing extry, but the return value is always false. I can use the size statement, which shall be 1 then. However, is there a better way for checking?


  • Moderators

    @koahnig You need to call next() before isValid() returns true or not. You can also test the return value of next().

    And of course testing the size as you are doing works fine as well.


  • Moderators

    @ambershark

    Thanks. The documentation for isValid is a bit ambiguous when reading as stand-alone.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.