@@ -504,8 +504,8 @@ describe('271. fetchTypeHandler.js', function() {
504504 const clobVal = '[-1, 2, 3]' ;
505505 const blobVal = Buffer . from ( '{ "KeyA": 8, "KeyB": "A String" }' ) ;
506506 const charVal = '[-2, 2, 3, [34, 23, 24]]' ;
507- const defaultFetchTypeHandler = oracledb . fetchTypeHandler ;
508507
508+ oracledb . future . oldJsonColumnAsObj = true ;
509509 await connection . execute ( plsql ) ;
510510 const sql = `INSERT into ${ TABLE } VALUES (:1, :2, :3)` ;
511511 await connection . execute ( sql , [ clobVal , blobVal , charVal ] ) ;
@@ -515,27 +515,29 @@ describe('271. fetchTypeHandler.js', function() {
515515 assert . deepStrictEqual ( result . rows [ 0 ] [ 1 ] , JSON . parse ( blobVal ) ) ;
516516 assert . deepStrictEqual ( result . rows [ 0 ] [ 2 ] , JSON . parse ( charVal ) ) ;
517517
518- // User defined handler can overwrite the default behaviour of
519- // converting IS JSON columns to JSON objects.
518+ // fetchtype handlers given preference than oldJsonColumnAsObj setting.
519+ const defaultFetchTypeHandler = oracledb . fetchTypeHandler ;
520+
521+ // register typehandler only for BLOB.
522+ // For other columns, they are still returned as JSON object.
520523 oracledb . fetchTypeHandler = function ( metaData ) {
521- // overwrite only for BLOB type to return LOB object.
522524 if ( metaData . isJson && metaData . dbType === oracledb . DB_TYPE_BLOB ) {
523525 const myConverter = ( v ) => {
524526 return v ;
525527 } ;
526528 return { converter : myConverter } ;
527529 }
528530 } ;
529- // mark fetch type for CLOB column as string but it will be
530- // converted to JSON object unless handler for CLOB is written.
531- result = await connection . execute ( `select cdata, bdata, chardata from ${ TABLE } ` , { } , {
532- fetchInfo : { CDATA : { type : oracledb . STRING } }
533- } ) ;
534- oracledb . fetchTypeHandler = defaultFetchTypeHandler ;
531+ result = await connection . execute ( `select * from ${ TABLE } ` ) ;
535532 assert . deepStrictEqual ( result . rows [ 0 ] [ 0 ] , JSON . parse ( clobVal ) ) ;
536- assert ( result . rows [ 0 ] [ 1 ] instanceof oracledb . Lob ) ;
533+ const blobData = await result . rows [ 0 ] [ 1 ] . getData ( ) ;
534+ assert . deepStrictEqual ( blobData , blobVal ) ;
537535 assert . deepStrictEqual ( result . rows [ 0 ] [ 2 ] , JSON . parse ( charVal ) ) ;
538536
537+ // restore the global settings.
538+ oracledb . future . oldJsonColumnAsObj = false ;
539+ oracledb . fetchTypeHandler = defaultFetchTypeHandler ;
540+
539541 await connection . execute ( testsUtil . sqlDropTable ( TABLE ) ) ;
540542 } ) ;
541543
0 commit comments