@@ -167,7 +167,6 @@ describe('41. dataTypeBlob.js', function() {
167167 const plsql = testsUtil . sqlCreateTable ( TABLE , createTable ) ;
168168
169169 before ( 'create table' , async function ( ) {
170- oracledb . fetchAsBuffer = [ oracledb . BLOB ] ;
171170 if ( testsUtil . getClientVersion ( ) >= 2100000000 &&
172171 connection . oracleServerVersion >= 2100000000 ) {
173172 isRunnable = true ;
@@ -177,11 +176,13 @@ describe('41. dataTypeBlob.js', function() {
177176 this . skip ( ) ;
178177 }
179178
179+ // Allows automatically converting OSON formatted columns to JSON objects.
180+ oracledb . future . oldJsonColumnAsObj = true ;
180181 await connection . execute ( plsql ) ;
181182 } ) ;
182183
183184 after ( async function ( ) {
184- oracledb . fetchAsBuffer = [ ] ;
185+ oracledb . future . oldJsonColumnAsObj = false ;
185186 await connection . execute ( testsUtil . sqlDropTable ( TABLE ) ) ;
186187 } ) ;
187188
@@ -203,25 +204,30 @@ describe('41. dataTypeBlob.js', function() {
203204 values (1, :1, :2) ` ,
204205 [ byteBuf , byteBuf ] ) ;
205206 result = await connection . execute ( `select OSONCOL from ${ TABLE } ` ) ;
206- let generatedObj = connection . decodeOSON ( result . rows [ 0 ] [ 0 ] ) ;
207- assert . deepStrictEqual ( expectedObj1 , generatedObj ) ;
207+ assert . deepStrictEqual ( expectedObj1 , result . rows [ 0 ] [ 0 ] ) ;
208208
209209 // Generate OSON bytes and insert these bytes and verify with decode.
210210 const osonBytes = connection . encodeOSON ( expectedObj2 ) ;
211211 result = await connection . execute ( `insert into ${ TABLE } (IntCol, OsonCol, blobCol)
212212 values (2, :1, :2) ` ,
213213 [ osonBytes , byteBuf ] ) ;
214214 result = await connection . execute ( `select OSONCOL from ${ TABLE } where IntCol = 2` ) ;
215- generatedObj = connection . decodeOSON ( result . rows [ 0 ] [ 0 ] ) ;
216- assert . deepStrictEqual ( expectedObj2 , generatedObj ) ;
215+ assert . deepStrictEqual ( expectedObj2 , result . rows [ 0 ] [ 0 ] ) ;
217216
218217 // Verify vector inside OSON image for 23.4 server onwards.
219218 if ( connection . oracleServerVersion >= 2304000000 ) {
220219 result = await connection . execute ( `insert into ${ TABLE } (IntCol, OsonCol, blobCol)
221220 values (3, :1, :2) ` ,
222221 [ connection . encodeOSON ( expectedObj3 ) , byteBuf ] ) ;
223222 result = await connection . execute ( `select OSONCOL from ${ TABLE } where IntCol = 3` ) ;
224- generatedObj = connection . decodeOSON ( result . rows [ 0 ] [ 0 ] ) ;
223+ assert . deepStrictEqual ( expectedObj3 , result . rows [ 0 ] [ 0 ] ) ;
224+
225+ // Verify LOB is returned by default (oracledb.future.oldJsonColumnAsObj = false).
226+ // We need to explicitly use decodeOSON to convert the LOB data into JSON object.
227+ oracledb . future . oldJsonColumnAsObj = false ;
228+ result = await connection . execute ( `select OSONCOL from ${ TABLE } where IntCol = 3` ) ;
229+ const lob = result . rows [ 0 ] [ 0 ] ;
230+ const generatedObj = connection . decodeOSON ( await lob . getData ( ) ) ;
225231 assert . deepStrictEqual ( expectedObj3 , generatedObj ) ;
226232 }
227233
0 commit comments