-
Bug
-
Resolution: Done
-
P2: Important
-
4.8.6, 5.3.0
-
Windows 7
-
da72e5538ebcc7e6008d0c4b3538d2a994f02a7e (qtbase/dev, 27.10.2014, 5.5)
Documentation of QSqlField::isAutoValue says "Returns true if the value is auto-generated by the database, for example auto-increment primary key values."
But when ODBC driver is used return value is always false. Seems that qsql_odbc.cpp implementation is missing the auto-increment part.
Patch proposal attached but it doesn't work in every cases.
The reason: The SQLColAttribute() function returns descriptor information for a column in a result_set.
There is no way (or a least, I did not find any way) to get column information without doing a SELECT.
A note should be added to the documentation of QSqlField::isAutoValue() stating that for the QODBC driver, this value is only set in QSqlRecord objects resulting of a SELECT:
Note: When using the ODBC driver, due to limitations in ODBC, the autoValue() field is only valid in QSqlResult::record() resulting of a SELECT query.
It is always false in records from QSqlDatabase::record() and
QSqlDatabase::primaryIndex().
Sample application attached.
Steps how to reproduce:
1. Create an empty mysql database
2. Install myODBC connector(Tested with 5.1 and 5.3 versions)
http://dev.mysql.com/downloads/connector/odbc/5.1.html
http://dev.mysql.com/downloads/connector/odbc/5.3.html
3. Open "Data Sources (ODBC) from control panel and add an entry for your database. Name it "mydb" or change the definition in main.cpp.
4. Run the example and see the "isAutoValue" outputs.
Original driver output is:
record.autovalues: no no (should be: yes no)
primaryIndex.autovalues: no (should be: yes)
select.autovalues: no (should be: yes)
Patched driver output:
record.autovalues: no no (should be: yes no)
primaryIndex.autovalues: no (should be: yes)
select.autovalues: yes (OK)
For Gerrit Dashboard: QTBUG-39388 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
97859,4 | Improve QDebug formatting of QtSql classes. | 5.4 | qt/qtbase | Status: MERGED | +2 | 0 |
97860,2 | WIP: Retrieve auto-value for ODBC fields. | 5.4 | qt/qtbase | Status: ABANDONED | 0 | 0 |
97960,2 | Remove non-UNICODE code branches from ODBC plugin. | dev | qt/qtbase | Status: MERGED | +2 | 0 |
97961,3 | Fix MSVC warnings about integer conversions in ODBC driver. | dev | qt/qtbase | Status: MERGED | +2 | 0 |
97962,3 | Split up function qMakeFieldInfo() in ODBC plugin. | dev | qt/qtbase | Status: MERGED | +2 | 0 |
97963,3 | Retrieve auto-value for ODBC fields. | dev | qt/qtbase | Status: MERGED | +2 | 0 |