PDA

View Full Version : model->select() gives error "you have an error in your syntax" etc.



JeanC
15th February 2008, 10:48
Hello,

Don't know what happens here, it's just a plain litte table.
The error msg is: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'index, ip, name, pass FROM members' at line 1 QMYSQL: Unable to execute query"
It's the only table that produces this error.
QSqlQuery on it works and shows the content.



db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.1.10");
db.setDatabaseName("iris");
db.setUserName("me");
db.setPassword("pass");
if (!db.open())
setWindowTitle(db.lastError().text());
model = new QSqlTableModel;
model->setTable("members");
if (!model->select())
qDebug() << model->lastError().text();

jpn
15th February 2008, 12:02
Is that MySQL 4 or higher?

JeanC
15th February 2008, 15:23
Yes this is 5.0.15

I now use a tablewidget and a query which suited me better, though I thought I'd ask anyway..

Khal Drogo
15th February 2008, 18:11
I may be mistaken on this, but isn't index a mysql keyword? You are using it without prefixing it with the table name and without ' '.

JeanC
15th February 2008, 18:27
You are right. I didn't know that. It tests ok with another fieldname.

Thanks.