QSQLITE Unable to fetch row in create
Code:
QSqlQuery query
("CREATE TABLE itinerario(id INTEGER, nombre VARCHAR(32), tipo_sendero INTEGER, " "municipio VARCHAR(25), fecha_visita DATE, punto_salida VARCHAR(25), punto_llegada VARCHAR(25), "
"zona VARCHAR(25), provincia VARCHAR(25), fecha DATE, mapa VARCHAR(25), modo_realizacion INTEGER);");
if(!query.exec()){
QMessageBox::critical(parent,
"", query.
lastError().
text());
return false;
}
return true;
}
Is this code wrong? I'm trying to query a database created in another function and it gives the error:
Quote:
SQL logic error or missing database Unable to fetch row
But if I redo the query the error changes to:
Quote:
table itinerario already exists Unable to fetch
Any help?
Re: QSQLITE Unable to fetch row in create
I use QSqlQuery the following way and it works fine.
Code:
if(!query.exec("CREATE TABLE cgroup(id INTEGER PRIMARY KEY,name TEXT,category INTEGER,operator TEXT)")){
//Error message
}
Re: QSQLITE Unable to fetch row in create
WTF!
Why if I use the SQL into the exec() it works?
Now it works :s
Re: QSQLITE Unable to fetch row in create
It's simple!
you might have understood the docs incorrectly
Will execute the query. which explains why you get the warning
Quote:
SQL logic error or missing database Unable to fetch row
when you run query.exec(). " Qt expects a prepared query here; which is not there "
Now you will be able to figure out why query.exec( createTableQuery ) works