2016-05-28 33 views
1

我的桌子上有一個clob列。我使用oracledb驅動程序從我的快車應用程序連接到數據庫。我想打印出這個clob。這是我的代碼:Clob在快速應用程序中未正確打印

router.get('/:task_name', function (req,res) { 
"use strict"; 

oracledb.getConnection(connAttrs.database, function (err, connection) { 
    if (err) { 
     // Error connecting to DB 
     res.set('Content-Type', 'application/json'); 
     res.status(500).send(JSON.stringify({ 
      status: 500, 
      message: "Error connecting to DB", 
      detailed_message: err.message 
     })); 
     return; 
    } 

    connection.execute("select solution from solvedtasks s join tasks t on t.TASK_ID = s.TASK_ID WHERE task_name= :task_name", [req.params.task_name],{ 
     outFormat: oracledb.OBJECT //resultSet:true, 

    }, function (err, result) { 
     if (err) { 
      res.set('Content-Type', 'application/json'); 
      res.status(500).send(JSON.stringify({ 
       status: 500, 
       message: "Error getting the user profile", 
       detailed_message: err.message 
      })); 
     } else { 
      res.contentType('application/json').status(200); 
      res.send(JSON.stringify(result.rows[0])); 
      console.log(result.rows[0]); 
      // fetchRowsFromRS(connection,res,result.resultSet,10); 
     } 
     // Release the connection 

     connection.release(
      function (err) { 
       if (err) { 
        console.error(err.message); 
       } else { 
        console.log("GET /SolvedTasks : Connection released"); 
       } 
      }); 

    }); 
    }); 
}); 

而不是打印從我的數據庫的CLOB我得到的東西看起來像吊射元數據。有其他人遇到過這個問題嗎?這裏是我的輸出截圖: Clob output

回答

1

所以我解決了這個問題,我發佈了一個答案,以防有人遇到這個問題。顯然原來的oracledb驅動程序有一些處理clobs的問題。但有增強其功能庫,稱爲簡單OracleDB的,非常容易使用和安裝:https://github.com/sagiegurari/simple-oracledb

使用connection.query,CLOB的是妥善處理:

enter code here 
connection.query('SELECT * FROM departments WHERE manager_id > :id', [110],  { 
    splitResults: true, //True to enable to split the results into bulks, each bulk will invoke the provided callback (last callback invocation will have empty results) 
    bulkRowsAmount: 100 //The amount of rows to fetch (for splitting results, that is the max rows that the callback will get for each callback invocation) 
}, function onResults(error, results) { 
    if (error) { 
    //handle error... 
    } else if (results.length) { 
    //handle next bulk of results 
    } else { 
    //all rows read 
    } 
});