QSqlQuery bug/oddity

Report any problems with CopperSpice
Post Reply
seasoned_geek
Posts: 254
Joined: Thu Jun 11 2020 12:18 pm

QSqlQuery bug/oddity

Post by seasoned_geek »

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.

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
Easily identified from command line, but not programatically.

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() );
        }
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.
Post Reply