node.js连接DB2实现fetchRows一行一行获取sql的源码

Posted <・)))><<

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了node.js连接DB2实现fetchRows一行一行获取sql的源码相关的知识,希望对你有一定的参考价值。

参见程序中的queryResult那部分:

/*
 * This example demonstrates how to fetch a single row from a large table
 * one by one and get processed by application. It avoids allocation of 
 * large memory by the ibm_db and data processing becomes easier.
 *
 * This example has used Sync methods, but async methods also exist.
 */

var ibmdb = require("../") //require("ibm_db")
  , conn = new ibmdb.Database()
  , cn = "database=sample;hostname=hotel.torolab.ibm.com;port=21169;uid=newton;pwd=xxxx"
  ;

// open a connection to the database
conn.openSync(cn);

// create table and insert some rows to it.
conn.querySync("create table mytab (c1 int, c2 varchar(20))");
conn.querySync("insert into mytab values (1, ‘bimal‘),(2, ‘kamal‘),(3,‘mohan‘),(4,‘ram‘)");

// Select data from table
conn.queryResult("select * from mytab", function (err, result) {
  if(err) {
    console.log(err);
    return;
  }
  
  // Fetch single row at once and process it.
  // Note that queryResult will bring only 64k data from server and result.fetchSync
  // will return each row from this 64k client buffer. Once all data is read from
  // buffer, ibm_db driver will bring another 64k chunk of data from server.
  var data;
  while( data = result.fetchSync() )
  {
    console.log(data);
  }

  // drop the table and close connection.
  conn.querySync("drop table mytab");
  conn.closeSync();
});

参考链接:https://github.com/ibmdb/node-ibm_db/blob/master/examples/singleRowFetch.js

以上是关于node.js连接DB2实现fetchRows一行一行获取sql的源码的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 Node.js 为所有连接最好地实现 HTTPS?

如何在 node.js 中使用 sequelize-npm 实现与连接表的一对多关系

基于node.js搭建简单的MQTT服务器,手机通过热点连接电脑实现MQTT服务器测试

fetchrow_hashref 是不是返回默认值?

node.js如何配置mongodb连接池?

DB2如何实现远程连接