Skip to content
Merged
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
5 changes: 0 additions & 5 deletions src/40select.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ yy.Select = class Select {
Select statement in expression
*/
toJS(context) {
// console.log('Expression',this);
// if(this.expression.reduced) return 'true';
// return this.expression.toJS(context, tableid, defcols);
// console.log('Select.toJS', 81, this.queriesidx);
// var s = 'this.queriesdata['+(this.queriesidx-1)+'][0]';
var s =
'alasql.utils.flatArray(this.queriesfn[' +
(this.queriesidx - 1) +
Expand Down
4 changes: 3 additions & 1 deletion src/55functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,9 @@ Object.keys(alasql._aggrOriginal).forEach(function (k) {

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

// This array is required for fast GUID generation
Expand Down
1 change: 1 addition & 0 deletions src/alasqlparser.jison
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ SETS return 'SET'
%left DOT ARROW EXCLAMATION
%left TILDA
%left SHARP

%left BARBAR

%ebnf
Expand Down
31 changes: 31 additions & 0 deletions test/test1455.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}

describe('Test 1455 - REPLACE function', function () {
it('A) REPLACE with string target', function () {
var res = alasql("SELECT REPLACE('123', '2', '_')");
assert.deepEqual(res, [{["REPLACE('123','2','_')"]: '1_3'}]);
});

it('B) REPLACE with numeric target (converted to string)', function () {
var res = alasql("SELECT REPLACE(123, '2', '_')");
assert.deepEqual(res, [{["REPLACE(123,'2','_')"]: '1_3'}]);
});

it('C) Both string and numeric in same query', function () {
var res = alasql("SELECT REPLACE('123', '2', '_'), REPLACE(123, '2', '_')");
assert.deepEqual(res, [
{
["REPLACE('123','2','_')"]: '1_3',
["REPLACE(123,'2','_')"]: '1_3',
},
]);
});

it('D) REPLACE with numeric search and replacement', function () {
var res = alasql('SELECT REPLACE(12321, 2, 9)');
assert.deepEqual(res, [{['REPLACE(12321,2,9)']: '19391'}]);
});
});
Loading