Add SQLite Notifier table name getter (#1691)

* Add table name in SQLite Notifier

* Converted spaces to tabs to conform to Poco coding style

* One more spaces to tab change

* Added table compare to Notifier equality operator

* Returning const ref instead of string copy in Notifier getTable
This commit is contained in:
petko 2017-04-17 20:46:57 +03:00 committed by Aleksandar Fabijanic
parent 61f0bb2c2b
commit 3bacb6696f
3 changed files with 16 additions and 0 deletions

View File

@ -137,6 +137,9 @@ public:
void setRow(Poco::Int64 row);
/// Sets the row number.
const std::string& getTable() const;
/// Returns the table name.
const Poco::Dynamic::Var& getValue() const;
/// Returns the value.
@ -155,6 +158,7 @@ private:
const Session& _session;
Poco::Dynamic::Var _value;
Poco::Int64 _row;
std::string _table;
EnabledEventType _enabledEvents;
Poco::Mutex _mutex;
};
@ -168,6 +172,7 @@ inline bool Notifier::operator == (const Notifier& other) const
{
return _value == other._value &&
_row == other._row &&
_table == other._table &&
Utility::dbHandle(_session) == Utility::dbHandle(other._session);
}
@ -178,6 +183,12 @@ inline Poco::Int64 Notifier::getRow() const
}
inline const std::string& Notifier::getTable() const
{
return _table;
}
inline void Notifier::setRow(Poco::Int64 row)
/// Sets the row number.
{

View File

@ -163,16 +163,19 @@ void Notifier::sqliteUpdateCallbackFn(void* pVal, int opCode, const char* pDB, c
if (opCode == Utility::OPERATION_INSERT)
{
pV->_row = row;
pV->_table = pTable;
pV->insert.notify(pV);
}
else if (opCode == Utility::OPERATION_UPDATE)
{
pV->_row = row;
pV->_table = pTable;
pV->update.notify(pV);
}
else if (opCode == Utility::OPERATION_DELETE)
{
pV->_row = row;
pV->_table = pTable;
pV->erase.notify(pV);
}
}

View File

@ -2886,6 +2886,8 @@ void SQLiteTest::testNotifier()
assert (_updateCounter == 3);
assert (notifier.getRow() == 3);
assert (notifier.getTable() == "Person");
notifier.setRow(0);
// SQLite optimizes DELETE so here we must have
// the WHERE clause to trigger per-row notifications