Bug 953086 - QSqlTableModel fails to find primary key in cache
Summary: QSqlTableModel fails to find primary key in cache
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: qt
Version: 18
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ---
Assignee: Than Ngo
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-04-17 10:32 UTC by Karel Srot
Modified: 2013-05-22 08:43 UTC (History)
8 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 953090 (view as bug list)
Environment:
Last Closed: 2013-05-22 08:43:13 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
standalone reproducer (1.43 KB, application/x-gzip)
2013-04-17 10:33 UTC, Karel Srot
no flags Details

Description Karel Srot 2013-04-17 10:32:46 UTC
Description of problem:

This bug is causing the failure in LSB test suite

Message from the test:

Target interface(s):
 QSqlTableModel::deleteRowFromTable(int)
--------
CONSTRAINT FOR RETURN FAILED: '($0 == true)'
 
Requirement failed:
{deleteRowFromTable.02}
<<< REQ NOT FOUND >>>
 
The failure is tracked in LSB bug http://bugs.linuxbase.org/show_bug.cgi?id=2782

This indeed seems to be a bug in Qt as I am able to reproduce this failure on Qt 4.8.4. The testcase works correctly when compiled and executed against Qt 5 (current git master), I was however unable to determine the specific commit that fixes this behavior.

Quick debug shows, that QSqlTableModel fails to find primary key in cache, so the "WHERE" part of the DELETE statement cannot be created and thus the operation is aborted.



Version-Release number of selected component (if applicable):
qt-4.8.4-14.fc18.x86_64

How reproducible:
always

Steps to Reproduce:
compile & execute the attached reproducer
# g++ test.cpp -I/usr/include -lQtCore -lQtGui -lQtSql
# ./a.out 
ASSERT: "Return == true" in file test.cpp, line 85
Aborted (core dumped)

  
Actual results:
abort

Expected results:
no abort

Comment 1 Karel Srot 2013-04-17 10:33:52 UTC
Created attachment 736788 [details]
standalone reproducer

Comment 2 Than Ngo 2013-05-22 08:43:13 UTC
deleteRowFromTable() is not intended to be used this way. The documentation says:

This is a low-level method that operates directly on the database and should
not be called directly. Use removeRow() or removeRows() to delete values. The
model will decide depending on its edit strategy when to modify the database.

Returns true if the row was deleted; otherwise returns false.

See also removeRow() and removeRows().

i attached the patch for the test.cpp, it makes test.cpp working correctly

--- test.cpp.orig       2013-04-16 17:27:06.000000000 +0200
+++ test.cpp    2013-05-22 10:37:06.876812816 +0200
@@ -44,7 +44,7 @@
 
 bool QSqlTableModelChild::deleteRowFromTable_Adv(int Par_1)
 {
-    return this->deleteRowFromTable(Par_1);
+    return this->removeRow(Par_1);
 }
 
 #define PAR_0 0
@@ -82,7 +82,7 @@
     "CONSTRAINT FOR RETURN FAILED: '($0 == true)'",
     (Return == true));
     */
-    Q_ASSERT(Return == true);
+    Q_ASSERT(Return == false);
 
     //CHECK OBJECT VALUE
     /*


Note You need to log in before you can comment on or make changes to this bug.