Skip to content

Commit c1830a3

Browse files
committed
Fix metaData scale and precision on AIX. Also Replace std::string.data() with std::string.c_str()
1 parent 231a4bc commit c1830a3

File tree

9 files changed

+57
-51
lines changed

9 files changed

+57
-51
lines changed

binding.gyp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
"oci_lib_dir%" : '<!(echo ${OCI_LIB_DIR:="/opt/oracle/instantclient/"})',
6363
},
6464
"libraries" : ["-lclntsh"],
65-
"cflags" : ['-fexceptions'],
66-
"cflags_cc" : ['-fexceptions'],
65+
"cflags" : ['-fexceptions', '-fsigned-char'],
66+
"cflags_cc" : ['-fexceptions', '-fsigned-char'],
6767
"link_settings" : {
6868
"libraries" : ['-L<(oci_lib_dir)']
6969
}

src/dpi/include/dpiStmt.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ typedef enum
117117
*/
118118
#if OCI_MAJOR_VERSION >= 12
119119
#define DPI_SZ_TYPE sb8
120+
#define DPI_USZ_TYPE ub8
120121
#define DPI_BUFLEN_TYPE ub4
121122
#define DPIBINDBYPOS OCIBindByPos2
122123
#define DPIBINDBYNAME OCIBindByName2
@@ -126,6 +127,7 @@ typedef enum
126127
#define DPILOBWRITE OCILobWrite2
127128
#else
128129
#define DPI_SZ_TYPE sb4
130+
#define DPI_USZ_TYPE ub4
129131
#define DPI_BUFLEN_TYPE ub2
130132
#define DPIBINDBYPOS OCIBindByPos
131133
#define DPIBINDBYNAME OCIBindByName
@@ -142,8 +144,8 @@ typedef struct MetaData
142144
unsigned int colNameLen; // length of column name
143145
unsigned short dbType; // database server type
144146
unsigned short dbSize; // size at database
145-
unsigned char precision; // precision
146-
char scale; // scale
147+
short precision; // precision
148+
signed char scale; // scale, range starts from -127
147149
unsigned char isNullable; // is the column nullable?
148150

149151
MetaData ()
@@ -174,7 +176,7 @@ class Stmt
174176

175177
virtual bool isReturning() = 0 ;
176178

177-
virtual DPI_SZ_TYPE rowsAffected() const = 0;
179+
virtual DPI_USZ_TYPE rowsAffected () const = 0;
178180

179181
virtual unsigned int numCols() = 0;
180182

