Added oracledb.oracleClientVersion and connection.oracleServerVersion

This commit is contained in:
Christopher Jones 2015-10-15 12:46:20 +11:00
parent ad3838fa36
commit 14654e53e0
17 changed files with 300 additions and 45 deletions

View File

@ -2,6 +2,10 @@
## node-oracledb v1.3.0 (DD Mon YYYY)
- Added oracledb.oracleClientVersion property giving the version of the Oracle
client library, and connection.oracleServerVersion property giving the Oracle
Database Server version.
- BIND_IN is default when not specified.
- Fixed 11.2.0.4 DB-specific NULL output with DML RETURNING when string value is of size 4k.

View File

@ -18,7 +18,8 @@
"src/dpi/src/dpiPoolImpl.cpp",
"src/dpi/src/dpiStmtImpl.cpp",
"src/dpi/src/dpiUtils.cpp",
"src/dpi/src/dpiLob.cpp"
"src/dpi/src/dpiLob.cpp",
"src/dpi/src/dpiCommon.cpp"
],
"conditions" : [
[

View File

@ -42,14 +42,15 @@ limitations under the License.
- 3.2.4 [fetchAsString](#propdbfetchasstring)
- 3.2.5 [lobPrefetchSize](#propdblobprefetchsize)
- 3.2.6 [maxRows](#propdbmaxrows)
- 3.2.7 [outFormat](#propdboutformat)
- 3.2.8 [poolIncrement](#propdbpoolincrement)
- 3.2.9 [poolMax](#propdbpoolmax)
- 3.2.10 [poolMin](#propdbpoolmin)
- 3.2.11 [poolTimeout](#propdbpooltimeout)
- 3.2.12 [prefetchRows](#propdbprefetchrows)
- 3.2.13 [stmtCacheSize](#propdbstmtcachesize)
- 3.2.14 [version](#propdbversion)
- 3.2.7 [oracleClientVersion](#propdboracleClientVersion)
- 3.2.8 [outFormat](#propdboutformat)
- 3.2.9 [poolIncrement](#propdbpoolincrement)
- 3.2.10 [poolMax](#propdbpoolmax)
- 3.2.11 [poolMin](#propdbpoolmin)
- 3.2.12 [poolTimeout](#propdbpooltimeout)
- 3.2.13 [prefetchRows](#propdbprefetchrows)
- 3.2.14 [stmtCacheSize](#propdbstmtcachesize)
- 3.2.15 [version](#propdbversion)
- 3.3 [Oracledb Methods](#oracledbmethods)
- 3.3.1 [createPool()](#createpool)
- 3.3.2 [getConnection()](#getconnectiondb)
@ -58,7 +59,8 @@ limitations under the License.
- 4.1.1 [action](#propconnaction)
- 4.1.2 [clientId](#propconnclientid)
- 4.1.3 [module](#propconnmodule)
- 4.1.4 [stmtCacheSize](#propconnstmtcachesize)
- 4.1.4 [oracleServerVersion](#propconnoracleserverversion)
- 4.1.5 [stmtCacheSize](#propconnstmtcachesize)
- 4.2 [Connection Methods](#connectionmethods)
- 4.2.1 [break()](#break)
- 4.2.2 [commit()](#commit)
@ -504,7 +506,23 @@ var oracledb = require('oracledb');
oracledb.lobPrefetchSize = 16384;
```
#### <a name="propdboutformat"></a> 3.2.7 outFormat
#### <a name="propdboracleClientVersion"></a> 3.2.7 oracleClientVersion
```
readonly Number oracleClientVersion
```
This readonly property gives a numeric representation of the Oracle client library version.
For version *a.b.c.d.e*, this property gives the number: `(100000000 * a) + (1000000 * b) + (10000 * c) + (100 * d) + e`
##### Example
```javascript
var oracledb = require('oracledb');
console.log("Oracle client library version number is " + oracledb.oracleClientVersion);
```
#### <a name="propdboutformat"></a> 3.2.8 outFormat
```
Number outFormat
@ -534,7 +552,7 @@ var oracledb = require('oracledb');
oracledb.outFormat = oracledb.ARRAY;
```
#### <a name="propdbpoolincrement"></a> 3.2.8 poolIncrement
#### <a name="propdbpoolincrement"></a> 3.2.9 poolIncrement
```
Number poolIncrement
@ -554,7 +572,7 @@ var oracledb = require('oracledb');
oracledb.poolIncrement = 1;
```
#### <a name="propdbpoolmax"></a> 3.2.9 poolMax
#### <a name="propdbpoolmax"></a> 3.2.10 poolMax
```
Number poolMax
@ -573,7 +591,7 @@ var oracledb = require('oracledb');
oracledb.poolMax = 4;
```
#### <a name="propdbpoolmin"></a> 3.2.10 poolMin
#### <a name="propdbpoolmin"></a> 3.2.11 poolMin
```
Number poolMin
@ -593,7 +611,7 @@ var oracledb = require('oracledb');
oracledb.poolMin = 0;
```
#### <a name="propdbpooltimeout"></a> 3.2.11 poolTimeout
#### <a name="propdbpooltimeout"></a> 3.2.12 poolTimeout
```
Number poolTimeout
@ -615,7 +633,7 @@ var oracledb = require('oracledb');
oracledb.poolTimeout = 60;
```
#### <a name="propdbprefetchrows"></a> 3.2.12 prefetchRows
#### <a name="propdbprefetchrows"></a> 3.2.13 prefetchRows
```
Number prefetchRows
@ -645,7 +663,7 @@ var oracledb = require('oracledb');
oracledb.prefetchRows = 100;
```
#### <a name="propdbstmtcachesize"></a> 3.2.13 stmtCacheSize
#### <a name="propdbstmtcachesize"></a> 3.2.14 stmtCacheSize
```
Number stmtCacheSize
@ -672,12 +690,12 @@ var oracledb = require('oracledb');
oracledb.stmtCacheSize = 30;
```
#### <a name="propdbversion"></a> 3.2.14 version
#### <a name="propdbversion"></a> 3.2.15 version
```
readonly Number version
```
This readonly property gives a numeric representation of the node-oracledb's version.
This readonly property gives a numeric representation of the node-oracledb version.
For version *x.y.z*, this property gives the number: `(10000 * x) + (100 * y) + z`
##### Example
@ -994,7 +1012,16 @@ This is a write-only property. Displaying a Connection object will
show a value of `null` for this attribute. See
[End-to-end Tracing, Mid-tier Authentication, and Auditing](#endtoend).
#### <a name="propconnstmtcachesize"></a> 4.1.4 stmtCacheSize
#### <a name="propconnoracleserverversion"></a> 4.1.4 oracleServerVersion
```
readonly Number oracleServerVersion
```
This readonly property gives a numeric representation of the Oracle database version.
For version *a.b.c.d.e*, this property gives the number: `(100000000 * a) + (1000000 * b) + (10000 * c) + (100 * d) + e`
#### <a name="propconnstmtcachesize"></a> 4.1.5 stmtCacheSize
```
readonly Number stmtCacheSize

View File

@ -39,7 +39,6 @@ oracledb.getConnection(
console.error(err.message);
return;
}
console.log('Connection was successful!');
connection.release(

View File

@ -19,15 +19,51 @@
* version.js
*
* DESCRIPTION
* Shows the oracledb version attribute
* Shows the oracledb version attributes
*
*****************************************************************************/
var oracledb = require('oracledb');
var dbConfig = require('./dbconfig.js');
console.log("Driver version number is " + oracledb.version);
var addonVer, clientVer, serverVer;
var major, minor, update, port, portUpdate;
major = Math.floor(oracledb.version/10000);
minor = Math.floor(oracledb.version/100) % 100;
patch = oracledb.version % 100;
console.log("Driver version text is " + major + "." + minor + "." + patch);
addonVer = oracledb.version
major = Math.floor(addonVer / 10000);
minor = Math.floor(addonVer / 100) % 100;
update = addonVer % 100;
console.log("Node-oracledb version: " + addonVer);
console.log("Node-oracledb text format: " + major + "." + minor + "." + update);
clientVer = oracledb.oracleClientVersion;
major = Math.floor (clientVer / 100000000);
minor = Math.floor (clientVer / 1000000) % 100 ;
update = Math.floor (clientVer / 10000) % 100 ;
port = Math.floor (clientVer / 100) % 100 ;
portUpdate = clientVer % 100 ;
console.log("Oracle Client library version: " +clientVer);
console.log("Oracle Client library text format: " + major + "." + minor + "." + update + "." + port + "." + portUpdate);
oracledb.getConnection(
{
user : dbConfig.user,
password : dbConfig.password,
connectString : dbConfig.connectString
},
function(err, connection)
{
if (err) {
console.error(err.message);
return;
}
serverVer = connection.oracleServerVersion;
major = Math.floor (serverVer / 100000000);
minor = Math.floor (serverVer / 1000000) % 100 ;
update = Math.floor (serverVer / 10000) % 100 ;
port = Math.floor (serverVer / 100) % 100 ;
portUpdate = serverVer % 100 ;
console.log ("Oracle Database version: " + serverVer);
console.log("Oracle Database text format: " + major + "." + minor + "." + update + "." + port + "." + portUpdate);
});

View File

@ -56,6 +56,18 @@ enum DescriptorType
struct DpiHandle;
struct Descriptor;
/* Utiltiy class containing common functions */
class Common
{
public:
// To obtain the Oracle Client Library Version
static void clientVersion (int *majorv, int *minorv, int *patchv,
int *portv, int *portUpdv );
};
/*----------------------------------------------------------------------------
PUBLIC METHODS
----------------------------------------------------------------------------*/

View File

@ -88,6 +88,8 @@ public:
virtual DpiHandle *getErrh () = 0;
virtual unsigned int getServerVersion () = 0;
protected:
// clients cannot do new and delete
Conn(){};

View File

@ -86,6 +86,7 @@ class Env
virtual void externalAuth(bool externalAuth) = 0;
virtual bool externalAuth() const = 0;
// methods
virtual SPool * createPool(const string &user, const string &password,
const string &connString,

View File

@ -54,6 +54,7 @@ enum DpiError // error type
DpiOciInvalidHandle,
// "Invalid OCI Handle/Descriptor or invalid parameter for OCI handle/descriptor allocation call"
DpiErrMemAllocFail, // "Memory allocatio failed"
DpiErrNullValue, // "Unexpected NULL value"
};

View File

@ -56,6 +56,8 @@
#define DPI_CONNERR_ORA_NOT_LOGGED_ON 1012
#define DPI_CONNERR_MAX_IDLE_TIMEOUT 2396
#define DPI_MAX_VERSION_SIZE 512
using namespace std;
@ -130,7 +132,8 @@ ConnImpl::ConnImpl(PoolImpl *pool, OCIEnv *envh, bool externalAuth,
try : env_(NULL), pool_(pool),
envh_(envh), errh_(NULL), auth_(NULL),
svch_(NULL), sessh_(NULL), hasTxn_(false), srvh_(NULL), dropConn_(false)
svch_(NULL), sessh_(NULL), hasTxn_(false), srvh_(NULL),
dropConn_(false)
{
this->initConnImpl ( true, externalAuth, connClass, poolName, poolNameLen,
"", "" );
@ -525,6 +528,31 @@ void ConnImpl::setErrState ( int errNum )
}
/*****************************************************************************/
/*
DESCRIPTION
To obtain the Oracle Database Server version
PARAMETERS
-None-
RETURNS
version
*/
unsigned int ConnImpl::getServerVersion ()
{
ub4 oraServerVer = 0;
char verbuf[ DPI_MAX_VERSION_SIZE ];
ociCall ( OCIServerRelease ( svch_, errh_, (OraText *)verbuf,
(ub4) sizeof ( verbuf ),
(ub1) OCI_HTYPE_SVCCTX, &oraServerVer ),
errh_ ) ;
return oraServerVer;
}
/*---------------------------------------------------------------------------
PRIVATE METHODS
---------------------------------------------------------------------------*/

View File

@ -130,6 +130,8 @@ class ConnImpl : public Conn
}
#endif
virtual unsigned int getServerVersion () ;
private:
void initConnImpl( bool pool, bool externalAuth, const string& connClass,

View File

@ -59,6 +59,7 @@ static const char *dpiErrors[] =
// DpiErrExtAuth
"invalid OCI handle or descriptor", // DpiOciInvalidHandle
"memory allocation failed", // DpiErrMemAllocFail
"unexpected NULL value", // DpiErrNullValue
};

View File

@ -81,8 +81,9 @@ Persistent<FunctionTemplate> Connection::connectionTemplate_s;
*/
Connection::Connection()
{
dpiconn_ = (dpi::Conn *)0;
oracledb_ = (Oracledb *)0;
dpiconn_ = (dpi::Conn *)0;
oracledb_ = (Oracledb *)0;
oracleServerVersion_ = 0;
}
/*****************************************************************************/
@ -145,6 +146,10 @@ void Connection::Init(Handle<Object> target)
NanNew<v8::String>("action"),
Connection::GetAction,
Connection::SetAction );
tpl->InstanceTemplate()->SetAccessor(
NanNew<v8::String>("oracleServerVersion"),
Connection::GetOracleServerVersion,
Connection::SetOracleServerVersion);
NanAssignPersistent( connectionTemplate_s, tpl);
target->Set(NanNew<v8::String>("Connection"),tpl->GetFunction());
@ -323,6 +328,67 @@ NAN_SETTER(Connection::SetAction)
njsConn->dpiconn_->action(action);
}
}
/*****************************************************************************/
/*
DESCRIPTION
Get Accessor of OracleServerVersion Property
*/
NAN_PROPERTY_GETTER (Connection::GetOracleServerVersion)
{
NanScope();
Connection *njsConn = ObjectWrap::Unwrap<Connection>(args.Holder());
if ( !njsConn->isValid_ )
{
string error = NJSMessages::getErrorMsg ( errInvalidConnection );
NJS_SET_EXCEPTION(error.c_str(), error.length() );
NanReturnUndefined();
}
try
{
if ( !njsConn->oracleServerVersion_ )
{
/* Updating the member variable is not thread-safe, but all threads
* will get same value from DB and update the value which is atomic
* and so it is ok.
*/
unsigned int ver = njsConn->dpiconn_->getServerVersion ();
njsConn-> oracleServerVersion_ =
100000000 * ( ( ver >> 24 ) & 0x000000FF ) +
1000000 * ( ( ver >> 20 ) & 0x0000000F ) +
10000 * ( ( ver >> 12 ) & 0x000000FF ) +
100 * ( ( ver >> 8 ) & 0x0000000F ) +
( ( ver >> 0 ) & 0x000000FF ) ;
}
Local<Integer> value = NanNew<v8::Integer>(
(unsigned int ) njsConn-> oracleServerVersion_ );
NanReturnValue ( value );
}
catch ( dpi::Exception &e)
{
NJS_SET_CONN_ERR_STATUS ( e.errnum(), njsConn->dpiconn_ );
NJS_SET_EXCEPTION ( e.what(), strlen (e.what () ) );
NanReturnUndefined ();
}
}
/*****************************************************************************/
/*
DESCRIPTION
Set Accessor of OracleServerVersion Property
*/
NAN_SETTER(Connection::SetOracleServerVersion)
{
connectionPropertyException(ObjectWrap::Unwrap<Connection>(args.Holder()),
errReadOnly, "oracleServerVersion" );
}
/*****************************************************************************/
/*
DESCRIPTION

View File

@ -292,12 +292,14 @@ private:
static NAN_PROPERTY_GETTER(GetClientId);
static NAN_PROPERTY_GETTER(GetModule);
static NAN_PROPERTY_GETTER(GetAction);
static NAN_PROPERTY_GETTER(GetOracleServerVersion);
// Define Setter Accessors to properties
static NAN_SETTER(SetStmtCacheSize);
static NAN_SETTER(SetClientId);
static NAN_SETTER(SetModule);
static NAN_SETTER(SetAction);
static NAN_SETTER(SetOracleServerVersion);
static void connectionPropertyException(Connection* njsConn,
NJSErrorType errType,
@ -396,7 +398,7 @@ private:
dpi::Conn* dpiconn_;
bool isValid_;
unsigned int oracleServerVersion_;
};

View File

@ -88,7 +88,7 @@ Oracledb::Oracledb()
connClass_ = "";
externalAuth_ = false;
fetchAsStringTypes_ = NULL;
lobPrefetchSize_ = NJS_LOB_PREFETCH_SIZE;
lobPrefetchSize_ = NJS_LOB_PREFETCH_SIZE;
}
/*****************************************************************************/
@ -186,6 +186,11 @@ void Oracledb::Init(Handle<Object> target)
Oracledb::GetLobPrefetchSize,
Oracledb::SetLobPrefetchSize);
temp->InstanceTemplate()->SetAccessor(
NanNew<v8::String>("oracleClientVersion"),
Oracledb::GetOracleClientVersion,
Oracledb::SetOracleClientVersion);
NanAssignPersistent( oracledbTemplate_s, temp);
target->Set(NanNew<v8::String>("Oracledb"),temp->GetFunction());
}
@ -200,9 +205,22 @@ NAN_METHOD(Oracledb::New)
{
NanScope();
sword majorVer = 0, minorVer = 0, updateVer = 0, portVer = 0,
portUpdateVer = 0;
Oracledb *oracledb = new Oracledb();
oracledb->Wrap(args.This());
NanAssignPersistent( oracledb->jsOracledb, args.This() );
dpi::Common::clientVersion ( &majorVer, &minorVer, &updateVer,
&portVer, &portUpdateVer );
oracledb->oraClientVer_ = 100000000 * majorVer +
1000000 * minorVer +
10000 * updateVer +
100 * portVer +
portUpdateVer ;
NanReturnValue(args.This());
}
@ -626,6 +644,39 @@ NAN_SETTER(Oracledb::SetFetchAsString)
}
/*****************************************************************************/
/*
DESCRIPTION
Get Accessor of Oracle Client Library Version property
*/
NAN_PROPERTY_GETTER(Oracledb::GetOracleClientVersion)
{
NanScope();
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(args.Holder());
Local<Integer> value;
value = NanNew<v8::Integer>( (unsigned int) oracledb->oraClientVer_ );
NanReturnValue ( value );
}
/*****************************************************************************/
/*
DESCRIPTION
Set Accessor of Oracle Client Version Property
*/
NAN_SETTER(Oracledb::SetOracleClientVersion )
{
NanScope ();
std::string msg;
msg = NJSMessages::getErrorMsg (errReadOnly, "oracleClientVersion");
NJS_SET_EXCEPTION(msg.c_str(), (int) msg.length());
}
/*****************************************************************************/
/*

View File

@ -77,6 +77,7 @@ using namespace v8;
(NJS_NODE_ORACLEDB_MINOR * 100) + \
(NJS_NODE_ORACLEDB_PATCH) )
class Oracledb: public ObjectWrap
{
public:
@ -86,20 +87,22 @@ class Oracledb: public ObjectWrap
// Oracledb class
static void Init(Handle<Object> target);
dpi::Env* getDpiEnv () const { return dpienv_; }
bool getAutoCommit () const { return autoCommit_; }
unsigned int getOutFormat () const { return outFormat_; }
unsigned int getMaxRows () const { return maxRows_; }
unsigned int getStmtCacheSize () const { return stmtCacheSize_; }
unsigned int getPoolMin () const { return poolMin_; }
unsigned int getPoolMax () const { return poolMax_; }
unsigned int getPoolIncrement () const { return poolIncrement_; }
unsigned int getPoolTimeout () const { return poolTimeout_; }
unsigned int getPrefetchRows () const { return prefetchRows_; }
dpi::Env* getDpiEnv () const { return dpienv_; }
bool getAutoCommit () const { return autoCommit_; }
unsigned int getOutFormat () const { return outFormat_; }
unsigned int getMaxRows () const { return maxRows_; }
unsigned int getStmtCacheSize () const { return stmtCacheSize_; }
unsigned int getPoolMin () const { return poolMin_; }
unsigned int getPoolMax () const { return poolMax_; }
unsigned int getPoolIncrement () const { return poolIncrement_; }
unsigned int getPoolTimeout () const { return poolTimeout_; }
unsigned int getPrefetchRows () const { return prefetchRows_; }
const std::string& getConnectionClass () const { return connClass_; }
const DataType *getFetchAsStringTypes () const;
unsigned int getFetchAsStringTypesCount () const
{ return fetchAsStringTypesCount_ ; }
const DataType* getFetchAsStringTypes () const;
unsigned int getFetchAsStringTypesCount () const
{ return fetchAsStringTypesCount_ ; }
private:
// Define Oracledb Constructor
@ -132,6 +135,7 @@ private:
static NAN_PROPERTY_GETTER(GetPrefetchRows);
static NAN_PROPERTY_GETTER(GetFetchAsString);
static NAN_PROPERTY_GETTER(GetLobPrefetchSize);
static NAN_PROPERTY_GETTER(GetOracleClientVersion);
// Define Setter Accessors to Properties
static NAN_SETTER(SetPoolMin);
@ -148,6 +152,8 @@ private:
static NAN_SETTER(SetPrefetchRows);
static NAN_SETTER(SetFetchAsString);
static NAN_SETTER(SetLobPrefetchSize);
static NAN_SETTER(SetOracleClientVersion);
Oracledb();
~Oracledb();
@ -170,6 +176,7 @@ private:
DataType *fetchAsStringTypes_;
unsigned int fetchAsStringTypesCount_;
unsigned int lobPrefetchSize_;
unsigned int oraClientVer_;
};
/**
@ -201,6 +208,7 @@ typedef struct connectionBaton
dpi::Conn* dpiconn;
dpi::SPool* dpipool;
Oracledb *oracledb;
connectionBaton() : user(""), pswrd(""), connStr(""), connClass(""),

View File

@ -192,6 +192,11 @@ describe('58. properties.js', function() {
t.should.eql(defaultValues.lobPrefetchSize);
(oracledb.lobPrefetchSize).should.eql(defaultValues.lobPrefetchSize + 1);
})
it('58.1.14 oracleClientVersion', function () {
var t = oracledb.oracleClientVersion ;
} );
}) // 58.1
describe('58.2 pool properties', function() {
@ -373,5 +378,14 @@ describe('58. properties.js', function() {
connection.module = "103.3 module";
})
it ('58.3.6 oracleServerVersion', function () {
try {
var t = connection.oracleServerVersion;
}
catch (err ) {
should.exist ( err );
}
});
}) // 58.3
})