Error -1 on execute query...
-
I trying to execute a query, as showed below, and I got error everytime!
The code error is -1, and As showed at "Qsqlerror":http://qt-project.org/doc/qt-5.0/qsqlerror.html, this error "type cannot be determined.".@ QSqlDatabase database = SingletonSession::getDatabase();
if (database.open())
{
QSqlQuery query("SELECT * FROM velocidadeCAN", database);
query.exec();
query.first();
qDebug() << "Consulta: " << query.executedQuery();
qDebug() << "Error: " << query.lastError();
query.finish();
}
@Debug:
Consulta: "SELECT * FROM velocidadeCAN"
Error: QSqlError(-1, "", "")How can I make some debug, or check the database to validade all! I could open the database created by Qt on Firefox Plugin called "SQLite Manager" and do the same query and get the data from database without errors!
-
If you pass a non-empty query string to the QSqlQuery constructor the query is immediately executed. There is no need to explicitly call exec().
Quite contrary to, I'm not sure if a call to exec() is only allowed if there has been a query prepared using prepare(). This might be the cause of your error.
-
@ QSqlDatabase database = SingletonSession::getDatabase();
if (database.open()) //did you already open the database in your singleton?
{
QSqlQuery query("SELECT * FROM velocidadeCAN", database);
...
@Instead try (you probably want to omit "yourConnectionName" if you used the default):
@
QSqlDatabase database = QSqlDatabase::database( "yourConnectionName" );
if( database.isOpen() )
{
QSqlQuery query( database );
if( !query.exec( "your SQL statement" ) )
{
qDebug() << "Consulta: " << query.executedQuery();
qDebug() << "Error: " << query.lastError().text();
}
...
@... just an idea on how to proceed.