diff --git a/src/connector/nodejs/examples/cursorClose.js b/src/connector/nodejs/examples/cursorClose.js new file mode 100644 index 0000000000000000000000000000000000000000..1c00f652ad7bf2d504c18195dde19d8f17ba3e73 --- /dev/null +++ b/src/connector/nodejs/examples/cursorClose.js @@ -0,0 +1,49 @@ +const taos = require('../tdengine'); + +const conn = taos.connect({ + host: "localhost", +}); + +const cursor = conn.cursor(); + +function createDatabase() { + cursor.execute("CREATE DATABASE if not exists test_cursor_close"); + cursor.execute("USE test_cursor_close"); +} + +function insertData() { + const lines = [ + "meters,location=Beijing.Haidian,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249", + "meters,location=Beijing.Haidian,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611250", + "meters,location=Beijing.Haidian,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249", + "meters,location=Beijing.Haidian,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611250", + ]; + cursor.schemalessInsert( + lines, + taos.SCHEMALESS_PROTOCOL.TSDB_SML_LINE_PROTOCOL, + taos.SCHEMALESS_PRECISION.TSDB_SML_TIMESTAMP_MILLI_SECONDS + ); +} + +function query() { + let promise = cursor.query("select * from test_cursor_close.meters"); + promise.execute().then(result => result.pretty()).catch(err => console.log(e)); +} + +function destructData() { + cursor.execute("drop database if exists test_cursor_close"); +} + +function main() { + try { + createDatabase(); + insertData(); + query(); + destructData(); + } finally { + cursor.close(); + conn.close(); + } +} + +main(); \ No newline at end of file diff --git a/src/connector/nodejs/nodetaos/cursor.js b/src/connector/nodejs/nodetaos/cursor.js index 54431d9e98489481e3bdaa9433ef38177ce51b63..afd9fbcf472c8de3f47ffb52d0f705822d23dfcf 100644 --- a/src/connector/nodejs/nodetaos/cursor.js +++ b/src/connector/nodejs/nodetaos/cursor.js @@ -57,7 +57,7 @@ TDengineCursor.prototype.close = function close() { if (this._connection == null) { return false; } - this._connection._clearResultSet(); + // this._connection._clearResultSet(); this._reset_result(); this._connection = null; return true; diff --git a/src/connector/nodejs/test/cases/test.cases.js b/src/connector/nodejs/test/cases/test.cases.js index 6cf723331ef4330d56ee5d0db38e0a30b57eadb3..2bf92a1c1523cc48a0d2c0b7cabbc778c075cf44 100644 --- a/src/connector/nodejs/test/cases/test.cases.js +++ b/src/connector/nodejs/test/cases/test.cases.js @@ -48,6 +48,7 @@ beforeAll(() => { // Jest will wait for this promise to resolve before running tests. afterAll(() => { executeUpdate("drop database if exists node_test_db;"); + c1.close(); conn.close(); }); diff --git a/src/connector/nodejs/test/cases/test.stmt.js b/src/connector/nodejs/test/cases/test.stmt.js index 235178bb7c59ad5b6f15d179a55979f71a9e268a..78893479d8cd37c79f26bb6329e9bcbb56f825c4 100644 --- a/src/connector/nodejs/test/cases/test.stmt.js +++ b/src/connector/nodejs/test/cases/test.stmt.js @@ -95,6 +95,7 @@ beforeAll(() => { // Jest will wait for this promise to resolve before running tests. afterAll(() => { executeUpdate(`drop database if exists ${dbName};`); + c1.close(); conn.close(); });