From c8dd30ad84e58d4eb66e78e2532c41d845c1ce4a Mon Sep 17 00:00:00 2001 From: NmN03jain Date: Tue, 15 Aug 2023 13:29:58 +0530 Subject: [PATCH 1/3] Replace fucntio is working now --- src/55functions.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/55functions.js b/src/55functions.js index 40e7b9959e..6d4d9347d4 100644 --- a/src/55functions.js +++ b/src/55functions.js @@ -472,7 +472,10 @@ Object.keys(alasql._aggrOriginal).forEach(function (k) { // String functions stdfn.REPLACE = function (target, pattern, replacement) { - return (target || '').split(pattern).join(replacement); + if (typeof target !== 'string') { + throw new TypeError('Target must be a string'); + } + return target.split(pattern).join(replacement); }; // This array is required for fast GUID generation From 93d19c1c19844696d13f97ffb8195c64b4f7361a Mon Sep 17 00:00:00 2001 From: NmN03jain Date: Tue, 15 Aug 2023 14:22:19 +0530 Subject: [PATCH 2/3] adding test1455.js --- test/test1455.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/test1455.js diff --git a/test/test1455.js b/test/test1455.js new file mode 100644 index 0000000000..2a2cb1f6b6 --- /dev/null +++ b/test/test1455.js @@ -0,0 +1,51 @@ +if (typeof exports === 'object') { + var assert = require('assert'); + var alasql = require('..'); +} + +describe('Test 000 - multiple statements', function () { + const test = '000'; // insert test file number + + before(function () { + alasql('create database test' + test); + alasql('use test' + test); + }); + + after(function () { + alasql('drop database test' + test); + }); + + it('A) From single lines', function () { + var res = []; + res.push(alasql('create table one (a int)')); + res.push(alasql('insert into one values (1),(2),(3),(4),(5)')); + res.push(alasql('select * from one')); + assert.deepEqual(res, [1, 5, [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}]]); + }); + + it('B) Multiple statements in one string', function () { + // + var sql = 'create table two (a int);'; + sql += 'insert into two values (1),(2),(3),(4),(5);'; + sql += 'select * from two;'; + var res = alasql(sql); + assert.deepEqual(res, [1, 5, [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}]]); + }); + + it('C) Multiple statements in one string with callback', function (done) { + // Please note that first parameter (here `done`) must be called if defined - and is needed when testing async code + var sql = 'create table three (a int);'; + sql += 'insert into three values (1),(2),(3),(4),(5);'; + sql += 'select * from three;'; + alasql(sql, function (res) { + assert.deepEqual(res, [1, 5, [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}]]); + done(); + }); + }); +}); +stdfn.REPLACE = function (target, pattern, replacement) { + if (typeof target !== 'string') { + throw new TypeError('Target must be a string'); + } + return target.split(pattern).join(replacement); +}; \ No newline at end of file From 3ff33f66a9c02f7095d203191134b4dedc2dc05d Mon Sep 17 00:00:00 2001 From: Naman Jain <90062260+NmN03jain@users.noreply.github.com> Date: Thu, 17 Aug 2023 01:50:13 +0530 Subject: [PATCH 3/3] Update 55functions.js --- src/55functions.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/55functions.js b/src/55functions.js index 6d4d9347d4..3958db2910 100644 --- a/src/55functions.js +++ b/src/55functions.js @@ -472,10 +472,7 @@ Object.keys(alasql._aggrOriginal).forEach(function (k) { // String functions stdfn.REPLACE = function (target, pattern, replacement) { - if (typeof target !== 'string') { - throw new TypeError('Target must be a string'); - } - return target.split(pattern).join(replacement); + return (target.toString() || '').split(pattern).join(replacement); }; // This array is required for fast GUID generation