Results 1 to 14 of 14

Thread: submitAll() -> "no fields to update"

  1. #1
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default submitAll() -> "no fields to update"

    Hello,

    Porting some apps from linux to windows..
    I get this error from a QSqlTableModel when trying to submit changes. In linux this works without error and updates the database, in windows it doesn't.
    Changes made to individual records are done however, just not submitted back to the database.
    Did I forget something?

    And if anyone knows an ide for qt for windows which does debugging please tell...
    Last edited by JeanC; 19th September 2008 at 13:36.

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: submitAll() -> "no fields to update"

    This is an error in Qt 4.4.1 and 4.4.2; Trolls know about it and hopefully fix it soon.

  3. #3
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: submitAll() -> "no fields to update"

    Too bad, thanks.

  4. #4
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: submitAll() -> "no fields to update"

    I found two bug entries which seem about this bug
    http://trolltech.com/developer/task-...ntry&id=227468
    http://trolltech.com/developer/task-...ntry&id=182664

    The latter is from 2007, so I guess the first is this bug and it says:

    Version for fix set to 'Not scheduled', Priority changed to 'No Priority'

    That does not indicate there's gonna be a bugfix soon. Somebody knows a workaround?

  5. #5
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: submitAll() -> "no fields to update"

    fyi: this bug was fixed in Qt 4.4.0 (which was release in 2008 iirc)
    [that is to say: I get this bug in a lib of mine when saving a record. My code worked (and works) with 4.4.0; it does not work with newer releases]

  6. #6
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: submitAll() -> "no fields to update"

    He caduel,

    Well in linux I use some 3.x version and have no trubbles.
    I'm wondering if I should downgrade and compile qt 4.4.0 or wait for a bugfix.
    I'll see how it goes, if I miss the functionality too much I'll just downgrade.
    Thanks.
    Last edited by JeanC; 20th September 2008 at 17:51.

  7. #7
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: submitAll() -> "no fields to update"

    Quote Originally Posted by JeanC View Post
    Hello,

    Porting some apps from linux to windows..
    I get this error from a QSqlTableModel when trying to submit changes. In linux this works without error and updates the database, in windows it doesn't.
    Changes made to individual records are done however, just not submitted back to the database.
    Did I forget something?

    And if anyone knows an ide for qt for windows which does debugging please tell...
    On window OS i found submitAll() bug only on mysql client driver mysql version < 5.0.2 (minor as).

    try to build http://ppk.ciz.ch/qt_c++/mysql_model...YSQL_Model.zip screenshot
    http://ppk.ciz.ch/qt_c++/mysql_model...wser_model.png if you use mysql ... on sqlite3 i never found submitAll() bug.

    On window OS to close database MYSQL use delete &class to suppress all message....
    QSqlDatabase::close () only run clean on linux & mac.

  8. #8
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: submitAll() -> "no fields to update"

    I get the error on Oracle + linux.

  9. #9
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: submitAll() -> "no fields to update"

    Quote Originally Posted by caduel View Post
    I get the error on Oracle + linux.
    debug your table if driver can find index field from table
    If no index is found it not possibel to "auto update" or submitAll().

    Mysql = SHOW INDEX FROM table
    Ora = select index_name from dba_indexes where table_name='tablename';
    on oracle must display a key PRIMARY
    if not, set one...

    update where what = xx


    Qt Code:
    1. /* discovery total row whitout limit mysql / to play next prev ... button */
    2. void Mysql_Table::UpdateSumm()
    3. {
    4. QString grepprimary,grepauto;
    5. /* reset index fieldname */
    6. /* SHOW INDEX FROM table */
    7.  
    8. INDEXFIELD = "";
    9. FieldNameList.clear();
    10. const QString info = QString("SHOW COLUMNS FROM %1").arg(table);
    11. QSqlQuery query(info,db);
    12. QSqlRecord rec = query.record();
    13. ////int sumcol = rec.count();
    14. while (query.next()) {
    15. grepprimary = query.value(3).toString();
    16. grepprimary = grepprimary.toLower();
    17. grepauto = query.value(5).toString();
    18. grepauto = grepauto.toLower();
    19. ///////Q_ASSERT(grepauto.size() > 1); /* no mysql or not connect! or grand not...*/
    20. if (grepprimary == "pri" && grepauto.contains("auto")) {
    21. INDEXFIELD = query.value(0).toString();
    22. //////////qDebug() << "### INDEXFIELD have found " << INDEXFIELD ;
    23. }
    24. FieldNameList.append(query.value(0).toString());
    25. }
    26.  
    27.  
    28. if (INDEXFIELD.size() < 1) {
    29. haveindex = false;
    30. } else {
    31. haveindex = true;
    32. }
    33.  
    34.  
    35. totalrow = 0;
    36. if (haveindex) {
    37. const QString summitem = QString("SELECT COUNT(%2) FROM %1").arg(table).arg(INDEXFIELD);
    38. query.exec(summitem);
    39. while (query.next()) {
    40. totalrow = query.value(0).toInt();
    41. }
    42.  
    43. }
    44. qDebug() << "### totalrow " << totalrow;
    45.  
    46. }
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Nov 2008
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: submitAll() -> "no fields to update"

    I get the error on postgresql + linux.

  11. #11
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: submitAll() -> "no fields to update"

    Hello

    I get such error (i.e., error in submitAll after insertRows) using Sqlite and Qt 4.7.1. Is this still the previously mentioned unresolved bug, or do I something wrong?

    The code below produces an ASSERT failure in the last row with the error message "No Fields to update". The two lines that are commented out are two options that I tried.

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"));
    2. db.setDatabaseName(QLatin1String("testdb.db"));
    3. Q_ASSERT(db.open());
    4. QSqlQuery sqlQuery(db);
    5. bool ok;
    6. // ok = sqlQuery.exec(QLatin1String("CREATE TABLE Table1 (Content, Identifier INTEGER PRIMARY KEY AUTOINCREMENT, Parent INTEGER NOT NULL, Details);"));
    7. ok = sqlQuery.exec(QLatin1String("CREATE TABLE Table1 (Content, Identifier INTEGER PRIMARY KEY AUTOINCREMENT, Parent, Details);"));
    8. // ok = sqlQuery.exec(QLatin1String("CREATE TABLE Table1 (Content, Identifier, Parent, Details);"));
    9. Q_ASSERT_X(ok, "CREATE TABLE sql statement", "Table1 likely already exists");
    10. ok = sqlQuery.exec(QLatin1String("INSERT INTO Table1(Content, Parent, Details) VALUES ('first item', 0, 'Details for first item');"));
    11. Q_ASSERT(ok);
    12.  
    13. QSqlTableModel* tableModel = new QSqlTableModel(this, db);
    14. tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    15. tableModel->setTable(QLatin1String("Table1"));
    16. tableModel->select();
    17. tableView->setModel(tableModel);
    18. tableView->resizeColumnsToContents();
    19.  
    20. ok = tableModel->insertRows(0, 1, QModelIndex());
    21. Q_ASSERT(ok);
    22.  
    23. ok = tableModel->submitAll();
    24. Q_ASSERT_X(ok, "submitAll", qPrintable(tableModel->lastError().text()));
    To copy to clipboard, switch view to plain text mode 
    Any help appreciated; either to correct my code or to find a work-around.

    Al_

    Edit:
    others have issues with removeRows ..., see http://www.qtcentre.org/threads/3876...ght=insertRows
    Last edited by Al_; 26th February 2011 at 15:47.

  12. #12
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: submitAll() -> "no fields to update"

    Couldn't find anything in the docs (probably in there somewhere ) but by looking at the source code it appears you cannot submit an empty record to a database. And the question that bears asking is why would you?

    From qsqltablemodel.cpp:
    Qt Code:
    1. bool QSqlTableModel::insertRowIntoTable(const QSqlRecord &values)
    2. {
    3. QSqlRecord rec = values;
    4. emit beforeInsert(rec);
    5.  
    6. bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries);
    7. QString stmt = d->db.driver()->sqlStatement(QSqlDriver::InsertStatement, d->tableName,
    8. rec, prepStatement);
    9.  
    10. if (stmt.isEmpty()) {
    11. d->error = QSqlError(QLatin1String("No Fields to update"), QString(),
    12. QSqlError::StatementError);
    13. return false;
    14. }
    15.  
    16. return d->exec(stmt, prepStatement, rec);
    17. }
    To copy to clipboard, switch view to plain text mode 

    You can test this in your code:
    Qt Code:
    1. ...
    2. ok = tableModel->insertRows(0, 1, QModelIndex());
    3. Q_ASSERT(ok);
    4.  
    5. QSqlRecord record = tableModel->record(0); // retrieve inserted record
    6. QString stmt = db.driver()->sqlStatement(QSqlDriver::InsertStatement, "Table1", record, false); // test in source code above
    7. qDebug() << stmt; // QString stmt above is empty which causes your assert failure
    8. record.setValue(0,"inserted item");
    9. tableModel->setRecord(0,record); // record is no longer empty
    10. stmt = db.driver()->sqlStatement(QSqlDriver::InsertStatement, "Table1", record, false); // test modified record
    11. qDebug() << stmt; // stmt !isEmpty so submitAll returns true
    12.  
    13. ok = tableModel->submitAll();
    14. Q_ASSERT_X(ok, "submitAll", qPrintable(tableModel->lastError().text()));
    15. ...
    To copy to clipboard, switch view to plain text mode 
    Last edited by norobro; 26th February 2011 at 23:17.

  13. The following user says thank you to norobro for this useful post:

    Al_ (27th February 2011)

  14. #13
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: submitAll() -> "no fields to update"

    The QSqlTableModel code will not attempt to "update" a row that has been inserted but not modified. It strikes me that, even if it worked as you expect, the empty row in this circumstance violates the NOT NULL constraint placed on the Parent column. Setting that column of the blank row to zero allows the insert to go ahead.

  15. #14
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default [SOLVED] Re: submitAll() -> "no fields to update"

    @norobro: many thanks, this solved it. It also means that I need to use QSqlTableModel (as in the example provided) and not the more general case of any derivative of virtual QAbstractTableModel; however, I now realize that in that general case no guarantee is given that the non-abstract table model class supports insertions.

    @ChrisW67: yes, this is true for the first (commented out) version of the table definition, but not for the not-commented.

    Al_

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.