Skip to content

Commit

Permalink
Make 'without rowid' tables browseable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MKleusberg committed May 9, 2014
1 parent 1f8686d commit a002e67
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/sqlitetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ void SqliteTableModel::setTable(const QString& table)
m_sTable = table;

m_headers.clear();
m_headers.push_back("rowid");
QString rowid = "rowid";
if(m_db->getObjectByName(table).gettype() == "table")
rowid = sqlb::Table::parseSQL(m_db->getObjectByName(table).getsql()).rowidColumn();
m_headers.push_back(rowid);
m_headers.append(m_db->getTableFields(table));

m_mWhere.clear();
Expand Down Expand Up @@ -358,19 +361,16 @@ void SqliteTableModel::fetchData(unsigned int from, unsigned to)
void SqliteTableModel::buildQuery()
{
QString where;
QStringList headers;
headers.push_back("rowid");
headers.append(m_db->getTableFields(m_sTable));

if(m_mWhere.size())
{
where = "WHERE 1=1";

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

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);
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);
setQuery(sql, true);
}

Expand Down

0 comments on commit a002e67

Please sign in to comment.