未验证 提交 93f71456 编写于 作者: H huili 提交者: GitHub

Merge pull request #4707 from taosdata/hotfix/TD-2550

[TD-2550]<fix>: fix nodejs connector of td2.0-connector cannot use in…
...@@ -144,18 +144,9 @@ function convertBinary(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { ...@@ -144,18 +144,9 @@ function convertBinary(data, num_of_rows, nbytes = 0, offset = 0, micro=false) {
function convertNchar(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { function convertNchar(data, num_of_rows, nbytes = 0, offset = 0, micro=false) {
data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset);
let res = []; let res = [];
let currOffset = 0; let dataEntry = data.slice(0, nbytes); //one entry in a row under a column;
// every 4 bytes, a character is encoded; //TODO: should use the correct character encoding
while (currOffset < data.length) { res.push(dataEntry.toString("utf-8"));
let dataEntry = data.slice(currOffset, currOffset + nbytes); //one entry in a row under a column;
if (dataEntry.readInt64LE(0) == FieldTypes.C_NCHAR_NULL) {
res.push(null);
}
else {
res.push(dataEntry.toString("utf16le").replace(/\u0000/g, ""));
}
currOffset += nbytes;
}
return res; return res;
} }
...@@ -351,7 +342,8 @@ CTaosInterface.prototype.useResult = function useResult(result) { ...@@ -351,7 +342,8 @@ CTaosInterface.prototype.useResult = function useResult(result) {
CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) { CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) {
//let pblock = ref.ref(ref.ref(ref.NULL)); // equal to our raw data //let pblock = ref.ref(ref.ref(ref.NULL)); // equal to our raw data
let pblock = this.libtaos.taos_fetch_row(result); let pblock = this.libtaos.taos_fetch_row(result);
if (pblock == null) { let num_of_rows = 1;
if (ref.isNull(pblock) == true) {
return {block:null, num_of_rows:0}; return {block:null, num_of_rows:0};
} }
...@@ -363,17 +355,16 @@ CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) { ...@@ -363,17 +355,16 @@ CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) {
if (ref.isNull(fieldL) == false) { if (ref.isNull(fieldL) == false) {
for (let i = 0; i < fields.length; i ++) { for (let i = 0; i < fields.length; i ++) {
let plen = ref.reinterpret(fieldL, 4, i*4); let plen = ref.reinterpret(fieldL, 4, i*4);
let len = plen.readInt32LE(0); let len = plen.readInt32LE(0);
fieldlens.push(len); fieldlens.push(len);
} }
} }
let blocks = new Array(fields.length); let blocks = new Array(fields.length);
blocks.fill(null); blocks.fill(null);
num_of_rows = Math.abs(num_of_rows); //num_of_rows = Math.abs(num_of_rows);
let offset = 0; let offset = 0;
pblock = pblock.deref();
for (let i = 0; i < fields.length; i++) { for (let i = 0; i < fields.length; i++) {
pdata = ref.reinterpret(pblock,8,i*8); pdata = ref.reinterpret(pblock,8,i*8);
pdata = ref.ref(pdata.readPointer()); pdata = ref.ref(pdata.readPointer());
......
...@@ -25,6 +25,7 @@ function TaosResult(data, fields) { ...@@ -25,6 +25,7 @@ function TaosResult(data, fields) {
* @function pretty * @function pretty
* @since 1.0.6 * @since 1.0.6
*/ */
TaosResult.prototype.pretty = function pretty() { TaosResult.prototype.pretty = function pretty() {
let fieldsStr = ""; let fieldsStr = "";
let sizing = []; let sizing = [];
...@@ -46,8 +47,7 @@ TaosResult.prototype.pretty = function pretty() { ...@@ -46,8 +47,7 @@ TaosResult.prototype.pretty = function pretty() {
row.data.forEach((entry, i) => { row.data.forEach((entry, i) => {
if (this.fields[i]._field.type == 9) { if (this.fields[i]._field.type == 9) {
entry = entry.toTaosString(); entry = entry.toTaosString();
} } else {
else {
entry = entry == null ? 'null' : entry.toString(); entry = entry == null ? 'null' : entry.toString();
} }
rowStr += entry rowStr += entry
......
...@@ -48,6 +48,7 @@ for (let i = 0; i < 10000; i++) { ...@@ -48,6 +48,7 @@ for (let i = 0; i < 10000; i++) {
// Select // Select
console.log('select * from td_connector_test.all_types limit 3 offset 100;'); console.log('select * from td_connector_test.all_types limit 3 offset 100;');
c1.execute('select * from td_connector_test.all_types limit 2 offset 100;'); c1.execute('select * from td_connector_test.all_types limit 2 offset 100;');
var d = c1.fetchall(); var d = c1.fetchall();
console.log(c1.fields); console.log(c1.fields);
console.log(d); console.log(d);
...@@ -77,13 +78,24 @@ c1.query('select stddev(_double), stddev(_bigint), stddev(_float) from all_types ...@@ -77,13 +78,24 @@ c1.query('select stddev(_double), stddev(_bigint), stddev(_float) from all_types
}) })
// Binding arguments, and then using promise // Binding arguments, and then using promise
var q = c1.query('select * from td_connector_test.all_types where ts >= ? and _int > ? limit 100 offset 40;').bind(new Date(1231), 100) var q = c1.query('select _nchar from td_connector_test.all_types where ts >= ? and _int > ? limit 100 offset 40;').bind(new Date(1231), 100)
console.log(q.query); console.log(q.query);
q.execute().then(function(r) { q.execute().then(function(r) {
r.pretty(); r.pretty();
}); });
var q = c1.query('select * from td_connector_test.weather');
console.log(q.query);
q.execute().then(function(r) {
//console.log(r);
r.pretty();
});
function sleep(sleepTime) {
for(var start = +new Date; +new Date - start <= sleepTime; ) { }
}
sleep(10000);
// Raw Async Testing (Callbacks, not promises) // Raw Async Testing (Callbacks, not promises)
function cb2(param, result, rowCount, rd) { function cb2(param, result, rowCount, rd) {
...@@ -129,16 +141,21 @@ setTimeout(function(){ ...@@ -129,16 +141,21 @@ setTimeout(function(){
c1.fetchall_a(thisRes, cb4, param); c1.fetchall_a(thisRes, cb4, param);
},100); },100);
// Async through promises // Async through promises
var aq = c1.query('select count(*) from td_connector_test.all_types;',false); var aq = c1.query('select count(*) from td_connector_test.all_types;',false);
aq.execute_a().then(function(data) { aq.execute_a().then(function(data) {
data.pretty(); data.pretty();
}); });
c1.query('describe td_connector_test.stabletest;').execute_a().then(r=> r.pretty());
c1.query('describe td_connector_test.stabletest').execute_a().then(function(r){
r.pretty()
});
setTimeout(function(){ setTimeout(function(){
c1.query('drop database td_connector_test;'); c1.query('drop database td_connector_test;');
},200); },200);
setTimeout(function(){ setTimeout(function(){
conn.close(); conn.close();
},2000); },2000);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册