Is there a more expressive way of executing SQL query using Qt?

Posted by ShaChris23 on Stack Overflow See other posts from Stack Overflow or by ShaChris23
Published on 2010-03-18T21:48:52Z Indexed on 2010/03/18 21:51 UTC
Read the original article Hit count: 285

Filed under:
|

I currently have this code:

  // Construct query
  QString const statement = QString("drop database if exists %1")
                                    .arg(databaseName_);

  QSqlQuery query(db);
  query.exec(statement);

Is there a better way to code than the above?

Specifically, I dont like how I use QString for SQL statement. It'd be nice if Qt has some class so that I could do something like:

  // Construct query
  QSomeClass statement = "drop database if exists %1";
  statement.setArg(1, databaseName_); // Replace all %1 in the original string.

  QSqlQuery query(db);
  query.exec(statement);

© Stack Overflow or respective owner

Related posts about qt4

Related posts about qt