问题1: 正常来讲应该显示有500条记录。为什么只显示一条呢,查了相关文档也没说关于这一块的。希望大神指导下!如何才能全部显示出来呢? 代码如下:
Mingo.getsales=function getsales(callback){
var sqlstr="select * from Contract";
var connection = new sql.Connection(connects, function (err) {
if (err) console.log(err);//判断异常
var request = new sql.Request(connection);
request.multiple = true;
request.query(sqlstr, function (err, recordsets) {
if(recordsets.length===0) callback(err,'[]');
console.log(recordsets.length); // return 1
callback(err,recordsets);
});
});
}
结果显示为1。 问题2
var sqlstr="select b.name, sum(a.bldarea) as bldarea,convert(varchar(7),a.qdate,120) as qdate ";
sqlstr+=" from Contract left join project on a.pid=b.pid where name='AAA' group by b.name order by b.name,qdate";
为什么执行这一条sql的结果为空?实际在sql查询分析中是有值的! 诚邀大神@a272121742 md说明还有个方法。但是不太明白该怎么用
Streaming example with one global connection
If you plan to work with large amount of rows, you should always use streaming. Once you enable this, you must listen for events to receive data.
var sql = require('mssql');
var config = {
user: '...',
password: '...',
server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
database: '...',
stream: true, // You can enable streaming globally
options: {
encrypt: true // Use this if you're on Windows Azure
}
}
sql.connect(config, function(err) {
// ... error checks
var request = new sql.Request();
request.stream = true; // You can set streaming differently for each request
request.query('select * from verylargetable'); // or request.execute(procedure);
request.on('recordset', function(columns) {
// Emitted once for each recordset in a query
这里该怎么用,不是太明白,没有看到相应的demo
});
request.on('row', function(row) {
// Emitted for each row in a recordset
?????
});
request.on('error', function(err) {
// May be emitted multiple times
????
});
request.on('done', function(returnValue) {
// Always emitted as the last one
???
});
});
其实他有一个这样的方法,我没太懂该怎么用。
来个人吧。大神@a272121742
诚邀各位大神关注下。谢谢 @jiyinyiyong @alsotang @leapon @youxiachai
微软的东西不适合node(主要是服务器的问题,不适合互联网项目),哈哈,node搭配mysql和mongodb比较好
@saighost 我用的是mssql这个https://github.com/patriksimek/node-mssql#cfg-msnodesql
@saighost 应该是你认错人了吧。
@i5ting 现在没办法,必须要从这个数据库里拿东西。没辙啊。
@saighost 方便给我一个详细点的demo吗?嗯。数据库是05版的。感谢!
@saighost tds的地址方便给我一个吗?我搜了下发现好几个。
Streaming example with one global connection
If you plan to work with large amount of rows, you should always use streaming. Once you enable this, you must listen for events to receive data.
var sql = require('mssql');
var config = {
user: '...',
password: '...',
server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
database: '...',
stream: true, // You can enable streaming globally
options: {
encrypt: true // Use this if you're on Windows Azure
}
}
sql.connect(config, function(err) {
// ... error checks
var request = new sql.Request();
request.stream = true; // You can set streaming differently for each request
request.query('select * from verylargetable'); // or request.execute(procedure);
request.on('recordset', function(columns) {
// Emitted once for each recordset in a query
这里该怎么用,不是太明白,没有看到相应的demo
});
request.on('row', function(row) {
// Emitted for each row in a recordset
?????
});
request.on('error', function(err) {
// May be emitted multiple times
????
});
request.on('done', function(returnValue) {
// Always emitted as the last one
???
});
});
其实他有一个这样的方法,我没太懂该怎么用。
大神来指点一下啊
@saighost 非常感谢啦