I've learned that QSqlDriver::sqlStatement(QSqlDriver::WhereStatemen t, "table1", whereValues, false) can generate a QString like "WHERE column=value", but how do I generate "WHERE column<>value"?
Thanks.
I've learned that QSqlDriver::sqlStatement(QSqlDriver::WhereStatemen t, "table1", whereValues, false) can generate a QString like "WHERE column=value", but how do I generate "WHERE column<>value"?
Thanks.
What exactly are you trying to do? You shouldn't need to interact with QSqlDriver directly.
Thanks, but I am not using QSqlDriver directly. For example, the following code generate: SELECT "name" from Users WHERE "age" = 20
:
Qt Code:
QSqlRecord rec; QSqlRecord whereValues; db.setHostName("localhost"); db.setDatabaseName("D:\\test.db"); bool ok = db.open(); rec.append(f1); f2.setValue(20); whereValues.append(f2); To copy to clipboard, switch view to plain text mode
But how to generate the following:
- SELECT "name" from Users WHERE "age" <> 20
- SELECT "name" from Users WHERE "age" > 20
I am trying to create application that can change database system such as between SQLite, PostgreSql etc, without hardcoding the SQL statements.
No? So what's that?
But how to generate the following:
- SELECT "name" from Users WHERE "age" <> 20
Qt Code:
QSqlQuery q; q.prepare("SELECT name FROM Users WHERE age <> :val"); q.bindValue(":val", 20); q.exec();To copy to clipboard, switch view to plain text mode
- SELECT "name" from Users WHERE "age" > 20
Qt Code:
QSqlQuery q; q.prepare("SELECT name FROM Users WHERE age > :val"); q.bindValue(":val", 20); q.exec();To copy to clipboard, switch view to plain text mode
All databases must respect ANSI SQL so if you constrain yourself to that, all will be fine. It's not possible to build any generic query using the interface you were trying with. That's meant for something else.I am trying to create application that can change database system such as between SQLite, PostgreSql etc, without hardcoding the SQL statements.
jezz (15th January 2012)
Thanks, but is this considered using QSqlDriver directly? It is in this case actually QSQLiteDriver which is derived from QSqlDriver.
Yes, it's considered using QSqlDriver directly (as opposed to using QSqlDatabase and QSqlQuery that call QSqlDriver API behind the scenes).
Bookmarks