Skip to content

Commit 0efcffc

Browse files
committed
Set the internal driver name
1 parent de62da9 commit 0efcffc

File tree

9 files changed

+99
-15
lines changed

9 files changed

+99
-15
lines changed

src/dpi/include/dpiEnv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Env
6666
public:
6767
// creation/termination
6868

69-
static Env * createEnv();
69+
static Env * createEnv( const string &drvName = "" );
7070

7171
virtual void terminate() = 0;
7272

src/dpi/src/dpiConnImpl.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,17 @@ void ConnImpl::initConnImpl ( bool pool, bool externalAuth,
620620
OCI_ATTR_CONNECTION_CLASS, errh_ ), errh_ );
621621
}
622622

623+
/* In case of Pool, we set the driver name on poolAuth_ handle in
624+
* Pool implimentation. For non-pooled connections we set it here.
625+
*/
626+
if ( !pool && !(env_->drvName()).empty() )
627+
{
628+
ociCall ( OCIAttrSet ( (void*) auth_, OCI_HTYPE_AUTHINFO,
629+
(OraText *) ( env_->drvName() ).data (),
630+
( ub4 ) ( ( env_->drvName() ).length () ),
631+
OCI_ATTR_DRIVER_NAME, errh_ ), errh_);
632+
}
633+
623634
ociCall ( OCISessionGet ( envh_, errh_, &svch_, auth_, poolNmRconnStr,
624635
( ub4 ) nameLen, NULL, 0, NULL, NULL, NULL,
625636
mode ), errh_ );

src/dpi/src/dpiEnv.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ Env::~Env()
8686
nothing
8787
*/
8888

89-
Env * Env::createEnv()
89+
Env * Env::createEnv( const string & drvName )
9090
{
91-
return EnvImpl::createEnvImpl();
91+
return EnvImpl::createEnvImpl( drvName );
9292
}
9393

9494

src/dpi/src/dpiEnvImpl.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
#endif
5555

5656

57-
5857
/*---------------------------------------------------------------------------
5958
PRIVATE CONSTANTS
6059
---------------------------------------------------------------------------*/
@@ -88,11 +87,12 @@ static const int kStmtCacheSize = 60;
8887
8988
*/
9089

91-
EnvImpl::EnvImpl()
90+
EnvImpl::EnvImpl( const string & drvName )
9291

