Page 2 of 2 FirstFirst 12
Results 21 to 40 of 57

Thread: Record update windowd entered data saving

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Record update windowd entered data saving

    So, am I nut or what? This time submitAll failed and first qDebug() we have
    Qt Code:
    1. QSqlQueryModel::lastError returned {...}
    2. QSqlError::text returned {" " size=1}
    To copy to clipboard, switch view to plain text mode 
    and after second qDebug() we have:
    Qt Code:
    1. QSqlQueryModel::query returned {...}
    2. QSqlQuery::lastQuery returned {"SELECT stranka.SIFRA,stranka.DS,stranka.PRIIMEK,stranka.IME,ulica.naziv,stranka.STEVILKA_ULICE,kraj.naziv_kraja FROM stranka,u" size=217}
    To copy to clipboard, switch view to plain text mode 

    What is going on?
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Record update windowd entered data saving

    Quote Originally Posted by MarkoSan
    What is going on?
    Indeed something strange is going on. What does QSqlError::type() return?

  3. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Record update windowd entered data saving

    Ok, this is diagnostic code:
    Qt Code:
    1. if(m_pTableModel->submitAll())
    2. {
    3. qDebug() << "Data submitted successfully";
    4. } else
    5. {
    6. qDebug() << m_pTableModel->lastError().text();
    7. qDebug() << m_pTableModel->lastError().type();
    8. qDebug() << m_pTableModel->query().lastQuery();
    9. }
    To copy to clipboard, switch view to plain text mode 

    This is very very strange:
    Qt Code:
    1. QSqlError::type returned NoError
    To copy to clipboard, switch view to plain text mode 

    NoError has been reported!!! How come???
    Qt 5.3 Opensource & Creator 3.1.2

  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: Record update windowd entered data saving

    SELECT stranka.SIFRA,stranka.DS,stranka.PRIIMEK,stranka.I ME,ulica.naziv,stranka.STEVILKA_ULICE,kraj.naziv_kraja FROM stranka,u
    This stinks... What is the table "kraj" doing here if it's not in the "FROM" part of the query? On the other hand, looks like "u" is not used here, so why is it in the statement? Is that a complete output from lastQuery? Is this a SqlTableModel or QSqlRelationalTableModel? How come SqlTableModel has more than one table in use? Is that last query connected with the model at all?

  5. #5
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Record update windowd entered data saving

    Quote Originally Posted by wysota
    This stinks... What is the table "kraj" doing here if it's not in the "FROM" part of the query? On the other hand, looks like "u" is not used here, so why is it in the statement? Is that a complete output from lastQuery? Is this a SqlTableModel or QSqlRelationalTableModel? How come SqlTableModel has more than one table in use? Is that last query connected with the model at all?
    You are right. Does submitAll() generated any SQL statement? The reason I ask is that that statement is responsible for displaying data in QSqlRelationalTableModel and it works fine and lastQuery after sumbitAll still reports that statement, which is obviously not statement for inserting records.

    The statement that I get from debuger is:
    Qt Code:
    1. QSqlQuery::lastQuery returned {"SELECT stranka.SIFRA,stranka.DS,stranka.PRIIMEK,stranka.IME,ulica.naziv,stranka.STEVILKA_ULICE,kraj.naziv_kraja FROM stranka,u" size=217}
    To copy to clipboard, switch view to plain text mode 
    Last edited by MarkoSan; 8th January 2006 at 18:05.
    Qt 5.3 Opensource & Creator 3.1.2

  6. #6
    Join Date
    Jan 2006
    Location
    Lincoln, NE USA
    Posts
    177
    Thanks
    3
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Record update windowd entered data saving

    I do something like what is shown below, but if you have an updatable view (using multiple tables) on your database then something similar to this snippet should work.
    Qt Code:
    1. void homestead::UpdateProperty() {
    2. QDateTime dtNow = QDateTime::currentDateTime();
    3. QString propQryPrep = "UPDATE property_";
    4. propQryPrep.append(this->dbYear);
    5. propQryPrep.append(" SET \
    6. county = :county, \
    7. cntyname = :cntyname, \
    8. txdistrict = :txdistrict, \
    9. legal = :legal, \
    10. parcel_id = :parcel_id, \
    11. pvalue = :pvalue, \
    12. entry_id = :entry_id, \
    13. entry_date = :entry_date, \
    14. notes = :notes \
    15. WHERE proprty_id = :proprty_id");
    16.  
    17. propQry.prepare(propQryPrep);
    18. propQry.bindValue(":county",ui.leCountyNumber->text().toInt());
    19. propQry.bindValue(":cntyname",ui.cboCountyName->currentText());
    20. propQry.bindValue(":txdistrict",ui.leTaxDistrict->text());
    21. propQry.bindValue(":legal",ui.txtLegal->toPlainText());
    22. propQry.bindValue(":parcel_id",ui.leParcelID->text());
    23. propQry.bindValue(":pvalue",ui.leHomeValue->text().toInt());
    24. propQry.bindValue(":entry_id",homestead::RevID);
    25. propQry.bindValue(":entry_date",dtNow);
    26. propQry.bindValue(":notes",ui.teNotes->toPlainText());
    27. propQry.bindValue(":proprty_id",ui.leProprtyID->text().toInt());
    28. if (propQry.exec()) {
    29. ui.leStatus->setText("Property record: "+ui.leProprtyID->text()+" updated!");
    30. } else {
    31. ui.leStatus->setText("Cannot updated property record: "+ui.leProprtyID->text());
    32. }
    33. }
    To copy to clipboard, switch view to plain text mode 
    BTW, this code works on Oracle and on PostgreSQL before 8.1.0. On PostgreSQL after 8.0 they've added 3 millisecond positions to the QDateTime return.

  7. #7
    Join Date
    Jan 2006
    Location
    Iasi, Romania
    Posts
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Record update windowd entered data saving

    I have found a solution to my problem. I have appended a QSqlField to the record retrieved with model->record()
    Qt Code:
    1. QSqlRecord rec = model->record();
    2. QSqlField cityField("city", QVariant::Int);
    3. rec.append(cityField);
    4. rec.setValue("name", "Test Customer");
    5. rec.setValue("city", 1); // or whatever value exists in the related table 'cities'
    6.  
    7. model->insertRecord(-1, rec);
    8. model->submit();
    To copy to clipboard, switch view to plain text mode 
    'city' is the name of a field in the 'customers' database table but which is not part of the query that filled the model.
    'city_name' is the name of a field in the related table 'cities' and is contained by rec.
    I run this code and I got the same "error" - record inserted in the table 'customers' but the value of 'city' field is set to the default == 0. Then I have installed Qt 4.1.0 and magically it worked - record inserted with proper value for field 'city' == 1 (in this case).
    So, as wysota said, it is probably a bug in Qt 4.0.0.
    Thanks for all suggestions.

  8. #8
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Record update windowd entered data saving

    Whatever I do, I cannot get data into database!!!! I am going mad!!!
    Qt 5.3 Opensource & Creator 3.1.2

  9. #9
    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: Record update windowd entered data saving

    Quote Originally Posted by MarkoSan
    Whatever I do, I cannot get data into database!!!! I am going mad!!!
    Please provide a minimal compilable example which reproduces the problem. Your code is too complex (and incomplete) for us to test on our own machines.

  10. #10
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Record update windowd entered data saving

    Quote Originally Posted by wysota
    Please provide a minimal compilable example which reproduces the problem. Your code is too complex (and incomplete) for us to test on our own machines.
    I tried, but zip file is too big and i do not know how to distribure sql databse.
    Qt 5.3 Opensource & Creator 3.1.2

  11. #11
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Record update windowd entered data saving

    Is the situation maybe connected with http://www.trolltech.com/developer/t...entry&id=86645, what do you think?
    Qt 5.3 Opensource & Creator 3.1.2

  12. #12
    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: Record update windowd entered data saving

    Quote Originally Posted by MarkoSan
    I tried, but zip file is too big and i do not know how to distribure sql databse.
    So make it smaller. The example is to be minimal. We don't need your database, just a table schema and some sample data.

  13. #13
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Record update windowd entered data saving

    Here is minimal project file and sources (VC++ 6.0 Service Pack 6, Qt 4.0.1). After unziping in .sql file there are table declarations and sample data.
    Last edited by MarkoSan; 17th June 2006 at 03:11.
    Qt 5.3 Opensource & Creator 3.1.2

  14. #14
    Join Date
    Jan 2006
    Location
    Iasi, Romania
    Posts
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Record update windowd entered data saving

    I have managed to make it work but I use Qt 4.1.0 on WinXp and MySQL 4.1.11. Similar code didn't work on Qt 4.0.0, but I don't know about 4.0.1. My modifications are commented with 'modified by fane' (hope I didn't miss anyone), and of course your MySQL root password has to be changed.
    I have appended two QSqlFields to the record retrieved with model->record() named "ULICA" and "POSTA_STEVILKA", set their value with QSqlRecord::setValue(). I have modified the edit strategy to be OnRowChange and removed the setValue() call for the "SIFRA" field which is autoincremented by MySQL.
    I guess you have to move to Qt 4.1.0 according to this
    Attached Files Attached Files
    Last edited by fane; 18th January 2006 at 19:02.

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.