Skip to content

Commit 0fafee7

Browse files
committed
Fix review comments for query buffer space optimization
1 parent d4014f3 commit 0fafee7

File tree

5 files changed

+33
-28
lines changed

5 files changed

+33
-28
lines changed

src/dpi/include/dpiConn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Conn
6363
// properties
6464
virtual void stmtCacheSize(unsigned int stmtCacheSize) = 0;
6565
virtual unsigned int stmtCacheSize() const = 0;
66-
virtual int getByteExpansionRation () = 0;
66+
virtual int getByteExpansionRatio () = 0;
6767

6868
virtual void lobPrefetchSize(unsigned int lobPrefetchSize) = 0;
6969
virtual unsigned int lobPrefetchSize() const = 0;

src/dpi/src/dpiConnImpl.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@
5151
using namespace std;
5252

5353

54-
55-
5654
/*---------------------------------------------------------------------------
5755
PUBLIC METHODS
5856
---------------------------------------------------------------------------*/
@@ -246,9 +244,9 @@ void ConnImpl::stmtCacheSize(unsigned int stmtCacheSize)
246244
RETURNS:
247245
Byte expansion ratio (int)
248246
*/
249-
int ConnImpl::getByteExpansionRation ()
247+
int ConnImpl::getByteExpansionRatio ()
250248
{
251-
return lxgratio_;
249+
return csratio_;
252250
}
253251

254252
/*****************************************************************************/
@@ -502,8 +500,8 @@ void ConnImpl::initConnImpl ( bool pool, bool externalAuth,
502500
ub4 nameLen, const string &user, const string &password )
503501
{
504502
OCIServer *srvh = NULL;
505-
ub4 mode = 0;
506-
ub2 csid_ = 0;
503+
ub4 mode = OCI_DEFAULT;
504+
ub2 csid = 0;
507505

508506
if ( pool )
509507
mode = externalAuth ? ( OCI_SESSGET_CREDEXT | OCI_SESSGET_SPOOL ) :
@@ -557,13 +555,10 @@ void ConnImpl::initConnImpl ( bool pool, bool externalAuth,
557555
( ub4 ) OCI_ATTR_SERVER, errh_ ), errh_ );
558556

559557
// Get the DBCHARSET from server
560-
ociCall ( OCIAttrGet ( srvh, ( ub4 ) OCI_HTYPE_SERVER, ( void * ) &csid_,
558+
ociCall ( OCIAttrGet ( srvh, ( ub4 ) OCI_HTYPE_SERVER, ( void * ) &csid,
561559
( ub4 * ) 0, ( ub4 ) OCI_ATTR_CHARSET_ID, errh_ ),
562560
errh_ );
563-
if ( csid_ == DPI_AL32UTF8 )
564-
lxgratio_ = 1;
565-
else
566-
lxgratio_ = 3;
561+
csratio_ = getCsRatio ( csid );
567562
}
568563

569564
/*****************************************************************************/

src/dpi/src/dpiConnImpl.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ class PoolImpl;
5454

5555

5656

57+
/*
58+
* The maximum character expansion ratio from any DB character to
59+
* AL32UTF8 is known to be 3-times
60+
*/
61+
#define DPI_WORSTCASE_CHAR_CONVERSION_RATIO 3
62+
63+
// No character expansion required if DB has AL32UTF8 charset
64+
#define DPI_BESTCASE_CHAR_CONVERSION_RATIO 1
65+
5766
/*---------------------------------------------------------------------------
5867
PUBLIC TYPES
5968
---------------------------------------------------------------------------*/
@@ -89,7 +98,7 @@ class ConnImpl : public Conn
8998
virtual void module(const string &module);
9099

91100
virtual void action(const string &action);
92-
virtual int getByteExpansionRation ();
101+
virtual int getByteExpansionRatio ();
93102

94103
// interface methods
95104
virtual Stmt* getStmt(const string &sql);
@@ -124,6 +133,12 @@ class ConnImpl : public Conn
124133
void initConnImpl( bool pool, bool externalAuth, const string& connClass,
125134
OraText *poolNmRconnStr, ub4 nameLen,
126135
const string &user, const string &password );
136+
int getCsRatio ( ub2 csid )
137+
{
138+
return ( csid == DPI_AL32UTF8 ) ? DPI_BESTCASE_CHAR_CONVERSION_RATIO :
139+
DPI_WORSTCASE_CHAR_CONVERSION_RATIO;
140+
}
141+
127142
void cleanup();
128143

129144

@@ -136,7 +151,7 @@ class ConnImpl : public Conn
136151
OCISvcCtx *svch_; // OCI service handle
137152
OCISession *sessh_; // OCI Session handle. Do not free this.
138153
boolean hasTxn_; // set if transaction is in progress
139-
int lxgratio_; // Caches DBCharset ID
154+
int csratio_; // character expansion ratio
140155
};
141156

