Skip to content

Commit

Permalink
sql: use _rowid_ instead of rowid
Browse files Browse the repository at this point in the history
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
rp- committed Aug 22, 2014
1 parent 3b907df commit 55678bb
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/EditTableDialog.cpp
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions src/sqlitedb.cpp
Original file line number Diff line number Diff line change
@@ -436,7 +436,7 @@ bool DBBrowserDB::executeMultiSQL(const QString& statement, bool dirty, bool log

bool DBBrowserDB::getRow(const QString& sTableName, int rowid, QList<QByteArray>& 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();
2 changes: 1 addition & 1 deletion src/sqlitetypes.cpp
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ bool Field::isInteger() const
void Table::clear()
{
m_fields.clear();
m_rowidColumn = "rowid";
m_rowidColumn = "_rowid_";
}

Table::~Table()
2 changes: 1 addition & 1 deletion src/sqlitetypes.h
Original file line number Diff line number Diff line change
@@ -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; }

0 comments on commit 55678bb

Please sign in to comment.