OCILIB (C and C++ Driver for Oracle)  4.7.3
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
Subscription.hpp
1 /*
2  * OCILIB - C Driver for Oracle (C Wrapper for Oracle OCI)
3  *
4  * Website: http://www.ocilib.net
5  *
6  * Copyright (c) 2007-2021 Vincent ROGIER <vince.rogier@ocilib.net>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #pragma once
22 
23 #include "ocilibcpp/types.hpp"
24 
25 // ReSharper disable CppClangTidyHicppUseEqualsDefault
26 // ReSharper disable CppClangTidyPerformanceUnnecessaryValueParam
27 
28 namespace ocilib
29 {
30 
32 {
33 
34 }
35 
36 inline Subscription::Subscription(OCI_Subscription *pSubcription)
37 {
38  Acquire(pSubcription, nullptr, nullptr, nullptr);
39 }
40 
41 inline void Subscription::Register(const Connection &connection, const ostring& name, ChangeTypes changeTypes, NotifyHandlerProc handler, unsigned int port, unsigned int timeout)
42 {
43  Acquire(core::Check(OCI_SubscriptionRegister(connection, name.c_str(), changeTypes.GetValues(),
44  static_cast<POCI_NOTIFY> (handler != nullptr ? Environment::NotifyHandler : nullptr), port, timeout)),
45  reinterpret_cast<HandleFreeFunc>(OCI_SubscriptionUnregister), nullptr, nullptr);
46 
47  Environment::SetUserCallback<Subscription::NotifyHandlerProc>(static_cast<OCI_Subscription*>(*this), handler);
48 }
49 
51 {
52  Environment::SetUserCallback<Subscription::NotifyHandlerProc>(static_cast<OCI_Subscription*>(*this), nullptr);
53 
54  Release();
55 }
56 
57 inline void Subscription::Watch(const ostring& sql)
58 {
60 
61  st.Execute(sql);
62 
64 }
65 
67 {
69 }
70 
71 inline unsigned int Subscription::GetTimeout() const
72 {
74 }
75 
76 inline unsigned int Subscription::GetPort() const
77 {
78  return core::Check(OCI_SubscriptionGetPort(*this));
79 }
80 
82 {
83  return Connection(core::Check(OCI_SubscriptionGetConnection(*this)), nullptr);
84 }
85 
86 }
OCI_SYM_PUBLIC boolean OCI_API OCI_SubscriptionAddStatement(OCI_Subscription *sub, OCI_Statement *stmt)
Add a statement to the notification to monitor.
unsigned int GetPort() const
Return the port used by the notification.
ostring GetName() const
Return the name of the given registered subscription.
OCILIB ++ Namespace.
OCI_SYM_PUBLIC OCI_Subscription *OCI_API OCI_SubscriptionRegister(OCI_Connection *con, const otext *name, unsigned int type, POCI_NOTIFY handler, unsigned int port, unsigned int timeout)
Register a notification against the given database.
Subscription()
Default constructor.
Object used for executing SQL or PL/SQL statement and returning the produced results.
Definition: types.hpp:5536
A connection or session with a specific database.
Definition: types.hpp:1563
static T Check(T result)
Internal usage. Checks if the last OCILIB function call has raised an error. If so, it raises a C++ exception using the retrieved error handle.
Definition: Utils.hpp:53
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.
struct OCI_Subscription OCI_Subscription
OCILIB encapsulation of Oracle DCN notification.
Definition: types.h:418
Template Flags template class providing some type safety to some extends for manipulating flags set v...
Definition: core.hpp:147
OCI_SYM_PUBLIC const otext *OCI_API OCI_SubscriptionGetName(OCI_Subscription *sub)
Return the name of the given registered subscription.
OCI_SYM_PUBLIC OCI_Connection *OCI_API OCI_SubscriptionGetConnection(OCI_Subscription *sub)
Return the connection handle associated with a subscription handle.
ostring MakeString(const otext *result, int size=-1)
Internal usage. Constructs a C++ string object from the given OCILIB string pointer.
Definition: Utils.hpp:65
void(* NotifyHandlerProc)(Event &evt)
User callback for subscriptions event notifications.
Definition: types.hpp:7061
OCI_SYM_PUBLIC unsigned int OCI_API OCI_SubscriptionGetTimeout(OCI_Subscription *sub)
Return the timeout of the given registered subscription.
void(* POCI_NOTIFY)(OCI_Event *event)
Database Change Notification User callback prototype.
Definition: types.h:528
unsigned int GetTimeout() const
Return the timeout of the given registered subscription.
Connection GetConnection() const
Return the connection associated with a subscription handle.
OCI_SYM_PUBLIC unsigned int OCI_API OCI_SubscriptionGetPort(OCI_Subscription *sub)
Return the port used by the notification.
OCI_SYM_PUBLIC boolean OCI_API OCI_SubscriptionUnregister(OCI_Subscription *sub)
Unregister a previously registered notification.
void Watch(const ostring &sql)
Add a SQL query to monitor.
void Execute(const ostring &sql)
Prepare and execute a SQL statement or PL/SQL block.
Definition: Statement.hpp:110
void Unregister()
Unregister a previously registered notification.
std::basic_string< otext, std::char_traits< otext >, std::allocator< otext > > ostring
string class wrapping the OCILIB otext * type and OTEXT() macros ( see Character sets ) ...
Definition: config.hpp:120