QString TableSchema::primaryKeyFieldName() const { QSqlTableModel model; model.setTable(tablename); QSqlIndex index = model.primaryKey(); if (index.isEmpty()) { return QString(); } QSqlField fi = index.field(0); return fi.name(); }
int TableSchema::primaryKeyIndex() const { QSqlTableModel model; model.setTable(tablename); QSqlIndex index = model.primaryKey(); if (index.isEmpty()) { return -1; } QSqlField fi = index.field(0); return model.record().indexOf(fi.name()); }