3
I have an application with a database connection, when initializing the application I need to check if there is any record in the table, if a user should not be registered, when I run the query SELECT EXISTS (SELECT id FROM va_admins)
directly in the database is returned 0 if there is no record, if there is no return 0, however in the application, it is always returned 0, I am making the query this way:
bool Admin::issetAdm()
{
QSqlDatabase db = QSqlDatabase::database();
if(!db.isOpen()){
QMessageBox::critical(nullptr, "Falha ao verificar adm", "nenhuma conexão com o banco de dados encontrada");
qCritical() << "Falha ao verificar: " << db.lastError().text();
return false;
}
QSqlQuery q("SELECT EXISTS (SELECT id FROM va_admins)", db);
if(!q.exec()){
qCritical() << "Falha ao realizar a consulta: " << q.lastError().text();
exit(-1);
}
//Editado
while(q.next()){
qDebug() << q.record().value(q.record().indexOf("id")).toInt();
}
q.finish();
return true;
}
Worked perfectly
– Samuel Ives