[TD-6078]<fix>: fix binary/nchar null error in node.js [ci skip] (#7366)
This commit is contained in:
parent
9976d7a093
commit
9161244c22
|
@ -109,6 +109,24 @@ function convertDouble(data, num_of_rows, nbytes = 0, offset = 0, precision = 0)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function convertBinary(data, num_of_rows, nbytes = 0, offset = 0, precision = 0) {
|
||||||
|
data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset);
|
||||||
|
let res = [];
|
||||||
|
|
||||||
|
let currOffset = 0;
|
||||||
|
while (currOffset < data.length) {
|
||||||
|
let len = data.readIntLE(currOffset, 2);
|
||||||
|
let dataEntry = data.slice(currOffset + 2, currOffset + len + 2); //one entry in a row under a column;
|
||||||
|
if (dataEntry[0] == 255) {
|
||||||
|
res.push(null)
|
||||||
|
} else {
|
||||||
|
res.push(dataEntry.toString("utf-8"));
|
||||||
|
}
|
||||||
|
currOffset += nbytes;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
function convertNchar(data, num_of_rows, nbytes = 0, offset = 0, precision = 0) {
|
function convertNchar(data, num_of_rows, nbytes = 0, offset = 0, precision = 0) {
|
||||||
data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset);
|
data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset);
|
||||||
let res = [];
|
let res = [];
|
||||||
|
@ -117,7 +135,11 @@ function convertNchar(data, num_of_rows, nbytes = 0, offset = 0, precision = 0)
|
||||||
while (currOffset < data.length) {
|
while (currOffset < data.length) {
|
||||||
let len = data.readIntLE(currOffset, 2);
|
let len = data.readIntLE(currOffset, 2);
|
||||||
let dataEntry = data.slice(currOffset + 2, currOffset + len + 2); //one entry in a row under a column;
|
let dataEntry = data.slice(currOffset + 2, currOffset + len + 2); //one entry in a row under a column;
|
||||||
res.push(dataEntry.toString("utf-8"));
|
if (dataEntry[0] == 255 && dataEntry[1] == 255) {
|
||||||
|
res.push(null)
|
||||||
|
} else {
|
||||||
|
res.push(dataEntry.toString("utf-8"));
|
||||||
|
}
|
||||||
currOffset += nbytes;
|
currOffset += nbytes;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
@ -132,7 +154,7 @@ let convertFunctions = {
|
||||||
[FieldTypes.C_BIGINT]: convertBigint,
|
[FieldTypes.C_BIGINT]: convertBigint,
|
||||||
[FieldTypes.C_FLOAT]: convertFloat,
|
[FieldTypes.C_FLOAT]: convertFloat,
|
||||||
[FieldTypes.C_DOUBLE]: convertDouble,
|
[FieldTypes.C_DOUBLE]: convertDouble,
|
||||||
[FieldTypes.C_BINARY]: convertNchar,
|
[FieldTypes.C_BINARY]: convertBinary,
|
||||||
[FieldTypes.C_TIMESTAMP]: convertTimestamp,
|
[FieldTypes.C_TIMESTAMP]: convertTimestamp,
|
||||||
[FieldTypes.C_NCHAR]: convertNchar
|
[FieldTypes.C_NCHAR]: convertNchar
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
const taos = require('../tdengine');
|
||||||
|
var conn = taos.connect({ host: "localhost" });
|
||||||
|
var c1 = conn.cursor();
|
||||||
|
|
||||||
|
|
||||||
|
function checkData(data, row, col, expect) {
|
||||||
|
let checkdata = data[row][col];
|
||||||
|
if (checkdata == expect) {
|
||||||
|
// console.log('check pass')
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log('check failed, expect ' + expect + ', but is ' + checkdata)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c1.execute('drop database if exists testnodejsnchar')
|
||||||
|
c1.execute('create database testnodejsnchar')
|
||||||
|
c1.execute('use testnodejsnchar');
|
||||||
|
c1.execute('create table tb (ts timestamp, value float, text binary(200))')
|
||||||
|
c1.execute("insert into tb values('2021-06-10 00:00:00', 24.7, '中文10000000000000000000000');") -
|
||||||
|
c1.execute('insert into tb values(1623254400150, 24.7, NULL);')
|
||||||
|
c1.execute('import into tb values(1623254400300, 24.7, "中文3中文10000000000000000000000中文10000000000000000000000中文10000000000000000000000中文10000000000000000000000");')
|
||||||
|
sql = 'select * from tb;'
|
||||||
|
|
||||||
|
console.log('*******************************************')
|
||||||
|
|
||||||
|
c1.execute(sql);
|
||||||
|
data = c1.fetchall();
|
||||||
|
console.log(data)
|
||||||
|
//check data about insert data
|
||||||
|
checkData(data, 0, 2, '中文10000000000000000000000')
|
||||||
|
checkData(data, 1, 2, null)
|
||||||
|
checkData(data, 2, 2, '中文3中文10000000000000000000000中文10000000000000000000000中文10000000000000000000000中文10000000000000000000000')
|
Loading…
Reference in New Issue