Poco::Data::SQLite

class Notifier

File Information

Library: Data/SQLite
Package: SQLite
Header: Poco/Data/SQLite/Notifier.h

Description

Notifier is a wrapper for SQLite callback calls. It supports event callbacks for insert, update, delete, commit and rollback events. While (un)registering callbacks is thread-safe, execution of the callbacks themselves are not; it is the user's responsibility to ensure the thread-safey of the functions they provide as callback target. Additionally, commit callbacks may prevent database transactions from succeeding (see sqliteCommitCallbackFn documentation for details).

There can be only one set of callbacks per session (i.e. registering a new callback automatically unregisters the previous one). All callbacks are registered and enabled at Notifier contruction time and can be disabled at a later point time.

Member Summary

Member Functions: commitEnabled, disableAll, disableCommit, disableRollback, disableUpdate, enableAll, enableCommit, enableRollback, enableUpdate, getRow, getTable, getValue, operator ==, rollbackEnabled, setRow, setTable, setValue, sqliteCommitCallbackFn, sqliteRollbackCallbackFn, sqliteUpdateCallbackFn, updateEnabled

Types

EnabledEventType

typedef unsigned char EnabledEventType;

A type definition for events-enabled bitmap.

Event

typedef Poco::BasicEvent < void > Event;

Constructors

Notifier

Notifier(
    const Session & session,
    EnabledEventType enabled = SQLITE_NOTIFY_UPDATE | SQLITE_NOTIFY_COMMIT | SQLITE_NOTIFY_ROLLBACK
);

Creates a Notifier and enables all callbacks.

Notifier

Notifier(
    const Session & session,
    const Any & value,
    EnabledEventType enabled = SQLITE_NOTIFY_UPDATE | SQLITE_NOTIFY_COMMIT | SQLITE_NOTIFY_ROLLBACK
);

Creates a Notifier, assigns the value to the internal storage and and enables all callbacks.

Destructor

~Notifier

~Notifier();

Disables all callbacks and destroys the Notifier.

Member Functions

commitEnabled

bool commitEnabled() const;

Returns true if update callbacks are enabled, false otherwise.

disableAll

bool disableAll();

Disables all callbacks.

disableCommit

bool disableCommit();

Disables commit callbacks.

disableRollback

bool disableRollback();

Disables rollback callbacks.

disableUpdate

bool disableUpdate();

Disables update callbacks.

enableAll

bool enableAll();

Enables all callbacks.

enableCommit

bool enableCommit();

Enables commit callbacks.

enableRollback

bool enableRollback();

Enables rollback callbacks.

enableUpdate

bool enableUpdate();

Enables update callbacks.

getRow inline

Poco::Int64 getRow() const;

Returns the row number.

getTable inline

const std::string & getTable() const;

Returns the table name.

getValue inline

const Poco::Dynamic::Var & getValue() const;

Returns the value.

operator == inline

bool operator == (
    const Notifier & other
) const;

Equality operator. Compares value, row and database handles and returns true iff all are equal.

rollbackEnabled

bool rollbackEnabled() const;

Returns true if rollback callbacks are enabled, false otherwise.

setRow inline

void setRow(
    Poco::Int64 row
);

Sets the row number.

setTable inline

void setTable(
    const std::string & table
);

Sets the row number.

setValue inline

template < typename T > inline void setValue(
    const T & val
);

Sets the value.

sqliteCommitCallbackFn static

static int sqliteCommitCallbackFn(
    void * pVal
);

Commit callback event dispatcher. If an exception occurs, it is catched inside this function, non-zero value is returned, which causes SQLite engine to turn commit into a rollback. Therefore, callers should check for return value - if it is zero, callback completed succesfuly and transaction was committed.

sqliteRollbackCallbackFn static

static void sqliteRollbackCallbackFn(
    void * pVal
);

Rollback callback event dispatcher.

sqliteUpdateCallbackFn static

static void sqliteUpdateCallbackFn(
    void * pVal,
    int opCode,
    const char * pDB,
    const char * pTable,
    Poco::Int64 row
);

Update callback event dispatcher. Determines the type of the event, updates the row number and triggers the event.

updateEnabled

bool updateEnabled() const;

Returns true if update callbacks are enabled, false otherwise.

Variables

SQLITE_NOTIFY_COMMIT static

static const EnabledEventType SQLITE_NOTIFY_COMMIT = 2;

SQLITE_NOTIFY_ROLLBACK static

static const EnabledEventType SQLITE_NOTIFY_ROLLBACK = 4;

SQLITE_NOTIFY_UPDATE static

static const EnabledEventType SQLITE_NOTIFY_UPDATE = 1;

commit

Event commit;

erase

Event erase;

insert

Event insert;

rollback

Event rollback;

update

Event update;