9392
try : envh_(NULL), poolMax_(kPoolMax), poolMin_(kPoolMin),
9493
poolIncrement_(kPoolIncrement), poolTimeout_(kPoolTimeout),
95-
externalAuth_(false), stmtCacheSize_(kStmtCacheSize)
94+
externalAuth_(false), stmtCacheSize_(kStmtCacheSize),
95+
drvName_(drvName)
9696
{
9797

9898
sword rc = OCIEnvNlsCreate (&envh_, OCI_THREADED | OCI_OBJECT, NULL, NULL,
@@ -151,9 +151,9 @@ EnvImpl::~EnvImpl()
151151
nothing
152152
*/
153153

154-
EnvImpl * EnvImpl::createEnvImpl()
154+
EnvImpl * EnvImpl::createEnvImpl( const string & drvName )
155155
{
156-
return new EnvImpl();
156+
return new EnvImpl( drvName );
157157
}
158158

159159

@@ -354,6 +354,27 @@ unsigned int EnvImpl::poolTimeout() const
354354
}
355355

356356

357+
358+
/*****************************************************************************/
359+
/*
360+
DESCRIPTION
361+
Get the driver name
362+
363+
PARAMETERS:
364+
none
365+
366+
RETURNS:
367+
driver name
368+
369+
NOTES:
370+
371+
*/
372+
373+
const string & EnvImpl::drvName()
374+
{
375+
return drvName_;
376+
}
377+
357378
/*****************************************************************************/
358379
/*
359380
DESCRIPTION
@@ -759,7 +780,5 @@ DpiHandle * EnvImpl::envHandle() const
759780
return (DpiHandle *)envh_;
760781
}
761782

762-
763-
764783
/* end of file dpiEnvImpl.cpp */
765784

src/dpi/src/dpiEnvImpl.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ class EnvImpl : public Env
6262
{
6363
public:
6464
// creation/termination
65-
EnvImpl();
65+
EnvImpl( const string & drvName = "" );
6666

6767
virtual ~EnvImpl();
6868

69-
static EnvImpl * createEnvImpl();
69+
static EnvImpl * createEnvImpl( const string & drvName = "" );
7070

7171
virtual void terminate();
7272

@@ -83,6 +83,8 @@ class EnvImpl : public Env
8383
virtual void poolTimeout(unsigned int poolTimeout);
8484
virtual unsigned int poolTimeout() const;
8585

86+
virtual const string & drvName();
87+
8688
virtual void externalAuth(bool externalAuth);
8789
virtual bool externalAuth() const;
8890

@@ -137,10 +139,11 @@ class EnvImpl : public Env
137139
unsigned int poolIncrement_; // pool increment
138140
unsigned int poolTimeout_; // pool timeout
139141

140-
bool externalAuth_; // doing external authentication
142+
bool externalAuth_; // doing external authentication
141143
bool isEventEnabled_; // EVENTS are enabled
142144

143145
unsigned int stmtCacheSize_; // statement cache size
146+
string drvName_; // driver name
144147

145148
};
146149

src/dpi/src/dpiPoolImpl.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ PoolImpl::PoolImpl(EnvImpl *env, OCIEnv *envh,
8383
int poolMin, int poolIncrement,
8484
int poolTimeout, bool externalAuth, int stmtCacheSize)
8585
try : env_(env), externalAuth_(externalAuth), envh_(envh), errh_(NULL),
86-
spoolh_(NULL), poolName_(NULL)
86+
spoolh_(NULL), poolName_(NULL), poolAuth_(NULL)
8787
{
8888
ub4 mode = externalAuth ? OCI_DEFAULT : OCI_SPC_HOMOGENEOUS;
8989
void *errh = NULL;
9090
void *spoolh = NULL;
91+
void *poolAuth = NULL;
9192

9293
unsigned char spoolMode = OCI_SPOOL_ATTRVAL_NOWAIT; // spoolMode is a ub1
9394

@@ -102,6 +103,22 @@ PoolImpl::PoolImpl(EnvImpl *env, OCIEnv *envh,
102103
OCI_HTYPE_SPOOL, 0, (dvoid **)0), errh_);
103104
spoolh_ = ( OCISPool * ) spoolh;
104105

106+
ociCall ( OCIHandleAlloc ( ( void * ) envh_, ( dvoid ** ) &poolAuth,
107+
OCI_HTYPE_AUTHINFO, 0, ( dvoid ** ) 0 ), errh_ );
108+
109+
poolAuth_ = ( OCIAuthInfo *) poolAuth;
110+
111+
if ( !(env_->drvName()).empty() )
112+
{
113+
ociCall ( OCIAttrSet ( ( void * ) poolAuth_, OCI_HTYPE_AUTHINFO,
114+
( OraText * ) ( env_->drvName() ).data (),
115+
( ub4 ) ( ( env_->drvName() ).length () ),
116+
OCI_ATTR_DRIVER_NAME, errh_ ), errh_ );
117+
}
118+
119+
ociCall ( OCIAttrSet ( spoolh_, OCI_HTYPE_SPOOL, poolAuth_, 0,
120+
OCI_ATTR_SPOOL_AUTH, errh_ ), errh_ );
121+
105122
ociCall(OCISessionPoolCreate(envh_, errh_, spoolh_,
106123
&poolName_, &poolNameLen_,
107124
(OraText *)connString.data (),
@@ -120,6 +137,7 @@ PoolImpl::PoolImpl(EnvImpl *env, OCIEnv *envh,
120137
ociCall (OCIAttrSet (spoolh_, OCI_HTYPE_SPOOL, &spoolMode,
121138
sizeof (spoolMode), OCI_ATTR_SPOOL_GETMODE, errh_ ),
122139
errh_ ) ;
140+
123141
}
124142

125143
catch (...)
@@ -349,6 +367,12 @@ void PoolImpl::releaseConnection(ConnImpl *conn)
349367

350368
void PoolImpl::cleanup()
351369
{
370+
if ( poolAuth_ )
371+
{
372+
OCIHandleFree (poolAuth_, OCI_HTYPE_AUTHINFO );
373+
poolAuth_ = NULL;
374+
}
375+
352376
if (poolName_)
353377
{
354378
// Ignore errors thrown.

src/dpi/src/dpiPoolImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class PoolImpl : public SPool
9191
OCISPool *spoolh_; // OCI session pool handle
9292
OraText *poolName_; // pool name
9393
ub4 poolNameLen_; // pool name length
94+
OCIAuthInfo *poolAuth_; // pool Auth handle
9495
};
9596

9697

src/njs/src/njsOracle.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include "njsResultSet.h"
5757
#include "njsMessages.h"
5858
#include "njsIntLob.h"
59+
#include <sstream>
5960
//peristent Oracledb class handle
6061
Nan::Persistent<FunctionTemplate> Oracledb::oracledbTemplate_s;
6162

@@ -68,14 +69,16 @@ Nan::Persistent<FunctionTemplate> Oracledb::oracledbTemplate_s;
6869
#define NJS_PREFETCH_ROWS 100
6970
#define NJS_LOB_PREFETCH_SIZE 16384
7071

72+
#define NJS_DRIVERNAME_PREFIX "node-oracledb"
73+
7174
/*****************************************************************************/
7275
/*
7376
DESCRIPTION
7477
Constructor for the Oracledb class.
7578
*/
7679
Oracledb::Oracledb()
7780
{
78-
dpienv_ = dpi::Env::createEnv();
81+
dpienv_ = dpi::Env::createEnv( driverName() );
7982
outFormat_ = ROWS_ARRAY;
8083
maxRows_ = NJS_MAX_ROWS;
8184
autoCommit_ = false;
@@ -111,6 +114,26 @@ Oracledb::~Oracledb()
111114
}
112115
}
113116

117+
/*
118+
* DESCRIPTION
119+
* Compose the driver name using the constants NJS_DRIVERNAME_PREFIX,
120+
* NJS_NODE_ORACLEDB_MAJOR, NJS_NODE_ORACLEDB_MINOR and
121+
* NJS_NODE_ORACLEDB_PATCH
122+
*/
123+
const string Oracledb::driverName() const
124+
{
125+
stringstream strm;
126+
127+
strm << NJS_DRIVERNAME_PREFIX << " : "; //append prefix
128+
strm << NJS_NODE_ORACLEDB_MAJOR; //append Mjor version
129+
strm << ".";
130+
strm << NJS_NODE_ORACLEDB_MINOR; //append Minor version
131+
strm << ".";
132+
strm << NJS_NODE_ORACLEDB_PATCH; //append Patch version
133+
134+
return strm.str();
135+
}
136+
114137
/*****************************************************************************/
115138
/*
116139
DESCRIPTION

src/njs/src/njsOracle.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ using namespace v8;
7777
(NJS_NODE_ORACLEDB_MINOR * 100) + \
7878
(NJS_NODE_ORACLEDB_PATCH) )
7979

80+
8081
class Oracledb: public Nan::ObjectWrap
8182
{
8283
public:
@@ -104,6 +105,8 @@ class Oracledb: public Nan::ObjectWrap
104105
{ return fetchAsStringTypesCount_ ; }
105106

106107
private:
108+
const string driverName() const;
109+
107110
// Define Oracledb Constructor
108111
static Nan::Persistent<FunctionTemplate> oracledbTemplate_s;
109112

0 commit comments

Comments
 (0)