QSqlQuery bug/oddity
Posted: Tue Dec 27 2022 4:11 pm
All,
Manjaro XFCE 21. whatever the most recent is, all updates applied. PostgreSQL.
I had a bugger-boo in my code. Put the IF EXISTS clause in wrong place.
Easily identified from command line, but not programatically.
The lastError().text() and the resulting messagebox were both empty.
There do appear to be a loophole where not all error messages are caught. Odd, because the exec() knew of the failure.
Manjaro XFCE 21. whatever the most recent is, all updates applied. PostgreSQL.
I had a bugger-boo in my code. Put the IF EXISTS clause in wrong place.
Code: Select all
psql (14.6)
Type "help" for help.
tax_2022=# DROP DATABASE tax_1982 IF EXISTS;
ERROR: syntax error at or near "IF"
LINE 1: DROP DATABASE tax_1982 IF EXISTS;
^
tax_2022=# \q
Code: Select all
QString cmd = "DROP DATABASE %1 IF EXISTS;";
cmd = QStringParser::formatArg( cmd, physicalDbName );
QSqlQuery dropQuery( currentDb );
if ( !dropQuery.exec( cmd ) )
{
qDebug() << "dropQuery cmd: " << cmd << "\n";
qDebug() << "errorText: " << currentDb.lastError().text() << "\n";
QMessageBox::critical( nullptr, tr( "Database Deletion" ), currentDb.lastError().text() );
}
There do appear to be a loophole where not all error messages are caught. Odd, because the exec() knew of the failure.