I am using QtSql module with a MySQL back end. I prefer to using bindValue() as much as is possible for input values in queries.

I have a case where I need to SELECT and look for a NULL in the WHERE clause.
A simplified example of what I need to do [effectively]:

SELECT * FROM rabbits WHERE color IS NULL;
All the binding examples in the documentation show only INSERT statements, however. The documentation says to bind the QVariant(QVariant::String) to the ":color" term.

Qt Code:
  1. void do_query(QString color)
  2. {
  3. // stuff
  4. query.prepare("SELECT * FROM rabbits WHERE color=:color");
  5. if (color.isEmpty())
  6. query.bindValue(":color", QVariant(QVariant::String));
  7. else
  8. query.bindValue(":color", color);
  9. query.exec();
  10. // more stuff
  11. }
To copy to clipboard, switch view to plain text mode 
Some of the documentation wording gives me pause and I think it is probably specific to an INSERT statement which would convert to "=NULL" when making the MySQL call underneath. A where statement would need to be converted to " IS NULL" instead.

Is there is a way use binding to SELECT items matching a NULL as well as those matching a value?