hi
since the update to qt 4.5 i can't get QSqlQuery::bindValue to work
i tried google and searched the forum but couldn't find an answer to this question.
the following sample code works perfectly using qt 4.3.4, but with qt 4.5 i get this error:
QSqlError(-1, "QPSQL: Unable to create query", "ERROR: syntax error at or near "(" at character 10")
#include <QCoreApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>
#include <QVariant>
int main(int argc, char **argv) {
db.setHostName("localhost");
db.setDatabaseName("test");
db.setUserName("testuser");
db.setPassword("testpw");
db.open();
q.prepare("SELECT :bla FROM myTable");
q.bindValue(":bla","foo");
if(q.exec()) {
while(q.next()) {
qDebug() << "output:" << q.value(0).toString();
}
}
else {
qDebug() << q.lastError();
}
}
#include <QCoreApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>
#include <QVariant>
int main(int argc, char **argv) {
QCoreApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
db.setHostName("localhost");
db.setDatabaseName("test");
db.setUserName("testuser");
db.setPassword("testpw");
db.open();
QSqlQuery q(db);
q.prepare("SELECT :bla FROM myTable");
q.bindValue(":bla","foo");
if(q.exec()) {
while(q.next()) {
qDebug() << "output:" << q.value(0).toString();
}
}
else {
qDebug() << q.lastError();
}
}
To copy to clipboard, switch view to plain text mode
if i do a
q.prepare("SELECT foo FROM myTable");
q.prepare("SELECT foo FROM myTable");
To copy to clipboard, switch view to plain text mode
everything works just fine :/ but i can't get bindValue to work in qt 4.5 
does anyone know what's the problem here?
Bookmarks