Skip to content

Commit d3bc2cd

Browse files
committed
DPI changes (charset/ncharset settable, heterogeneous pool, SYSDBA connections, session tagging). These changes are not exposed in node-oracledb
1 parent 7650d08 commit d3bc2cd

File tree

13 files changed

+256
-72
lines changed

13 files changed

+256
-72
lines changed

src/dpi/include/dpiConn.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ namespace dpi
4646
/*---------------------------------------------------------------------------
4747
PUBLIC CONSTANTS
4848
---------------------------------------------------------------------------*/
49+
// Enumeration for Database Privileges
50+
typedef enum
51+
{
52+
dbPrivNONE = 0, // None specified
53+
dbPrivSYSDBA, // SYSDBA
54+
} DBPrivileges;
55+
56+
4957

5058
/*---------------------------------------------------------------------------
5159
PUBLIC TYPES
@@ -58,7 +66,7 @@ class Conn
5866
public:
5967
// termination
6068

61-
virtual void release() = 0;
69+
virtual void release( const string &tag = "", boolean retag = false ) = 0;
6270

6371
// properties
6472
virtual void stmtCacheSize(unsigned int stmtCacheSize) = 0;
@@ -75,6 +83,10 @@ class Conn
7583

7684
virtual void action(const string &action) = 0;
7785

86+
// In case of pooled-connections & tagged sessions, did we get session
87+
// with provided Tag
88+
virtual boolean sameTag () = 0;
89+
7890
// methods
7991
virtual Stmt* getStmt (const string &sql="") = 0;
8092

src/dpi/include/dpiEnv.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ class Env
6666
public:
6767
// creation/termination
6868

69-
static Env * createEnv( const string &drvName = "" );
69+
static Env * createEnv( const string &drvName,
70+
unsigned int charset = 0,
71+
unsigned int ncharset = 0);
7072

7173
virtual void terminate() = 0;
7274

@@ -86,6 +88,8 @@ class Env
8688
virtual void externalAuth(bool externalAuth) = 0;
8789
virtual bool externalAuth() const = 0;
8890

91+
virtual unsigned int dbcharset () const = 0;
92+
virtual unsigned int dbncharset () const = 0 ;
8993

9094
// methods
9195
virtual SPool * createPool(const string &user, const string &password,
@@ -94,17 +98,20 @@ class Env
9498
int poolIncrement = -1,
9599
int poolTimeout = -1,
96100
int stmtCacheSize = -1,
97-
bool externalAuth = false) = 0;
101+
bool externalAuth = false,
102+
bool homogeneous = true ) = 0;
98103

99-
virtual Conn * getConnection(const string &user, const string &password,
104+
virtual Conn * getConnection(const string &user,
105+
const string &password,
100106
const string &connString,
101107
int stmtCacheSize,
102108
const string &connClass = "",
103-
bool externalAuth = false) = 0;
109+
bool externalAuth = false,
110+
DBPrivileges dbpriv = dbPrivNONE ) = 0;
104111

105112
// DateTime array
106113
virtual DateTimeArray * getDateTimeArray( OCIError *errh ) const = 0;
107-
virtual void releaseDateTimeArray ( DateTimeArray *arr ) const = 0;
114+
virtual void releaseDateTimeArray ( DateTimeArray *arr ) const =0;
108115

109116
// handle and descriptor methods
110117
virtual DpiHandle * allocHandle(HandleType handleType) = 0;

src/dpi/include/dpiException.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ enum DpiError // error type
5050
DpiErrInvalidState,
5151
DpiErrUninitialized,
5252
DpiErrExtAuth,
53-
DpiOciInvalidHandle,
54-
DpiErrMemAllocFail,
55-
DpiErrNullValue,
53+
DpiOciInvalidHandle, // "Invalid OCI Handle/Descriptor or invalid parameter for OCI handle/descriptor allocation call"
54+
DpiErrMemAllocFail, // "Memory allocation failed"
55+
DpiErrNullValue, // "Unexpected NULL value"
5656
};
5757

5858

src/dpi/include/dpiPool.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ class SPool
5959

6060

6161
// methods
62-
virtual Conn * getConnection( const std::string &connClass = "" ) = 0;
62+
virtual Conn * getConnection( const std::string &connClass = "",
63+
const std::string &username = "",
64+
const std::string &password = "",
65+
const std::string &tag = "",
66+
const boolean any = false,
67+
const DBPrivileges dbPriv = dbPrivNONE ) = 0;
6368

6469

6570
protected:

src/dpi/src/dpiConnImpl.cpp

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ using namespace std;
7373
user - userid
7474
password - password
7575
connString - connect string
76+
connClass - DRCP Connection class string
77+
dbPriv - DB Privileges (SYSDBA or none).
7678
7779
RETURNS:
7880
nothing
@@ -81,16 +83,19 @@ using namespace std;
8183
ConnImpl::ConnImpl(EnvImpl *env, OCIEnv *envh, bool externalAuth,
8284
unsigned int stmtCacheSize,
8385
const string &user, const string &password,
84-
const string &connString, const string &connClass)
86+
const string &connString, const string &connClass,
87+
DBPrivileges dbPriv)
8588

8689
try : env_(env), pool_(NULL),
8790
envh_(envh), errh_(NULL), auth_(NULL), svch_(NULL), sessh_(NULL),
88-
hasTxn_(false), srvh_(NULL), dropConn_(false)
91+
hasTxn_(false), srvh_(NULL), dropConn_(false), tag_(""),
92+
retag_(false), sameTag_ (false)
8993
{
9094

9195
this->initConnImpl ( false, externalAuth, connClass,
9296
( OraText * ) connString.data (),
93-
( ub4 ) connString.length (), user, password );
97+
( ub4 ) connString.length (), user, password, "",
98+
false, dbPriv );
9499

95100
this->stmtCacheSize(stmtCacheSize);
96101
}
@@ -113,25 +118,33 @@ catch (...)
113118
poolName - name of the pool
114119
poolNameLen - length of pool name
115120
connectionClass - connection class.
121+
user - username in case of non-homogenous pool
122+
password - password in case of non-homogenous pool
123+
tag - session tag name
124+
matchAny - Match Tag name as MATCHANY or EXACT
125+
dbPriv - DB privileges (SYSDBA or none).
116126
117127
RETURNS:
118128
nothing
119129
120130
NOTES:
121131
This constructor to be used in session-pool scenarios.
132+
For homogeneous pool, user, password should be empty string.
122133
*/
123134

