Skip to content

Commit a002e67

Browse files
committed
Make 'without rowid' tables browseable
Don't depend on the existance of the rowid column when using the Browse Data tab; this means falling back to the primary key if the selected table is a 'without rowid' table. While still not supporting these tables very well this makes them at least readable.
1 parent 1f8686d commit a002e67

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

‎src/sqlitetablemodel.cpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ void SqliteTableModel::setTable(const QString& table)
2727
m_sTable = table;
2828

2929
m_headers.clear();
30-
m_headers.push_back("rowid");
30+
QString rowid = "rowid";
31+
if(m_db->getObjectByName(table).gettype() == "table")
32+
rowid = sqlb::Table::parseSQL(m_db->getObjectByName(table).getsql()).rowidColumn();
33+
m_headers.push_back(rowid);
3134
m_headers.append(m_db->getTableFields(table));
3235

3336
m_mWhere.clear();
@@ -358,19 +361,16 @@ void SqliteTableModel::fetchData(unsigned int from, unsigned to)
358361
void SqliteTableModel::buildQuery()
359362
{
360363
QString where;
361-
QStringList headers;
362-
headers.push_back("rowid");
363-
headers.append(m_db->getTableFields(m_sTable));
364364

365365
if(m_mWhere.size())
366366
{
367367
where = "WHERE 1=1";
368368

369369
for(QMap<int, QString>::const_iterator i=m_mWhere.constBegin();i!=m_mWhere.constEnd();++i)
370-
where.append(QString(" AND `%1` %2").arg(headers.at(i.key())).arg(i.value()));
370+
where.append(QString(" AND `%1` %2").arg(m_headers.at(i.key())).arg(i.value()));
371371
}
372372

373-
QString sql = QString("SELECT rowid,* FROM `%1` %2 ORDER BY `%3` %4").arg(m_sTable).arg(where).arg(headers.at(m_iSortColumn)).arg(m_sSortOrder);
373+
QString sql = QString("SELECT `%1`,* FROM `%2` %3 ORDER BY `%4` %5").arg(m_headers.at(0)).arg(m_sTable).arg(where).arg(m_headers.at(m_iSortColumn)).arg(m_sSortOrder);
374374
setQuery(sql, true);
375375
}
376376

0 commit comments

Comments
 (0)