142157

src/njs/src/njsConnection.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ void Connection::DoDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
13761376
unsigned int numCols )
13771377
{
13781378
Define *defines = executeBaton->defines = new Define[numCols];
1379-
int lxgratio = executeBaton->dpiconn->getByteExpansionRation ();
1379+
int csratio = executeBaton->dpiconn->getByteExpansionRatio ();
13801380

13811381
for (unsigned int col = 0; col < numCols; col++)
13821382
{
@@ -1418,13 +1418,12 @@ void Connection::DoDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
14181418
executeBaton->columnNames[col],
14191419
meta[col].dbType );
14201420
/*
1421-
* While fetching non-ascii characters, each byte on the server
1422-
* can take upto maximum of 3 bytes when it converted to AL32UTF8
1423-
* because the client character set is always set to AL32UTF8
1424-
* in node-oracledb. If server has AL32UTF8 then ratio is 1.
1421+
* the buffer size is increased to account for possible character
1422+
* size expansion when data is converted from the DB character set
1423+
* to AL32UTF8
14251424
*/
14261425

1427-
defines[col].maxSize = (meta[col].dbSize) * lxgratio;
1426+
defines[col].maxSize = (meta[col].dbSize) * csratio;
14281427

14291428

14301429
if ( NJS_SIZE_T_OVERFLOW ( defines[col].maxSize,
@@ -2814,7 +2813,7 @@ void Connection::cbDynBufferAllocate ( void *ctx, bool dmlReturning,
28142813
eBaton *executeBaton = (eBaton *)ctx;
28152814
Bind *bind = (Bind *)executeBaton->binds[bndpos];
28162815

2817-
if ( NJS_SIZE_T_OVERFLOW ( nRows, sizeof ( short )))
2816+
if ( NJS_SIZE_T_OVERFLOW ( sizeof ( short ), nRows ) )
28182817
{
28192818
executeBaton->error = NJSMessages::getErrorMsg( errResultsTooLarge );
28202819
return;
@@ -2830,7 +2829,7 @@ void Connection::cbDynBufferAllocate ( void *ctx, bool dmlReturning,
28302829
}
28312830
if ( dmlReturning )
28322831
{
2833-
if ( NJS_SIZE_T_OVERFLOW ( nRows, sizeof ( unsigned int )))
2832+
if ( NJS_SIZE_T_OVERFLOW ( sizeof ( unsigned int ), nRows ) )
28342833
{
28352834
executeBaton->error = NJSMessages::getErrorMsg( errResultsTooLarge );
28362835
return;
@@ -2943,10 +2942,6 @@ void Connection::cbDynBufferAllocate ( void *ctx, bool dmlReturning,
29432942
}
29442943
}
29452944
if ( !dmlReturning )
2946-
{
2947-
*(bind->len) = sizeof ( unsigned int ) ;
2948-
}
2949-
if ( !dmlReturning )
29502945
{
29512946
*(bind->len) = sizeof ( double ) ;
29522947
}
@@ -2968,7 +2963,7 @@ void Connection::cbDynBufferAllocate ( void *ctx, bool dmlReturning,
29682963
}
29692964
else
29702965
{
2971-
bind->value = (void *)malloc(sizeof(Descriptor *) * bind->rowsReturned);
2966+
bind->value = (void *)malloc(sizeof(Descriptor *) * nRows);
29722967
if( !bind->value )
29732968
{
29742969
executeBaton->error = NJSMessages::getErrorMsg(

src/njs/src/njsMessages.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static const char *errMsg[] =
5959
"NJS-022: invalid LOB",
6060
"NJS-023: concurrent operations on LOB are not allowed",
6161
"NJS-024: memory allocation failed",
62-
"NJS-025: overflow when calculating results area size"
62+
"NJS-025: overflow when calculating results area size",
6363
};
6464

6565
string NJSMessages::getErrorMsg ( NJSErrorType err, ... )

0 commit comments

Comments
 (0)