124135
ConnImpl::ConnImpl(PoolImpl *pool, OCIEnv *envh, bool externalAuth,
125-
OraText *poolName, ub4 poolNameLen, const string& connClass
126-
)
136+
OraText *poolName, ub4 poolNameLen, const string& connClass,
137+
const string &user, const string &password,
138+
const string &tag, const boolean matchAny,
139+
const DBPrivileges dbPriv )
127140

128141
try : env_(NULL), pool_(pool),
129142
envh_(envh), errh_(NULL), auth_(NULL),
130143
svch_(NULL), sessh_(NULL), hasTxn_(false), srvh_(NULL),
131-
dropConn_(false)
144+
dropConn_(false), tag_ (""), retag_ (false), sameTag_(false)
132145
{
133146
this->initConnImpl ( true, externalAuth, connClass, poolName, poolNameLen,
134-
"", "" );
147+
user, password, tag, matchAny, dbPriv );
135148
}
136149

137150
catch (...)
@@ -169,7 +182,8 @@ ConnImpl::~ConnImpl()
169182
Release the connection.
170183
171184
PARAMETERS:
172-
none
185+
tag - session tag name
186+
retag - tagCLRTAG, tagNONE
173187
174188
RETURNS:
175189
nothing
@@ -178,7 +192,7 @@ ConnImpl::~ConnImpl()
178192
179193
*/
180194

181-
void ConnImpl::release()
195+
void ConnImpl::release( const string &tag, boolean retag )
182196
{
183197
#if OCI_MAJOR_VERSION >= 12
184198
ociCall(OCIAttrGet(sessh_, OCI_HTYPE_SESSION, &hasTxn_, NULL,
@@ -188,6 +202,13 @@ void ConnImpl::release()
188202
if(hasTxn_)
189203
rollback();
190204

205+
retag_ = retag; /* for later use */
206+
207+
if ( tag.length () > 0 )
208+
{
209+
tag_ = tag;
210+
}
211+
191212
if (pool_)
192213
pool_->releaseConnection(this);
193214
else if (env_)
@@ -564,14 +585,18 @@ unsigned int ConnImpl::getServerVersion ()
564585
poolNmRconnStr - poolName or connectString
565586
user - userid in case of non-pool scenario
566587
password - password in case of non-pool scenario
588+
tag - session tag name
589+
any - Match session tag name as MATCHANY or MATCHEXACT
590+
dbPriv - DB Privileges (SYSDBA or none)
567591
568592
RETURNS:
569593
nothing
570594
*/
571595

572596
void ConnImpl::initConnImpl ( bool pool, bool externalAuth,
573597
const string& connClass, OraText *poolNmRconnStr,
574-
ub4 nameLen, const string &user, const string &password )
598+
ub4 nameLen, const string &user, const string &password,
599+
const string &tag, const boolean any, DBPrivileges dbPriv )
575600
{
576601
ub4 mode = OCI_DEFAULT;
577602
ub2 csid = 0;
@@ -611,6 +636,18 @@ void ConnImpl::initConnImpl ( bool pool, bool externalAuth,
611636
OCI_ATTR_PASSWORD, errh_ ), errh_ );
612637
}
613638

639+
switch ( dbPriv )
640+
{
641+
case dbPrivSYSDBA:
642+
mode |= OCI_SESSGET_SYSDBA;
643+
break;
644+
645+
case dbPrivNONE:
646+
default:
647+
break;
648+
}
649+
650+
614651
// If connection class provided, set it on auth handle
615652
if ( connClass.length () )
616653
{
@@ -631,8 +668,25 @@ void ConnImpl::initConnImpl ( bool pool, bool externalAuth,
631668
OCI_ATTR_DRIVER_NAME, errh_ ), errh_);
632669
}
633670

