Skip to content

Commit 1006555

Browse files
committed
Merge metadata changes derived from PR #386
1 parent c00ab72 commit 1006555

File tree

11 files changed

+866
-408
lines changed

11 files changed

+866
-408
lines changed

doc/api.md

Lines changed: 306 additions & 121 deletions
Large diffs are not rendered by default.

lib/oracledb.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,58 @@ function extend(oracledb) {
107107
value: 0,
108108
enumerable: true
109109
},
110+
DB_TYPE_VARCHAR: {
111+
value: 1,
112+
enumerable: true
113+
},
114+
DB_TYPE_NUMBER: {
115+
value: 2,
116+
enumerable: true
117+
},
118+
DB_TYPE_DATE: {
119+
value: 12,
120+
enumerable: true
121+
},
122+
DB_TYPE_RAW: {
123+
value: 23,
124+
enumerable: true
125+
},
126+
DB_TYPE_CHAR: {
127+
value: 96,
128+
enumerable: true
129+
},
130+
DB_TYPE_BINARY_FLOAT: {
131+
value: 100,
132+
enumerable: true
133+
},
134+
DB_TYPE_BINARY_DOUBLE: {
135+
value: 101,
136+
enumerable: true
137+
},
138+
DB_TYPE_ROWID: {
139+
value: 104,
140+
enumerable: true
141+
},
142+
DB_TYPE_CLOB: {
143+
value: 112,
144+
enumerable: true
145+
},
146+
DB_TYPE_BLOB: {
147+
value: 113,
148+
enumerable: true
149+
},
150+
DB_TYPE_TIMESTAMP: {
151+
value: 187,
152+
enumerable: true
153+
},
154+
DB_TYPE_TIMESTAMPTZ: {
155+
value: 188,
156+
enumerable: true
157+
},
158+
DB_TYPE_TIMESTAMPLTZ: {
159+
value: 232,
160+
enumerable: true
161+
},
110162
STRING: {
111163
value: 2001,
112164
enumerable: true

src/dpi/include/dpiStmt.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,20 @@ typedef enum
136136
#endif
137137

138138

139-
typedef struct
139+
typedef struct MetaData
140140
{
141141
unsigned char *colName; // column name
142142
unsigned int colNameLen; // length of column name
143143
unsigned short dbType; // database server type
144144
unsigned short dbSize; // size at database
145-
unsigned int precision; // precision
145+
unsigned char precision; // precision
146146
char scale; // scale
147147
unsigned char isNullable; // is the column nullable?
148+
149+
MetaData ()
150+
: colName ( NULL ), colNameLen ( 0 ), dbType ( 0 ), dbSize ( 0 ),
151+
precision ( 0 ), scale ( 0 ), isNullable ( 0 )
152+
{}
148153
} MetaData;
149154

150155

@@ -195,7 +200,12 @@ class Stmt
195200

196201
virtual void fetch(unsigned int numRows = 1) = 0;
197202

198-
virtual const MetaData * getMetaData() = 0;
203+
204+
/*
205+
* The returned pointer to MetaData struct should not be freed by the caller
206+
* since this will be freed as part of StmtImpl::release()
207+
*/
208+
virtual const MetaData * getMetaData( bool extendedMetaData ) = 0;
199209

200210
virtual unsigned int rowsFetched() const = 0;
201211

src/dpi/src/dpiStmtImpl.cpp

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,18 @@ unsigned int StmtImpl::rowsFetched () const
475475
obtains column meta data
476476
477477
PARAMETERS
478-
-None-
478+
extendedMetaData - true - all fields are populated
479+
false - only column name, db type, size is populated.
479480
480481
RETURNS
481-
-None-
482+
Pointer to MetaData struct.
482483
*/
483-
const MetaData* StmtImpl::getMetaData ()
484+
485+
/*
486+
* The returned pointer to MetaData struct should not be freed by the caller
487+
* since this will be freed as part of StmtImpl::release()
488+
*/
489+
const MetaData* StmtImpl::getMetaData ( bool extendedMetaData )
484490
{
485491

486492
if ( !meta_ )
@@ -509,30 +515,53 @@ const MetaData* StmtImpl::getMetaData ()
509515
(void*) &(meta_[col].dbType),(ub4 *) 0,
510516
(ub4) OCI_ATTR_DATA_TYPE,
511517
errh_ ), errh_ );
512-
ociCall(OCIAttrGet(colDesc, (ub4) OCI_DTYPE_PARAM,
513-
(void*) &(meta_[col].dbSize),(ub4 *) 0,
514-
(ub4) OCI_ATTR_DATA_SIZE,
515-
errh_ ), errh_ );
516-
ociCall(OCIAttrGet(colDesc, (ub4) OCI_DTYPE_PARAM,
517-
(void*) &(meta_[col].isNullable),(ub4*) 0,
518-
(ub4) OCI_ATTR_IS_NULL,
519-
errh_ ), errh_ );
520-
if (meta_[col].dbType == DpiNumber || meta_[col].dbType == DpiBinaryFloat
521-
||meta_[col].dbType == DpiBinaryDouble )
518+
switch ( meta_[col].dbType )
519+
{
520+
case DpiVarChar:
521+
case DpiFixedChar:
522+
case DpiRaw:
523+
// byteSize in case VARCHAR, FIXEDCHAR, RAW columns
524+
ociCall(OCIAttrGet(colDesc, (ub4) OCI_DTYPE_PARAM,
525+
(void*) &(meta_[col].dbSize),(ub4 *) 0,
526+
(ub4) OCI_ATTR_DATA_SIZE,
527+
errh_ ), errh_ );
528+
break;
529+
530+
default:
531+
break;
532+
}
533+
534+
if ( extendedMetaData )
522535
{
523536
ociCall(OCIAttrGet(colDesc, (ub4) OCI_DTYPE_PARAM,
524-
(void*) &(meta_[col].precision),(ub4* ) 0,
525-
(ub4) OCI_ATTR_PRECISION,
526-
errh_ ), errh_ );
527-
ociCall(OCIAttrGet(colDesc, (ub4) OCI_DTYPE_PARAM,
528-
(void*) &(meta_[col].scale),(ub4*) 0,
529-
(ub4) OCI_ATTR_SCALE,
537+
(void*) &(meta_[col].isNullable),(ub4*) 0,
538+
(ub4) OCI_ATTR_IS_NULL,
530539
errh_ ), errh_ );
531-
}
532-
else
533-
{ // avoid uninitialized variables
534-
meta_[col].precision = 0;
535-
meta_[col].scale = 0;
540+
switch ( meta_[col].dbType )
541+
{
542+
case DpiNumber:
543+
ociCall(OCIAttrGet(colDesc, (ub4) OCI_DTYPE_PARAM,
544+
(void*) &(meta_[col].precision),(ub4* ) 0,
545+
(ub4) OCI_ATTR_PRECISION,
546+
errh_ ), errh_ );
547+
ociCall(OCIAttrGet(colDesc, (ub4) OCI_DTYPE_PARAM,
548+
(void*) &(meta_[col].scale),(ub4*) 0,
549+
(ub4) OCI_ATTR_SCALE,
550+
errh_ ), errh_ );
551+
break;
552+
553+
case DpiTimestamp:
554+
case DpiTimestampTZ:
555+
case DpiTimestampLTZ:
556+
ociCall(OCIAttrGet(colDesc, (ub4) OCI_DTYPE_PARAM,
557+
(void*) &(meta_[col].scale),(ub4*) 0,
558+
(ub4) OCI_ATTR_SCALE,
559+
errh_ ), errh_ );
560+
break;
561+
562+
default:
563+
break;
564+
}
536565
}
537566

538567
OCIDescriptorFree( colDesc, OCI_DTYPE_PARAM);

src/dpi/src/dpiStmtImpl.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ class StmtImpl : public Stmt
9494
DPI_SZ_TYPE bufSize, short *ind, DPI_BUFLEN_TYPE *bufLen);
9595
virtual void fetch (unsigned int numRows = 1);
9696

97-
virtual const MetaData *getMetaData ();
97+
98+
/*
99+
* The returned pointer to MetaData struct should not be freed by the caller
100+
* since this will be freed as part of StmtImpl::release()
101+
*/
102+
virtual const MetaData *getMetaData ( bool extendedMetaData );
98103

99104
virtual OCIError * getError () { return errh_; }
100105

0 commit comments

Comments
 (0)