Skip to content

Commit 3ffeaa6

Browse files
committed
Consolidate all executeXXX() methods in dpiStmt to single dpiStmt::execute () method.
1 parent 0464745 commit 3ffeaa6

File tree

4 files changed

+38
-63
lines changed

4 files changed

+38
-63
lines changed

src/dpi/include/dpiStmt.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,8 @@ class Stmt
152152
virtual void bind(const unsigned char *name, int nameLen,
153153
unsigned short type, void *buf, DPI_SZ_TYPE bufSize,
154154
short *ind, DPI_BUFLEN_TYPE *bufLen) = 0;
155-
156-
virtual void executeDML(bool isAutoCommit) = 0;
157-
158-
virtual void executeMany(int numIterations, bool isAutoCommit ) = 0;
159-
160-
virtual void executeQuery() = 0;
155+
156+
virtual void execute ( int numIterations, bool isAutoCommit = false) = 0;
161157

162158
virtual void define(unsigned int pos, unsigned short type, void *buf,
163159
DPI_SZ_TYPE bufSize, short *ind, DPI_BUFLEN_TYPE *bufLen) = 0;

src/dpi/src/dpiStmtImpl.cpp

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ StmtImpl::StmtImpl (EnvImpl *env, OCIEnv *envh, ConnImpl *conn,
8686
OCISvcCtx *svch, const string &sql)
8787

8888
try : conn_(conn), errh_(NULL), svch_(svch),
89-
stmth_(NULL), numCols_ (0),meta_(NULL)
89+
stmth_(NULL), numCols_ (0),meta_(NULL), stmtType_ (DpiStmtUnknown)
9090