671+
/*
672+
* Applicable only on Pooled sessions - attempts to return a session with
673+
* specified tag
674+
*
675+
* If any is false - then a session with a different tag is never returned
676+
* if any is true - if such a session not available, available untagged
677+
* if no untagged is available, then any tagged session
678+
* is returned. All returned sessions are authenticated.
679+
*
680+
* sameTag_ flag will be true if such a tagged session was returned
681+
* false otherwise.
682+
*/
683+
if ( pool && any )
684+
{
685+
mode |= OCI_SESSGET_SPOOL_MATCHANY;
686+
}
687+
634688
ociCall ( OCISessionGet ( envh_, errh_, &svch_, auth_, poolNmRconnStr,
635-
( ub4 ) nameLen, NULL, 0, NULL, NULL, NULL,
689+
( ub4 ) nameLen, NULL, 0, NULL, NULL, &sameTag_,
636690
mode ), errh_ );
637691

638692
ociCall ( OCIAttrGet ( svch_, OCI_HTYPE_SVCCTX, &sessh_, 0,
@@ -686,7 +740,21 @@ void ConnImpl::cleanup()
686740
relMode |= OCI_SESSRLS_DROPSESS;
687741
}
688742

689-
OCISessionRelease(svch_, errh_, NULL, 0, relMode);
743+
// Re-tagging
744+
if( retag_ )
745+
{
746+
relMode |= OCI_SESSRLS_RETAG;
747+
}
748+
749+
/*
750+
* RETAG behavior: (same as in OCI).
751+
* if retag_ is TRUE & tag_ length is non-zero, then tag_ is set
752+
* if retag_ is TRUE & tag_ length is zero, then session-tag is cleared
753+
* if retag_ is FALSE, then no action taken(if tag_ given will be ignored)
754+
*/
755+
756+
OCISessionRelease(svch_, errh_, (OraText *)tag_.c_str (),
757+
(ub4) tag_.length (), relMode);
690758
svch_ = NULL;
691759
}
692760

src/dpi/src/dpiConnImpl.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,17 @@ class ConnImpl : public Conn
7676
unsigned int stmtCacheSize,
7777
const string &user, const string &password,
7878
const string &connString,
79-
const string &connClass);
79+
const string &connClass,
80+
DBPrivileges dbPriv );
8081

8182
ConnImpl(PoolImpl *pool, OCIEnv *envh, bool externalAuth,
82-
OraText *poolName, ub4 poolNameLen, const string &connClass
83-
);
83+
OraText *poolName, ub4 poolNameLen, const string &connClass,
84+
const string &user, const string &password, const string &tag,
85+
const boolean any, const DBPrivileges dbPriv );
8486

8587
virtual ~ConnImpl();
8688

87-
virtual void release();
89+
virtual void release( const string &tag, boolean retag);
8890

8991
// interface properties
9092
virtual void stmtCacheSize(unsigned int stmtCacheSize);
@@ -98,6 +100,10 @@ class ConnImpl : public Conn
98100
virtual void module(const string &module);
99101

100102
virtual void action(const string &action);
103+
104+
// Connection with requested tag returned or not?
105+
virtual boolean sameTag () { return sameTag_; }
106+
101107
virtual int getByteExpansionRatio ();
102108

103109
// interface methods
@@ -136,7 +142,8 @@ class ConnImpl : public Conn
136142

137143
void initConnImpl( bool pool, bool externalAuth, const string& connClass,
138144
OraText *poolNmRconnStr, ub4 nameLen,
139-
const string &user, const string &password );
145+
const string &user, const string &password,
146+
const string &tag, boolean any, DBPrivileges dbPriv );
140147

141148
int getCsRatio ( ub2 csid )
142149
{
@@ -159,6 +166,9 @@ class ConnImpl : public Conn
159166
int csratio_; // character expansion ratio
160167
OCIServer *srvh_; // OCI server handle
161168
bool dropConn_; // Set flag in case of unusable connection
169+
string tag_; // Session tag
170+
boolean retag_; // How to retag? (leave it, update, clear)
171+
boolean sameTag_; // connection is of same tag as requested?
162172
};
163173

164174

src/dpi/src/dpiEnv.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,17 @@ Env::~Env()
8080
Create the Env object.
8181
8282
PARAMETERS:
83-
none
83+
drvName - driver name
84+
charset - charset id
85+
ncharset - ncharset id
8486
8587
RETURNS:
8688
nothing
8789
*/
88-
89-
Env * Env::createEnv( const string & drvName )
90+
Env * Env::createEnv( const string& drvName,
91+
unsigned int charset, unsigned int ncharset)
9092
{
91-
return EnvImpl::createEnvImpl( drvName );
93+
return EnvImpl::createEnvImpl( drvName, charset, ncharset );
9294
}
9395

9496

0 commit comments

Comments
 (0)