Unsolved How to determine if primary key is generated always or by default
dadler last edited by dadler
Using DB2, we have tables which use the following definitions to create primary keys:
CREATE TABLE TEST.ZIPPOINT(
objectid BIGINT NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY
CREATE TABLE TEST.ZIPPOLY(
objectid INTEGER NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
We use code like the following to get the primary key information:
QSqlIndex pk = mDatabase.primaryIndex( table );
QSqlField pkFld = pk.field( 0 );
QgsDebugMsg(QString("auto: %1; generated: %2" ).arg(pkFld.isAutoValue()).arg(pkFld.isGenerated()));
But isAutoValue() is always 0 and isGenerated() is always 1
The documentation states:
*bool QSqlField::isAutoValue() const
Returns true if the value is auto-generated by the database, for example auto-increment primary key values.
bool QSqlField::isGenerated() const
Returns true if the field is generated; otherwise returns false.*
It isn't clear what "generated" actually means for the field.
dadler last edited by
@dadler From looking at the source, it appears that the ODBC driver that we are using does not call setAutoValue so isAuto will always be false. This is also true of the DB2-specific driver.
isGenerated has to do with whether or not SQL is generated for a field and doesn't have anything to do with primary key generation.
mrjj Lifetime Qt Champion last edited by
The doc says this for ODBC
But it seems u found that its also true for the DB2 driver?
Thank you for updating the post.