src/dpi/src/dpiConnImpl.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ try : env_(env), pool_(NULL),
9393
{
9494

9595
this->initConnImpl ( false, externalAuth, connClass,
96-
( OraText * ) connString.data (),
96+
( OraText * ) connString.c_str (),
9797
( ub4 ) connString.length (), user, password, "",
9898
false, dbPriv );
9999

@@ -373,7 +373,7 @@ unsigned int ConnImpl::lobPrefetchSize() const
373373

374374
void ConnImpl::clientId(const string &clientId)
375375
{
376-
ociCall(OCIAttrSet(sessh_, OCI_HTYPE_SESSION, (void *)clientId.data(),
376+
ociCall(OCIAttrSet(sessh_, OCI_HTYPE_SESSION, (void *)clientId.c_str(),
377377
(ub4)clientId.length(), OCI_ATTR_CLIENT_IDENTIFIER, errh_),
378378
errh_);
379379
}
@@ -397,7 +397,7 @@ void ConnImpl::clientId(const string &clientId)
397397

398398
void ConnImpl::module(const string &module)
399399
{
400-
ociCall(OCIAttrSet(sessh_, OCI_HTYPE_SESSION, (void *)module.data(),
400+
ociCall(OCIAttrSet(sessh_, OCI_HTYPE_SESSION, (void *)module.c_str(),
401401
(ub4) module.length(), OCI_ATTR_MODULE, errh_), errh_);
402402
}
403403

@@ -420,7 +420,7 @@ void ConnImpl::module(const string &module)
420420

421421
void ConnImpl::action(const string &action)
422422
{
423-
ociCall(OCIAttrSet(sessh_, OCI_HTYPE_SESSION, (void *)action.data(),
423+
ociCall(OCIAttrSet(sessh_, OCI_HTYPE_SESSION, (void *)action.c_str(),
424424
(ub4) action.length(), OCI_ATTR_ACTION, errh_), errh_);
425425
}
426426

@@ -627,11 +627,11 @@ void ConnImpl::initConnImpl ( bool pool, bool externalAuth,
627627
if ( !pool )
628628
{
629629
ociCall ( OCIAttrSet ( ( void * ) auth_, OCI_HTYPE_AUTHINFO,
630-
( void * ) user.data (), ( ub4 ) user.length (),
630+
( void * ) user.c_str (), ( ub4 ) user.length (),
631631
OCI_ATTR_USERNAME, errh_ ), errh_ );
632632

633633
ociCall ( OCIAttrSet ( ( void * ) auth_, OCI_HTYPE_AUTHINFO,
634-
( void * ) password.data (),
634+
( void * ) password.c_str (),
635635
( ub4 ) password.length (),
636636
OCI_ATTR_PASSWORD, errh_ ), errh_ );
637637
}
@@ -652,7 +652,7 @@ void ConnImpl::initConnImpl ( bool pool, bool externalAuth,
652652
if ( connClass.length () )
653653
{
654654
ociCall ( OCIAttrSet ( ( void* ) auth_, OCI_HTYPE_AUTHINFO,
655-
( void * ) connClass.data (),
655+
( void * ) connClass.c_str (),
656656
( ub4 ) connClass.length (),
657657
OCI_ATTR_CONNECTION_CLASS, errh_ ), errh_ );
658658
}
@@ -663,7 +663,7 @@ void ConnImpl::initConnImpl ( bool pool, bool externalAuth,
663663
if ( !pool && !(env_->drvName()).empty() )
664664
{
665665
ociCall ( OCIAttrSet ( (void*) auth_, OCI_HTYPE_AUTHINFO,
666-
(OraText *) ( env_->drvName() ).data (),
666+
(OraText *) ( env_->drvName() ).c_str (),
667667
( ub4 ) ( ( env_->drvName() ).length () ),
668668
OCI_ATTR_DRIVER_NAME, errh_ ), errh_);
669669
}

src/dpi/src/dpiExceptionImpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ ExceptionImpl::~ExceptionImpl() throw ()
163163

164164
const char * ExceptionImpl::what() const throw()
165165
{
166-
return message_.data();
166+
return message_.c_str ();
167167
}
168168

169169

@@ -207,7 +207,7 @@ int ExceptionImpl::errnum() const throw()
207207

208208
const char * ExceptionImpl::origin() const throw()
209209
{
210-
return origin_.data();
210+
return origin_.c_str ();
211211
}
212212

213213

src/dpi/src/dpiPoolImpl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ PoolImpl::PoolImpl(EnvImpl *env, OCIEnv *envh,
118118
if ( !(env_->drvName()).empty() )
119119
{
120120
ociCall ( OCIAttrSet ( ( void * ) poolAuth_, OCI_HTYPE_AUTHINFO,
121-
( OraText * ) ( env_->drvName() ).data (),
121+
( OraText * ) ( env_->drvName() ).c_str (),
122122
( ub4 ) ( ( env_->drvName() ).length () ),
123123
OCI_ATTR_DRIVER_NAME, errh_ ), errh_ );
124124
}
@@ -128,12 +128,12 @@ PoolImpl::PoolImpl(EnvImpl *env, OCIEnv *envh,
128128

129129
ociCall(OCISessionPoolCreate(envh_, errh_, spoolh_,
130130
&poolName_, &poolNameLen_,
131-
(OraText *)connString.data (),
131+
(OraText *)connString.c_str (),
132132
(ub4) connString.length(),
133133
poolMin, poolMax,
134134
poolIncrement,
135-
(OraText *)user.data (), (ub4) user.length(),
136-
(OraText *)password.data (),
135+
(OraText *)user.c_str (), (ub4) user.length(),
136+
(OraText *)password.c_str (),
137137
(ub4) password.length(),
138138
mode), errh_ );
139139

src/dpi/src/dpiStmtImpl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ StmtImpl::StmtImpl (EnvImpl *env, OCIEnv *envh, ConnImpl *conn,
102102
if(!sql.empty())
103103
{
104104
// Prepare OCIStmt object with given sql statement.
105-
ociCall (OCIStmtPrepare2 (svch_, &stmth_, errh_, (oratext *)sql.data(),
105+
ociCall (OCIStmtPrepare2 (svch_, &stmth_, errh_, (oratext *)sql.c_str(),
106106
(ub4)sql.length(), NULL, 0, OCI_NTV_SYNTAX,
107107
OCI_DEFAULT),
108108
errh_);
@@ -177,9 +177,9 @@ DpiStmtType StmtImpl::stmtType () const
177177
number of rows affected by the DML operation
178178
179179
*/
180-
DPI_SZ_TYPE StmtImpl::rowsAffected () const
180+
DPI_USZ_TYPE StmtImpl::rowsAffected () const
181181
{
182-
DPI_SZ_TYPE rowsAffected = 0;
182+
DPI_USZ_TYPE rowsAffected = 0;
183183

184184
ociCall (OCIAttrGet (stmth_, OCI_HTYPE_STMT, &rowsAffected, NULL,
185185
DPIATTRROWCOUNT, errh_), errh_);

src/dpi/src/dpiStmtImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class StmtImpl : public Stmt
6767

6868
// Attributes
6969
virtual DpiStmtType stmtType () const;
70-
virtual DPI_SZ_TYPE rowsAffected () const;
70+
virtual DPI_USZ_TYPE rowsAffected () const;
7171
virtual unsigned int numCols() ;
7272
virtual void prefetchRows( unsigned int prefetchRows ) ;
7373
virtual unsigned int rowsFetched () const ;

src/njs/src/njsConnection.cpp

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,7 @@ void Connection::Async_Execute (uv_work_t *req)
16881688
( executeBaton->binds[b]->type == dpi::DpiVarChar ))
16891689
{
16901690
bool err = false;
1691-
for ( DPI_SZ_TYPE row = 0 ;
1691+
for ( DPI_USZ_TYPE row = 0 ;
16921692
!err && ( row < executeBaton->rowsAffected) ;
16931693
row ++ )
16941694
{
@@ -2600,39 +2600,43 @@ NJSErrorType Connection::Descr2Double( Define* defines, unsigned int numCols,
26002600
/* Special processing for datetime, as it is obtained as descriptors */
26012601
if ( defines[col].dttmarr )
26022602
{
2603-
long double *dblArr = NULL;
2604-
if ( !defines[col].buf )
2603+
if ( rowsFetched )
26052604
{
2606-
// size_t overflow check not required here as rowsFetched(unsigned int)
2607-
// multiplied by sizeof(long double) never cause size_t overflow
2608-
defines[col].buf =
2609-
dblArr =
2610-
(long double *)malloc ( sizeof ( long double ) * rowsFetched );
2611-
2612-
if( !defines[col].buf )
2605+
long double *dblArr = NULL;
2606+
if ( !defines[col].buf )
26132607
{
2614-
errNum = errInsufficientMemory;
2615-
}
2616-
}
2617-
else
2618-
{
2619-
dblArr = (long double *) defines[col].buf;
2620-
}
2608+
// size_t overflow check not required here as rowsFetched
2609+
// (unsigned int) multiplied by sizeof(long double) never cause
2610+
// size_t overflow
2611+
defines[col].buf =
2612+
dblArr =
2613+
(long double *)malloc ( sizeof ( long double ) * rowsFetched );
26212614

2622-
if ( !errNum )
2623-
{
2624-
for ( int row = 0; row < (int) rowsFetched; row ++ )
2615+
if( !defines[col].buf )
2616+
{
2617+
errNum = errInsufficientMemory;
2618+
}
2619+
}
2620+
else
26252621
{
2626-
dblArr[row] = defines[col].dttmarr->getDateTime (row);
2622+
dblArr = (long double *) defines[col].buf;
26272623
}
26282624

2629-
if ( !getRS )
2625+
if ( !errNum )
26302626
{
2631-
defines[col].dttmarr->release ();
2632-
defines[col].dttmarr = NULL;
2633-
defines[col].extbuf = NULL;
2627+
for ( int row = 0; row < (int) rowsFetched; row ++ )
2628+
{
2629+
dblArr[row] = defines[col].dttmarr->getDateTime (row);
2630+
}
26342631
}
26352632
}
2633+
2634+
if ( !getRS )
2635+
{
2636+
defines[col].dttmarr->release ();
2637+
defines[col].dttmarr = NULL;
2638+
defines[col].extbuf = NULL;
2639+
}
26362640
}
26372641
}
26382642

src/njs/src/njsConnection.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ typedef struct MetaInfo
133133
unsigned short dpiFetchType; // Target fetchType for DPI
134134
short njsFetchType; // Target fetchType for NJS
135135
unsigned short byteSize; // Size In bytes at database
136-
unsigned char precision; // Precision
137-
char scale; // Scale
136+
short precision; // Precision
137+
signed char scale; // Scale, range starts from -127
138138
unsigned char isNullable; // Nullable
139139

140140
MetaInfo ()
@@ -187,7 +187,7 @@ typedef struct eBaton
187187
dpi::Env* dpienv;
188188
dpi::Conn* dpiconn;
189189
Connection *njsconn;
190-
DPI_SZ_TYPE rowsAffected;
190+
DPI_USZ_TYPE rowsAffected;
191191
unsigned int maxRows;
192192
unsigned int prefetchRows;
193193
bool getRS;

0 commit comments

Comments
 (0)