OCILIB (C and C++ Driver for Oracle)  4.7.6
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-2023 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  AcquireTransient
39  (
40  pSubcription,
41  Environment::GetEnvironmentHandle()
42  );
43 }
44 
45 inline void Subscription::Register(const Connection &connection, const ostring& name, ChangeTypes changeTypes, NotifyHandlerProc handler, unsigned int port, unsigned int timeout)
46 {
47  AcquireAllocated
48  (
50  (
52  (
53  connection, name.c_str(), changeTypes.GetValues(),
54  static_cast<POCI_NOTIFY> (handler != nullptr ? Environment::NotifyHandler : nullptr),
55  port, timeout
56  )
57  ),
58  Environment::GetEnvironmentHandle()
59  );
60 
61  Environment::SetUserCallback<Subscription::NotifyHandlerProc>(static_cast<OCI_Subscription*>(*this), handler);
62 }
63 
65 {
66  Environment::SetUserCallback<Subscription::NotifyHandlerProc>(static_cast<OCI_Subscription*>(*this), nullptr);
67 
68  Release();
69 }
70 
71 inline void Subscription::Watch(const ostring& sql)
72 {
74 
75  st.Execute(sql);
76 
78 }
79 
81 {
83 }
84 
85 inline unsigned int Subscription::GetTimeout() const
86 {
88 }
89 
90 inline unsigned int Subscription::GetPort() const
91 {
92  return core::Check(OCI_SubscriptionGetPort(*this));
93 }
94 
96 {
97  return Connection
98  (
100  Environment::GetEnvironmentHandle()
101  );
102 }
103 
104 }
A connection or session with a specific database.
Definition: types.hpp:1580
Object used for executing SQL or PL/SQL statement and returning the produced results.
Definition: types.hpp:5559
void Execute(const ostring &sql)
Prepare and execute a SQL statement or PL/SQL block.
Definition: Statement.hpp:115
void Watch(const ostring &sql)
Add a SQL query to monitor.
void Unregister()
Unregister a previously registered notification.
Subscription()
Default constructor.
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.
Connection GetConnection() const
Return the connection associated with a subscription handle.
unsigned int GetTimeout() const
Return the timeout of the given registered subscription.
ostring GetName() const
Return the name of the given registered subscription.
unsigned int GetPort() const
Return the port used by the notification.
Template Flags template class providing some type safety to some extends for manipulating flags set v...
Definition: core.hpp:148
void(* POCI_NOTIFY)(OCI_Event *event)
Database Change Notification User callback prototype.
Definition: types.h:540
struct OCI_Subscription OCI_Subscription
OCILIB encapsulation of Oracle DCN notification.
Definition: types.h:430
OCI_SYM_PUBLIC const otext *OCI_API OCI_SubscriptionGetName(OCI_Subscription *sub)
Return the name of the given registered subscription.
OCI_SYM_PUBLIC unsigned int OCI_API OCI_SubscriptionGetTimeout(OCI_Subscription *sub)
Return the timeout 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.
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.
OCI_SYM_PUBLIC boolean OCI_API OCI_SubscriptionAddStatement(OCI_Subscription *sub, OCI_Statement *stmt)
Add a statement to the notification to monitor.
OCI_SYM_PUBLIC unsigned int OCI_API OCI_SubscriptionGetPort(OCI_Subscription *sub)
Return the port used by the notification.
static T Check(T result)
Internal usage. Checks if the last OCILIB function call has raised an error. If so,...
Definition: Utils.hpp:53
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
OCILIB ++ Namespace.
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