SQLite Notifier has no table information #1687 (#2540)

This commit is contained in:
Aleksandar Fabijanic 2018-11-13 07:23:37 -06:00 committed by GitHub
parent 9f53d07d4c
commit 8d95644bad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 16 deletions

View File

@ -129,6 +129,12 @@ public:
/// Equality operator. Compares value, row and database handles and
/// returns true iff all are equal.
const std::string& getTable() const;
/// Returns the table name.
void setTable(const std::string& table);
/// Sets the row number.
Poco::Int64 getRow() const;
/// Returns the row number.
@ -151,8 +157,9 @@ private:
Notifier& operator=(const Notifier&);
const Session& _session;
Poco::Dynamic::Var _value;
std::string _table;
Poco::Int64 _row;
Poco::Dynamic::Var _value;
EnabledEventType _enabledEvents;
Poco::Mutex _mutex;
};
@ -170,6 +177,19 @@ inline bool Notifier::operator == (const Notifier& other) const
}
inline const std::string& Notifier::getTable() const
{
return _table;
}
inline void Notifier::setTable(const std::string& table)
/// Sets the row number.
{
_table = table;
}
inline Poco::Int64 Notifier::getRow() const
{
return _row;
@ -177,7 +197,6 @@ inline Poco::Int64 Notifier::getRow() const
inline void Notifier::setRow(Poco::Int64 row)
/// Sets the row number.
{
_row = row;
}

View File

@ -23,9 +23,7 @@ namespace SQLite {
Notifier::Notifier(const Session& session, EnabledEventType enabled):
_session(session),
_row(),
_enabledEvents()
_session(session)
{
if (enabled & SQLITE_NOTIFY_UPDATE) enableUpdate();
if (enabled & SQLITE_NOTIFY_COMMIT) enableCommit();
@ -35,9 +33,7 @@ Notifier::Notifier(const Session& session, EnabledEventType enabled):
Notifier::Notifier(const Session& session, const Any& value, EnabledEventType enabled):
_session(session),
_value(value),
_row(),
_enabledEvents()
_value(value)
{
if (enabled & SQLITE_NOTIFY_UPDATE) enableUpdate();
if (enabled & SQLITE_NOTIFY_COMMIT) enableCommit();
@ -158,18 +154,22 @@ void Notifier::sqliteUpdateCallbackFn(void* pVal, int opCode, const char* pDB, c
{
poco_check_ptr(pVal);
Notifier* pV = reinterpret_cast<Notifier*>(pVal);
if (opCode == Utility::OPERATION_INSERT)
{
pV->_table = pTable;
pV->_row = row;
pV->insert.notify(pV);
}
else if (opCode == Utility::OPERATION_UPDATE)
{
pV->_table = pTable;
pV->_row = row;
pV->update.notify(pV);
}
else if (opCode == Utility::OPERATION_DELETE)
{
pV->_table = pTable;
pV->_row = row;
pV->erase.notify(pV);
}

View File

@ -1939,13 +1939,13 @@ void SQLiteTest::testInternalExtraction()
assertTrue (3 == rset2.columnCount());
assertTrue (4 == rset2.rowCount());
Int32 a = rset.value<Int64>(0,2);
Int32 a = static_cast<Int32>(rset.value<Int64>(0,2));
assertTrue (3 == a);
int c = rset2.value(0);
assertTrue (1 == c);
Int32 b = rset2.value<Int64>("InT0",2);
Int32 b = static_cast<Int32>(rset2.value<Int64>("InT0",2));
assertTrue (3 == b);
double d = rset.value<double>(1,0);
@ -2517,7 +2517,7 @@ void SQLiteTest::testBindingCount()
tmp << "CREATE TABLE Ints (int0 INTEGER, int1 INTEGER, int2 INTEGER)", now;
try { tmp << "INSERT INTO Ints VALUES (?,?,?)", bind(42), bind(42), now; fail("must fail"); }
catch (ParameterCountMismatchException& ex) { }
catch (ParameterCountMismatchException&) { }
}
@ -2880,6 +2880,7 @@ void SQLiteTest::testNotifier()
session << "INSERT INTO PERSON VALUES('Simpson', 'Homer', 'Springfield', 42)", now;
assertTrue (_insertCounter == 3);
assertTrue (notifier.getRow() == 3);
assertTrue (notifier.getTable() == "Person");
session << "UPDATE PERSON SET Age = 11 WHERE FirstName = 'Bart'", now;
assertTrue (_updateCounter == 1);
@ -2935,7 +2936,7 @@ void SQLiteTest::testNotifier()
void SQLiteTest::onInsert(const void* pSender)
{
Notifier* pN = reinterpret_cast<Notifier*>(const_cast<void*>(pSender));
std::cout << "onInsert, row:" << pN->getRow() << std::endl;
std::cout << "onInsert, table:" << pN->getTable() << ", row:" << pN->getRow() << std::endl;
++_insertCounter;
}
@ -2943,7 +2944,7 @@ void SQLiteTest::onInsert(const void* pSender)
void SQLiteTest::onUpdate(const void* pSender)
{
Notifier* pN = reinterpret_cast<Notifier*>(const_cast<void*>(pSender));
std::cout << "onUpdate, row:" << pN->getRow() << std::endl;
std::cout << "onUpdate, table:" << pN->getTable() << ", row:" << pN->getRow() << std::endl;
++_updateCounter;
}
@ -2951,7 +2952,7 @@ void SQLiteTest::onUpdate(const void* pSender)
void SQLiteTest::onDelete(const void* pSender)
{
Notifier* pN = reinterpret_cast<Notifier*>(const_cast<void*>(pSender));
std::cout << "onDelete, row:" << pN->getRow() << std::endl;
std::cout << "onDelete, table:" << pN->getTable() << ", row:" << pN->getRow() << std::endl;
++_deleteCounter;
}
@ -2959,7 +2960,7 @@ void SQLiteTest::onDelete(const void* pSender)
void SQLiteTest::onCommit(const void* pSender)
{
Notifier* pN = reinterpret_cast<Notifier*>(const_cast<void*>(pSender));
std::cout << "onCommit, row:" << pN->getRow() << std::endl;
std::cout << "onCommit, table:" << pN->getTable() << ", row:" << pN->getRow() << std::endl;
++_commitCounter;
}
@ -2967,7 +2968,7 @@ void SQLiteTest::onCommit(const void* pSender)
void SQLiteTest::onRollback(const void* pSender)
{
Notifier* pN = reinterpret_cast<Notifier*>(const_cast<void*>(pSender));
std::cout << "onRollback, row:" << pN->getRow() << std::endl;
std::cout << "onRollback, table:" << pN->getTable() << ", row:" << pN->getRow() << std::endl;
++_rollbackCounter;
}