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

fix: exists in query #1952

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 3 deletions src/alasqlparser.jison
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,8 @@ Select
yy.extend($$,$5); yy.extend($$,$6);yy.extend($$,$7);
yy.extend($$,$8); yy.extend($$,$9); yy.extend($$,$10);
$$ = $1;
/* if(yy.exists) $$.exists = yy.exists;
delete yy.exists;
if(yy.queries) $$.queries = yy.queries;
if(yy.exists) $$.exists = yy.exists.slice();
/* if(yy.queries) $$.queries = yy.queries;
delete yy.queries;
*/ }
| SEARCH SearchSelector* IntoClause SearchFrom?
Expand Down
5 changes: 2 additions & 3 deletions src/alasqlparser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

describe('Test 1937: EXISTS in SQL Queries and SET Statements', function () {
before(function () {
alasql('create database test1937');
alasql('use test1937');
alasql('DROP TABLE IF EXISTS one');
alasql('CREATE TABLE one (a INT)');
alasql('INSERT INTO one VALUES (1),(2),(3),(4),(5)');
});

after(function () {
alasql('drop database test1937');
});

it('Nested EXISTS in subquery', function (done) {
const res = alasql(
'SELECT EXISTS(SELECT a FROM one WHERE 0) AS main_exists, * FROM (SELECT EXISTS(SELECT a FROM one) AS sub_exists, a FROM one)'
);
assert.deepEqual(
[
{main_exists: false, a: 1, sub_exists: true},
{main_exists: false, a: 2, sub_exists: true},
{main_exists: false, a: 3, sub_exists: true},
{main_exists: false, a: 4, sub_exists: true},
{main_exists: false, a: 5, sub_exists: true},
],
res
);
done();
});

it('EXISTS in SET statement', function (done) {
const res = alasql(
`SET @existsLessThan3 = (SELECT EXISTS(SELECT a FROM one WHERE a < 3));
SET @existsGreaterThan10 = (SELECT EXISTS(SELECT a FROM one WHERE a > 10));
SELECT @existsLessThan3, @existsGreaterThan10;`
);
assert.deepEqual([{'@existsLessThan3': true, '@existsGreaterThan10': false}], res[2]);
done();
});
});
Loading