#include <iostream>
#include "ocilib.hpp"
#if defined(_WINDOWS)
#define sleep(x) Sleep(x*1000)
#else
#include <unistd.h>
#endif
#define WaitForEvents() sleep(5)
#define WaitForDatabase() sleep(60)
static std::map<unsigned int, ostring> EventTypes;
static std::map<unsigned int, ostring> ObjectEvents;
void EventHandler(
Event &evt);
void SetupNames();
int main(int argc, char* argv[])
{
SetupNames();
try
{
st.Execute("create table table1(code number)");
st.Execute("create table table2(str varchar2(10))");
sub.
Watch(
"select * from table1");
sub.
Watch(
"select * from table2");
st.Execute("alter table table1 add price number");
WaitForEvents();
st.Execute("insert into table1 values(1, 10.5)");
st.Execute("insert into table2 values('shoes')");
WaitForEvents();
st.Execute("update table1 set price = 13.5 where code = 1");
st.Execute("delete from table2 ");
WaitForEvents();
st.Execute("drop table table1");
st.Execute("drop table table2");
WaitForEvents();
WaitForDatabase();
}
catch (std::exception &ex)
{
std::cout << ex.what() << std::endl;
}
}
void SetupNames()
{
}
void EventHandler(
Event &evt)
{
std::cout <<
"** Event : " << EventTypes[evt.
GetType()] << std::endl;
{
std::cout <<
".... Object : " << evt.
GetObjectName() << std::endl;
std::cout <<
".... Action : " << ObjectEvents[evt.
GetObjectEvent()] << std::endl;
std::cout <<
".... RowID : " << evt.
GetRowID() << std::endl;
}
std::cout << std::endl;
}
void SetAutoCommit(bool enabled)
Enable or disable auto commit mode (implicit commits after every SQL execution)
static void ShutdownDatabase(const ostring &db, const ostring &user, const ostring &pwd, Environment::ShutdownFlags shutdownFlags, Environment::ShutdownMode shutdownMode, Environment::SessionFlags sessionFlags=SessionSysDba)
Shutdown a database instance.
static void StartDatabase(const ostring &db, const ostring &user, const ostring &pwd, Environment::StartFlags startFlags, Environment::StartMode startMode, Environment::SessionFlags sessionFlags=SessionSysDba, const ostring &spfile=OTEXT(""))
Start a database instance.
ostring GetRowID() const
Return the rowid of the altered database object row.
Subscription GetSubscription() const
Return the subscription that generated this event.
ostring GetObjectName() const
Return the name of the object that generated the event.
ObjectEvent GetObjectEvent() const
Return the type of operation reported by a notification.
ostring GetDatabaseName() const
Return the name of the database that generated the event.
EventType GetType() const
Return the type of event reported by a notification.
Subscription to database or objects changes.
void Watch(const ostring &sql)
Add a SQL query to monitor.
void Unregister()
Unregister a previously registered notification.
void Register(const Connection &connection, const ostring &name, ChangeTypes changeTypes, NotifyHandlerProc handler, unsigned int port=0, unsigned int timeout=0)
Register a notification against the given database.
ostring GetName() const
Return the name of the given registered subscription.