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

PR pain #1942

Merged
merged 4 commits into from
Jul 8, 2024
Merged

PR pain #1942

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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,15 @@ AlaSQL is an [OPEN Open Source Project](http://openopensource.org/). This means

We appreciate any and all contributions we can get. If you feel like contributing, have a look at [CONTRIBUTING.md](https://github.com/alasql/alasql/blob/develop/CONTRIBUTING.md)

## Rebuilding the parser

To rebuild the parser, follow these steps:

* Make changes to alasqlparser.jison
* `npm install -g jison`
* `npm run jison`
* `npm test` to validate the changes made
* Commit changes to alasqlparser.jison and alasqlparser.js

## Credits

Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
"scripts": {
"test": "sh build.sh && yarn test-only",
"test-ci": "(yarn test-format || 1) && yarn test && yarn install-g && alasql 'select 1 as Succes'",
"test-only": "mocha ./test --reporter dot # npx bun node_modules/.bin/mocha ./test --reporter dot",
"test-only": "node node_modules/mocha/bin/mocha.js ./test --reporter dot",
"#test-only": "(command -v bun && bun node_modules/.bin/mocha ./test --reporter dot) || npx bun node_modules/.bin/mocha ./test --reporter dot",
"test-browser": "node test/browserTestRunner.js 7387",
"test-cover": "# istanbul cover -x 'lib/zt/zt.js' --dir test/coverage _mocha",
"build": "yarn format && yarn build-only",
"build-only": "sh build.sh",
"install-g": "yarn build && npm uninstall alasql -g && npm install -g .",
"release": "yarn version",
"jison": "npx jison-gho ./src/alasqlparser.jison -o ./src/alasqlparser.js",
"jison": "jison ./src/alasqlparser.jison -o ./src/alasqlparser.js",
"fmt": "yarn pretty-commit --write",
"format": "yarn pretty-since-dev --write",
"format-all": "yarn pretty-all --write",
Expand Down Expand Up @@ -53,27 +53,27 @@
"blueimp-md5": "2.19.0",
"cmdmix": "2.1.1",
"dom-storage": "2.1.0",
"esbuild": "0.21.3",
"esbuild": "0.23.0",
"eslint": "8.57.0",
"eslint-config-standard": "17.1.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-n": "16.6.2",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "6.1.1",
"eslint-plugin-promise": "6.4.0",
"git-branch-is": "4.0.0",
"husky": "8.0.3",
"jison-gho": "^0.6.1-216",
"lint-staged": "15.2.2",
"mocha": "10.4.0",
"jison": "^0.4.18",
"lint-staged": "15.2.7",
"mocha": "10.6.0",
"mocha.parallel": "0.15.6",
"open": "10.1.0",
"prettier": "3.2.5",
"prettier": "3.3.2",
"react-native-fetch-blob": "^0.10.8",
"react-native-fs": "^2.20.0",
"rexreplace": "7.1.3",
"strftime": "0.10.2",
"strftime": "0.10.3",
"tabletop": "1.6.3",
"uglify-js": "3.17.4"
"uglify-js": "3.18.0"
},
"resolutions": {
"got": "14.2.1",
Expand Down
19 changes: 19 additions & 0 deletions src/61date.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ stdfn.NOW = function () {
stdfn.GETDATE = stdfn.NOW;
stdfn.CURRENT_TIMESTAMP = stdfn.NOW;

/**
* Returns the current date, without time component.
* @returns date object without time component
*/
stdfn.CURDATE = stdfn.CURRENT_DATE = function () {
var date = new Date();
date.setHours(0, 0, 0, 0);
if (alasql.options.dateAsString) {
var s =
date.getFullYear() +
'-' +
('0' + (date.getMonth() + 1)).substr(-2) +
'-' +
('0' + date.getDate()).substr(-2);
return s;
}
return date;
};

// stdfn.GETDATE = function(){
// var d = new Date();
// var s = d.getFullYear()+"."+("0"+(d.getMonth()+1)).substr(-2)+"."+("0"+d.getDate()).substr(-2);
Expand Down
8 changes: 8 additions & 0 deletions src/alasqlparser.jison
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ COLUMNS return 'COLUMN'
"CROSS" return 'CROSS'
'CUBE' return 'CUBE'
"CURRENT_TIMESTAMP" return 'CURRENT_TIMESTAMP'
"CURRENT_DATE" return 'CURRENT_DATE'
"CURDATE" return 'CURRENT_DATE'
"CURSOR" return 'CURSOR'
DATABASE(S)? return 'DATABASE'
'DATEADD' return 'DATEADD'
Expand Down Expand Up @@ -1259,6 +1261,8 @@ Expression
{$$ = $1}
| CURRENT_TIMESTAMP
{ $$ = new yy.FuncValue({funcid:'CURRENT_TIMESTAMP'});}
| CURRENT_DATE
{ $$ = new yy.FuncValue({funcid:'CURRENT_DATE'});}
/* | USER
{ $$ = new yy.FuncValue({funcid:'USER'});}
*/ ;
Expand Down Expand Up @@ -1313,6 +1317,8 @@ PrimitiveValue
{ $$ = $1; }
| CURRENT_TIMESTAMP
{ $$ = new yy.FuncValue({funcid:'CURRENT_TIMESTAMP'}); }
| CURRENT_DATE
{ $$ = new yy.FuncValue({funcid:'CURRENT_DATE'}); }
/* | USER
{ $$ = new yy.FuncValue({funcid:'USER'}); }
*/ ;
Expand Down Expand Up @@ -1387,6 +1393,8 @@ FuncValue
{ $$ = new yy.FuncValue({ funcid: 'IIF', args:$3 }) }
| REPLACE LPAR ExprList RPAR
{ $$ = new yy.FuncValue({ funcid: 'REPLACE', args:$3 }) }
| CURRENT_DATE LPAR RPAR
{ $$ = new yy.FuncValue({ funcid: $1 }) }
| DATEADD LPAR Literal COMMA Expression COMMA Expression RPAR
{ $$ = new yy.FuncValue({ funcid: 'DATEADD', args:[new yy.StringValue({value:$3}),$5,$7]}) }
| DATEADD LPAR STRING COMMA Expression COMMA Expression RPAR
Expand Down
1,150 changes: 580 additions & 570 deletions src/alasqlparser.js

Large diffs are not rendered by default.

32 changes: 19 additions & 13 deletions test/test1684.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,30 @@ if (typeof exports === 'object') {

describe('Test 1684 - UNION ALL still not returning correct results bug', function () {
it('1. should not insert empty objects in results when using UNION ALL Expression', function (done) {
var data = [
{ "city": "Madrid", "population": 3041579 },
{ "city": "Rome", "population": 2863223 },
{ "city": "Paris", "population": 2249975 }
]
var sql = "SELECT city FROM :data WHERE city = 'Madrid' \
var data = [
{city: 'Madrid', population: 3041579},
{city: 'Rome', population: 2863223},
{city: 'Paris', population: 2249975},
];
var sql =
"SELECT city FROM :data WHERE city = 'Madrid' \
UNION ALL SELECT city FROM :data WHERE city = 'Rome' \
UNION ALL SELECT city FROM :data WHERE city = 'Paris' \
"
var res = alasql(sql, { data });
assert.deepEqual(res, [{ city: 'Madrid' }, { city: 'Rome' }, { city: 'Paris' }]);
";
var res = alasql(sql, {data});
assert.deepEqual(res, [{city: 'Madrid'}, {city: 'Rome'}, {city: 'Paris'}]);

var sql = "SELECT * FROM :data WHERE city = 'Madrid' \
var sql =
"SELECT * FROM :data WHERE city = 'Madrid' \
UNION ALL SELECT * FROM :data WHERE city = 'Rome' \
UNION ALL SELECT * FROM :data WHERE city = 'Paris' \
"
var res = alasql(sql, { data });
assert.deepEqual(res, [{ city: 'Madrid', population: 3041579 }, { city: 'Rome', population: 2863223 }, { city: 'Paris', population: 2249975 }]);
";
var res = alasql(sql, {data});
assert.deepEqual(res, [
{city: 'Madrid', population: 3041579},
{city: 'Rome', population: 2863223},
{city: 'Paris', population: 2249975},
]);

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

describe('Test 1936 - Check CURDATE', function () {
it('CURDATE in SELECT - as Date', function () {
alasql.options.dateAsString = false;
let result = alasql(
'SELECT CURDATE AS date1, CURRENT_DATE AS date2, CURDATE(), CURRENT_DATE()'
);

assert.ok(result[0]['date1'] instanceof Date);
assert.ok(result[0]['date1'].getHours() === 0);
assert.ok(result[0]['date1'].getMinutes() === 0);
assert.ok(result[0]['date1'].getSeconds() === 0);

assert.ok(result[0]['date2'] instanceof Date);
assert.ok(result[0]['date2'].getHours() === 0);
assert.ok(result[0]['date2'].getMinutes() === 0);
assert.ok(result[0]['date2'].getSeconds() === 0);

assert.ok(result[0]['CURDATE()'] instanceof Date);
assert.ok(result[0]['CURDATE()'].getHours() === 0);
assert.ok(result[0]['CURDATE()'].getMinutes() === 0);
assert.ok(result[0]['CURDATE()'].getSeconds() === 0);

assert.ok(result[0]['CURRENT_DATE()'] instanceof Date);
assert.ok(result[0]['CURRENT_DATE()'].getHours() === 0);
assert.ok(result[0]['CURRENT_DATE()'].getMinutes() === 0);
assert.ok(result[0]['CURRENT_DATE()'].getSeconds() === 0);
});

it('CURDATE in SELECT - as String', function () {
alasql.options.dateAsString = true;
let result = alasql(
'SELECT CURDATE AS date1, CURRENT_DATE AS date2, CURDATE(), CURRENT_DATE()'
);

assert.ok(typeof result[0]['date1'] === 'string');
assert.ok(!result[0]['date1'].includes('00:00:00'));

assert.ok(typeof result[0]['date2'] === 'string');
assert.ok(!result[0]['date2'].includes('00:00:00'));

assert.ok(typeof result[0]['CURDATE()'] === 'string');
assert.ok(!result[0]['CURDATE()'].includes('00:00:00'));

assert.ok(typeof result[0]['CURRENT_DATE()'] === 'string');
assert.ok(!result[0]['CURRENT_DATE()'].includes('00:00:00'));
});
});
Loading
Loading