PDA

View Full Version : QSQLITE Unable to fetch row in create



xgoan
17th October 2006, 20:08
bool crearTablas(QWidget *parent){
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:

SQL logic error or missing database Unable to fetch row
But if I redo the query the error changes to:

table itinerario already exists Unable to fetch

Any help?

munna
18th October 2006, 09:08
I use QSqlQuery the following way and it works fine.




QSqlQuery query;

if(!query.exec("CREATE TABLE cgroup(id INTEGER PRIMARY KEY,name TEXT,category INTEGER,operator TEXT)")){
//Error message
}

xgoan
18th October 2006, 09:51
WTF!

Why if I use the SQL into the exec() it works?

Now it works :s

sunil.thaha
18th October 2006, 15:39
It's simple!
you might have understood the docs incorrectly



QSqlQuery q( queryStirng );
Will execute the query. which explains why you get the warning


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