Results 1 to 5 of 5

Thread: QSqlTableModel submitAll access query

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

    Default QSqlTableModel submitAll access query

    i have subclass a QTableView to display row limit ... and is model model->setEditStrategy(QSqlTableModel::OnManualSubmit) ;

    How i can access last query to update the 2° database back-up to?



    Qt Code:
    1. /* save all DirtySQL true value and reset DirtySQL to false */
    2. void Mysql_Table::BigCommit()
    3. {
    4. if (model->submitAll()) {
    5. model->database().commit();
    6. DirtySQL = false;
    7. emit ModelError(true);
    8. return;
    9. } else {
    10. model->database().rollback();
    11.  
    12. if (!haveindex) {
    13. QMessageBox::warning(0, tr("Table %1 ").arg(table),
    14. tr("The database reported an error: %1\nAnd table not having index!").arg(model->lastError().text()));
    15. } else {
    16. QMessageBox::warning(0, tr("Table %1 ").arg(table),
    17. tr("The database reported an error: %1").arg(model->lastError().text()));
    18. }
    19. emit ModelError(false);
    20. return;
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 26th April 2007 at 23:52. Reason: wrapped too long lines

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlTableModel submitAll access query

    Last query of what? An SQL model? Most probably through QSqlQueryModel::query()

  3. #3
    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: QSqlTableModel submitAll access query

    Quote Originally Posted by wysota View Post
    Last query of what? An SQL model? Most probably through QSqlQueryModel::query()

    No the UPDATE Query by submit all..

    i found only ONE Way... connect the model an grab all data to construct a sqlquery..
    is here no other way?

    Qt Code:
    1. connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(WakeUpTable(QModelIndex,QModelIndex)));
    2.  
    3. void Mysql_Table::WakeUpTable(const QModelIndex & a , const QModelIndex & b )
    4. {
    5. if (a.isValid() && b.isValid()) {
    6.  
    7. if (model->isDirty(a) && model->isDirty(b)) {
    8. /* user mods data set new wath? */
    9. const QString fieldnametouch = FieldNameList.at(a.column());
    10. const QString indexfieldname = INDEXFIELD; /* discovery on SHOW COLUMNS FROM table + make qstringlist FieldNameList */
    11.  
    12. DirtySQL = true;
    13. if (INDEXFIELD.size() > 0) {
    14. /* QModelIndex index field */
    15. QModelIndex base = a.sibling(a.row(),indexcolumn);
    16. /* Prepare Dirty sqlupdate */
    17. const QString pending = QString("UPDATE %1 SET %2='%3' WHERE %4='%5' LIMIT 1")
    18. .arg(table)
    19. .arg(fieldnametouch)
    20. .arg(a.data().toString())
    21. .arg(INDEXFIELD)
    22. .arg(base.data(Qt::DisplayRole).toString());
    23. /* append on a list wakeup on submit ... */
    24. DirtyPendingQuery.append(pending);
    25. qDebug() << "### Pendingsql one line " << pending;
    26. qDebug() << "### WakeUpTable " << table << " fieldname active " << fieldnametouch << " - "
    27. << a.data().toString() << " - " << a.row()
    28. << "x" << a.column() << " on " << base.data(Qt::DisplayRole).toString();
    29. }
    30. }
    31. }
    32.  
    33. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 26th April 2007 at 23:51. Reason: wrapped too long line

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlTableModel submitAll access query

    If you submit ALL, then obviously ALL rows are submitted, so the query is easy to guess. I don't really see what you're trying to do... If you want only dirty rows to be submited then simply subclass the model, store somewhere a list of dirty rows and update them manually.

  5. #5
    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: QSqlTableModel submitAll access query

    Quote Originally Posted by wysota View Post
    If you submit ALL, then obviously ALL rows are submitted, so the query is easy to guess. I don't really see what you're trying to do... If you want only dirty rows to be submited then simply subclass the model, store somewhere a list of dirty rows and update them manually.
    I have two DB MYSQL connection, one db1 on Lan to fast select data 150'000 user adress 2GB data, other db2 on server outside an this db2 receive only update query.. from outside.

    Model work only on db1, i can not connect model on two db connection. Also i must put on cache each query and at end sumbit all on db2.

    Moreover it has also sense, to have a query log from user, to grab or discovery mistake update by so mach data.

Similar Threads

  1. Replies: 1
    Last Post: 4th October 2006, 16:05

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.