9191
{
9292
// create an OCIError object for this execution
@@ -137,12 +137,14 @@ StmtImpl::~StmtImpl ()
137137
*/
138138
DpiStmtType StmtImpl::stmtType () const
139139
{
140-
ub2 stmtType ;
141-
142-
ociCall (OCIAttrGet (stmth_, OCI_HTYPE_STMT, &stmtType, NULL,
143-
OCI_ATTR_STMT_TYPE, errh_), errh_);
140+
// Try to query the statement type only once.
141+
if ( stmtType_ == DpiStmtUnknown )
142+
{
143+
ociCall (OCIAttrGet (stmth_, OCI_HTYPE_STMT, (ub2 * )&stmtType_, NULL,
144+
OCI_ATTR_STMT_TYPE, errh_), errh_);
145+
}
144146

145-
return (DpiStmtType)stmtType;
147+
return stmtType_;
146148
}
147149

148150

@@ -251,65 +253,34 @@ void StmtImpl::bind (const unsigned char *name, int nameLen,
251253
/****************************************************************************/
252254
/*
253255
DESCRIPTION
254-
Execute the DML statement.
256+
Execute the SQL statement.
255257
256258
PARAMETERS
257259
isAutoCommit - true/false - autocommit enabled or not
260+
numIterations - iterations to repeat
258261
259262
RETURNS:
260263
-None-
261264
*/
262-
void StmtImpl::executeDML (bool isAutoCommit )
265+
void StmtImpl::execute (int numIterations, bool isAutoCommit)
263266
{
264-
executeMany ( 1 , isAutoCommit ); // Use execute Many special case only one iteration.
265-
}
266-
267-
268-
/*****************************************************************************/
269-
/*
270-
DESCRIPTION
271-
Execute the DML statement multiple times.
267+
ub4 mode = isAutoCommit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT;
272268

273-
PARAMETERS:
274-
numIterations - number of times to execute
275-
isAutoCommit - true/false - autocommit enabled or not
269+
ociCall (OCIStmtExecute ( svch_, stmth_, errh_, (ub4)numIterations, (ub4)0,
270+
(OCISnapshot *)NULL, (OCISnapshot *)NULL, mode),
271+
errh_ );
276272

277-
RETURNS
278-
-None-
279-
*/
280-
void StmtImpl::executeMany (int numIterations, bool isAutoCommit )
281-
{
282-
ub4 mode = isAutoCommit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT ;
283-
284-
ociCall (OCIStmtExecute (svch_, stmth_, errh_, (ub4)numIterations, (ub4)0,
285-
(OCISnapshot *)NULL, (OCISnapshot *)NULL, mode),
286-
errh_);
287-
#if OCI_MAJOR_VERSION < 12
288-
if(!conn_->hasTxn())
289-
conn_->hasTxn(true); /* Not to be reset, till thread safety is ensured in
290-
NJS */
291-
#endif
273+
#if OCI_MAJOR_VERSION < 12
274+
if ( IsDML () && !conn_->hasTxn () )
275+
{
276+
/* Not to be reset, till thread safety is ensured in NJS */
277+
conn_->hasTxn (true );
278+
}
279+
#endif
292280
}
293281

294282

295283

296-
/*****************************************************************************/
297-
/*
298-
DESCRIPTION
299-
Execute the SELECT statement
300-
301-
PARAMETERS
302-
-None-
303-
304-
RETURNS:
305-
-None-
306-
*/
307-
void StmtImpl::executeQuery ()
308-
{
309-
ociCall (OCIStmtExecute (svch_, stmth_, errh_, 0, (ub4)0,
310-
(OCISnapshot *)NULL, (OCISnapshot *)NULL,
311-
OCI_DEFAULT), errh_);
312-
}
313284

314285

315286
/****************************************************************************/

src/dpi/src/dpiStmtImpl.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,8 @@ class StmtImpl : public Stmt
6767
virtual void bind (const unsigned char *name, int nameLen,
6868
unsigned short type, void *buf, DPI_SZ_TYPE bufSize, short *ind,
6969
DPI_BUFLEN_TYPE *bufLen);
70-
71-
virtual void executeDML ( bool isAutoCommit );
72-
virtual void executeMany (int numIterations, bool isAutoCommit );
73-
virtual void executeQuery ();
70+
71+
virtual void execute ( int numIterations, bool isAutoCommit );
7472

7573
virtual void define (unsigned int pos, unsigned short type, void *buf,
7674
DPI_SZ_TYPE bufSize, short *ind, DPI_BUFLEN_TYPE *bufLen);
@@ -79,6 +77,15 @@ class StmtImpl : public Stmt
7977
virtual const MetaData *getMetaData ();
8078

8179
virtual OCIError * getError () { return errh_; }
80+
81+
// Is the SQL statement DML or not ?
82+
virtual inline bool IsDML ()
83+
{
84+
return ( ( stmtType_ == DpiStmtInsert ) ||
85+
( stmtType_ == DpiStmtUpdate ) ||
86+
( stmtType_ == DpiStmtDelete ) );
87+
}
88+
8289

8390
private:
8491
void cleanup ();
@@ -95,6 +102,7 @@ class StmtImpl : public Stmt
95102

96103
unsigned int numCols_; // # of cols this stmt execution will return
97104
MetaData *meta_; // Meta data array
105+
DpiStmtType stmtType_; // Statement Type (Query, DML, ... )
98106
};
99107

100108

src/njs/src/njsConnection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,12 +713,12 @@ void Connection::Async_Execute (uv_work_t *req)
713713
executeBaton->st = executeBaton->dpistmt->stmtType();
714714
if (executeBaton->st == DpiStmtSelect)
715715
{
716-
executeBaton->dpistmt->executeQuery();
716+
executeBaton->dpistmt->execute(executeBaton->isAutoCommit);
717717
Connection::GetDefines(executeBaton);
718718
}
719719
else
720720
{
721-
executeBaton->dpistmt->executeDML(executeBaton->isAutoCommit);
721+
executeBaton->dpistmt->execute(executeBaton->isAutoCommit);
722722
executeBaton->rowsAffected = executeBaton->dpistmt->rowsAffected();
723723

724724
/* Process date/timestamp INOUT/OUT bind values */

0 commit comments

Comments
 (0)