From 55678bb9450a0546835b2d86f5124e7efb0a1109 Mon Sep 17 00:00:00 2001 From: Peinthor Rene Date: Fri, 22 Aug 2014 23:21:44 +0200 Subject: [PATCH] sql: use _rowid_ instead of rowid This doesn't really solve the problem, but reduces the chance to have a nameclash with rowid, until we come up with something better we can't fully support tables with a column name _rowid_ but that should be very seldom --- src/EditTableDialog.cpp | 2 +- src/sqlitedb.cpp | 6 +++--- src/sqlitetypes.cpp | 2 +- src/sqlitetypes.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/EditTableDialog.cpp b/src/EditTableDialog.cpp index c7202f7b..26d6ae73 100644 --- a/src/EditTableDialog.cpp +++ b/src/EditTableDialog.cpp @@ -232,7 +232,7 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column) // we need to check for this case and cancel here. Maybe we can think of some way to modify the INSERT INTO ... SELECT statement // to at least replace all troublesome NULL values by the default value SqliteTableModel m(this, pdb); - m.setQuery(QString("SELECT COUNT(rowid) FROM `%1` WHERE `%2` IS NULL;").arg(curTable).arg(field->name())); + m.setQuery(QString("SELECT COUNT(_rowid_) FROM `%1` WHERE `%2` IS NULL;").arg(curTable).arg(field->name())); if(m.data(m.index(0, 0)).toInt() > 0) { // There is a NULL value, so print an error message, uncheck the combobox, and return here diff --git a/src/sqlitedb.cpp b/src/sqlitedb.cpp index 4ce6e6f0..d4b401e8 100644 --- a/src/sqlitedb.cpp +++ b/src/sqlitedb.cpp @@ -436,7 +436,7 @@ bool DBBrowserDB::executeMultiSQL(const QString& statement, bool dirty, bool log bool DBBrowserDB::getRow(const QString& sTableName, int rowid, QList& rowdata) { - QString sQuery = QString("SELECT * from %1 WHERE rowid=%2;").arg(sTableName).arg(rowid); + QString sQuery = QString("SELECT * from %1 WHERE _rowid_=%2;").arg(sTableName).arg(rowid); QByteArray utf8Query = sQuery.toUtf8(); sqlite3_stmt *stmt; bool ret = false; @@ -488,7 +488,7 @@ bool DBBrowserDB::deleteRecord(const QString& table, int rowid) bool ok = false; lastErrorMessage = QString("no error"); - QString statement = QString("DELETE FROM `%1` WHERE rowid=%2;").arg(table).arg(rowid); + QString statement = QString("DELETE FROM `%1` WHERE _rowid_=%2;").arg(table).arg(rowid); if (_db){ logSQL(statement, kLogMsg_App); @@ -510,7 +510,7 @@ bool DBBrowserDB::updateRecord(const QString& table, const QString& column, int lastErrorMessage = QString("no error"); - QString sql = QString("UPDATE `%1` SET `%2`=? WHERE rowid=%3;").arg(table).arg(column).arg(row); + QString sql = QString("UPDATE `%1` SET `%2`=? WHERE _rowid_=%3;").arg(table).arg(column).arg(row); logSQL(sql, kLogMsg_App); setRestorePoint(); diff --git a/src/sqlitetypes.cpp b/src/sqlitetypes.cpp index be674046..443eff49 100644 --- a/src/sqlitetypes.cpp +++ b/src/sqlitetypes.cpp @@ -57,7 +57,7 @@ bool Field::isInteger() const void Table::clear() { m_fields.clear(); - m_rowidColumn = "rowid"; + m_rowidColumn = "_rowid_"; } Table::~Table() diff --git a/src/sqlitetypes.h b/src/sqlitetypes.h index e2abba69..6065de47 100644 --- a/src/sqlitetypes.h +++ b/src/sqlitetypes.h @@ -72,7 +72,7 @@ typedef QVector< FieldPtr > FieldVector; class Table { public: - Table(const QString& name): m_name(name), m_rowidColumn("rowid") {} + Table(const QString& name): m_name(name), m_rowidColumn("_rowid_") {} virtual ~Table(); void setName(const QString& name) { m_name = name; }