Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace fucntion is working now #1455 #1774

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/55functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ Object.keys(alasql._aggrOriginal).forEach(function (k) {

// String functions
stdfn.REPLACE = function (target, pattern, replacement) {
return (target || '').split(pattern).join(replacement);
return (target.toString() || '').split(pattern).join(replacement);
};

// This array is required for fast GUID generation
Expand Down
51 changes: 51 additions & 0 deletions test/test1455.js
Original file line number Diff line number Diff line change
@@ -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);
};