[Interest] QSqlTableModel and QSqlRelationalTableModel busted for SQLite

Roland Hughes roland at logikalsolutions.com
Fri Jan 1 02:37:37 CET 2021


All,

Someone asked me to take a look at this and set up a nice little demo 
program using SQLite. I couldn't believe it when I tried this.

void SQLiteModel::deleteRow(int rowNo)
{
     qDebug() << "removeRow called for " << rowNo << "\n";
     bool rslt = removeRow(rowNo);
     qDebug() << "result of removeRow() " << rslt << "\n";
     qDebug() << "Error: " << lastError().text() << "\n";
     qDebug() << "query: " << query().lastQuery() << "\n";
     submitAll();
}

removeRow called for  3

result of removeRow()  false

Error:  "near \"WHERE\": syntax error Unable to execute statement"

query:  "select * from questions;"

Every I/O operation performed within the model fails with that exact 
same error whether it is a nothing table like this:

query.exec("CREATE TABLE IF NOT EXISTS questions (Q_NO INTEGER PRIMARY 
KEY, Q_TEXT TEXT);");

or a slightly less than nothing.

query.exec("CREATE TABLE IF NOT EXISTS questions (Q_NO INTEGER PRIMARY 
KEY AUTOINCREMENT, Q_TEXT TEXT NOT NULL);"

It appears this has been broken for at least a year.

https://forum.qt.io/topic/109992/how-to-remove-row-from-qsqltablemodel/10

I have a full program to test with if someone wants it.

-- 
Roland Hughes, President
Logikal Solutions
(630)-205-1593

http://www.theminimumyouneedtoknow.com
http://www.infiniteexposure.net
http://www.johnsmith-book.com
http://www.logikalblog.com
http://www.interestingauthors.com/blog



More information about the Interest mailing list