@@ -54,9 +54,6 @@ describe('181. dataTypeXML.js', function() {
5454 '</Warehouse>\n' ;
5555
5656 before ( 'create table and insert a row' , async function ( ) {
57- if ( oracledb . thin ) {
58- this . skip ( ) ;
59- }
6057
6158 const connection = await oracledb . getConnection ( dbConfig ) ;
6259
@@ -74,8 +71,9 @@ describe('181. dataTypeXML.js', function() {
7471 " EXECUTE IMMEDIATE (' \n" +
7572 " CREATE TABLE " + tableName + " ( \n" +
7673 " num number(9) not null, \n" +
77- " content xmltype not null \n" +
78- " ) \n" +
74+ " content xmltype not null, \n" +
75+ " embedLOBXML xmltype \n" +
76+ " ) XMLTYPE embedLOBXML STORE AS CLOB\n" +
7977 " '); \n" +
8078 "END; " ;
8179 await connection . execute ( sql ) ;
@@ -106,19 +104,17 @@ describe('181. dataTypeXML.js', function() {
106104 it ( '181.1 basic case, insert XML data and query back' , async ( ) => {
107105 const conn = await oracledb . getConnection ( dbConfig ) ;
108106 const sql = "select content from " + tableName + " where num = :id" ;
109- const expectedMetadata = {
110- name : 'CONTENT' ,
111- dbType : oracledb . DB_TYPE_XMLTYPE ,
112- nullable : false ,
113- isJson : false ,
114- dbTypeName : 'XMLTYPE' ,
115- fetchType : oracledb . DB_TYPE_XMLTYPE
116- } ;
117107 const bindVar = { id : testRowID } ;
118108 const options = { outFormat : oracledb . OUT_FORMAT_OBJECT } ;
119- const result = await conn . execute ( sql , bindVar , options ) ;
120- assert . strictEqual ( result . rows [ 0 ] . CONTENT , testXMLData ) ;
121- assert . deepStrictEqual ( result . metaData [ 0 ] , expectedMetadata ) ;
109+
110+ // test execute and re-execute
111+ for ( let i = 0 ; i < 2 ; i ++ ) {
112+ const result = await conn . execute ( sql , bindVar , options ) ;
113+ assert . strictEqual ( result . rows [ 0 ] . CONTENT , testXMLData ) ;
114+ assert . strictEqual ( result . metaData [ 0 ] . dbType , oracledb . DB_TYPE_XMLTYPE ) ;
115+ assert . strictEqual ( result . metaData [ 0 ] . fetchType , oracledb . DB_TYPE_XMLTYPE ) ;
116+ }
117+
122118 await conn . close ( ) ;
123119 } ) ; // 181.1
124120
@@ -182,9 +178,7 @@ describe('181. dataTypeXML.js', function() {
182178 await conn . close ( ) ;
183179 } ) ; // 181.4
184180
185- // ORA-19011: Character string buffer too small
186- it . skip ( '181.5 inserts data that is larger than 4K' , async ( ) => {
187-
181+ it ( '181.5 inserts data that is larger than 4K' , async ( ) => {
188182 const ID = 50 ;
189183 const str = 'a' . repeat ( 31 * 1024 ) ;
190184 const head = '<data>' , tail = '</data>\n' ;
@@ -197,13 +191,60 @@ describe('181. dataTypeXML.js', function() {
197191 let result = await conn . execute ( sql , bindValues ) ;
198192 assert . strictEqual ( result . rowsAffected , 1 ) ;
199193
200- sql = "select content from " + tableName + " where num = :id" ;
201194 const bindVar = { id : ID } ;
202195 const options = { outFormat : oracledb . OUT_FORMAT_OBJECT } ;
203- result = await conn . execute ( sql , bindVar , options ) ;
204- assert . strictEqual ( result . rows [ 0 ] . CONTENT , xml ) ;
196+ if ( oracledb . thin ) {
197+ sql = "select content from " + tableName + " where num = :id" ;
198+ result = await conn . execute ( sql , bindVar , options ) ;
199+ assert . strictEqual ( result . rows [ 0 ] . CONTENT , xml ) ;
200+ } else {
201+ // For thick, we get an error ORA-19011: Character string buffer too small, so use getclobval
202+ options . fetchInfo = { "OBJ" : { type : oracledb . STRING } } ;
203+ sql = "select xmltype.getclobval(content) as obj from " + tableName + " where num = :id" ;
204+ result = await conn . execute ( sql , bindVar , options ) ;
205+ assert . strictEqual ( result . rows [ 0 ] . OBJ , xml ) ;
206+ }
205207 await conn . commit ( ) ;
206208 await conn . close ( ) ;
207209 } ) ; // 181.5
208210
211+ it ( '181.6 Insert and Verify Embedded LOB locator inside XML' , async ( ) => {
212+ const ID = 51 ;
213+ const largestr = 'a' . repeat ( 64 * 1024 ) ;
214+ const smallstr = 'a' . repeat ( 1 * 1024 ) ;
215+ const head = '<data>' , tail = '</data>\n' ;
216+ const xml = head . concat ( smallstr ) . concat ( tail ) ;
217+ const largexml = head . concat ( largestr ) . concat ( tail ) ;
218+
219+ const conn = await oracledb . getConnection ( dbConfig ) ;
220+ const lob = await conn . createLob ( oracledb . CLOB ) ;
221+ await lob . write ( largexml ) ;
222+
223+ let sql = `insert into ${ tableName } ( num, content, embedLOBXML )
224+ values(:id, XMLType(:bv1), XMLType(:bv2))` ;
225+ const bindValues = { id : ID , bv1 : xml , bv2 : { type : oracledb . CLOB , val : lob } } ;
226+ let result = await conn . execute ( sql , bindValues ) ;
227+ assert . strictEqual ( result . rowsAffected , 1 ) ;
228+
229+ const bindVar = { id : ID } ;
230+ const options = { outFormat : oracledb . OUT_FORMAT_OBJECT } ;
231+
232+ if ( oracledb . thin ) {
233+ sql = "select embedlobxml as OBJ from " + tableName + " where num = :id" ;
234+ } else {
235+ options . fetchInfo = { "OBJ" : { type : oracledb . STRING } } ;
236+ sql = "select xmltype.getclobval(embedlobxml) as OBJ from " + tableName + " where num = :id" ;
237+ }
238+ result = await conn . execute ( sql , bindVar , options ) ;
239+ assert . strictEqual ( result . rows [ 0 ] . OBJ , largexml ) ;
240+
241+ // free temp lob
242+ await new Promise ( ( resolve ) => {
243+ lob . once ( 'close' , resolve ) ;
244+ lob . destroy ( ) ;
245+ } ) ;
246+ await conn . commit ( ) ;
247+ await conn . close ( ) ;
248+ } ) ; // 181.6
249+
209250} ) ;
0 commit comments