Skip to content

Commit

Permalink
Correct OFFSET (fix AlaSQL#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasrw committed Apr 6, 2017
1 parent 7b6a47c commit c15912d
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 23 deletions.
4 changes: 2 additions & 2 deletions dist/alasql-worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! AlaSQL v0.3.9-develop-1512 | © 2014-2016 Andrey Gershun & Mathias Rangel Wulff | License: MIT
//! AlaSQL v0.3.9-develop-1513 | © 2014-2016 Andrey Gershun & Mathias Rangel Wulff | License: MIT
/*
@module alasql
@version 0.3.9-develop-1512
@version 0.3.9-develop-1513
AlaSQL - JavaScript SQL database
© 2014-2016 Andrey Gershun & Mathias Rangel Wulff
Expand Down
2 changes: 1 addition & 1 deletion dist/alasql-worker.min.js

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

1 change: 1 addition & 0 deletions dist/alasql.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ declare namespace alaSQLSpace {
fn: userDefinedFunctionLookUp;
aggr: userAggregatorLookUp;
autoval(tablename: string, colname: string, getNext?:boolean): number;
yy:{};
}
}

Expand Down
13 changes: 8 additions & 5 deletions dist/alasql.fs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! AlaSQL v0.3.9-develop-1512 | © 2014-2016 Andrey Gershun & Mathias Rangel Wulff | License: MIT
//! AlaSQL v0.3.9-develop-1513 | © 2014-2016 Andrey Gershun & Mathias Rangel Wulff | License: MIT
/*
@module alasql
@version 0.3.9-develop-1512
@version 0.3.9-develop-1513

AlaSQL - JavaScript SQL database
© 2014-2016 Andrey Gershun & Mathias Rangel Wulff
Expand Down Expand Up @@ -137,7 +137,7 @@ var alasql = function(sql, params, cb, scope) {
Current version of alasql
@constant {string}
*/
alasql.version = '0.3.9-develop-1512';
alasql.version = '0.3.9-develop-1513';

/**
Debug flag
Expand Down Expand Up @@ -6646,10 +6646,13 @@ function doLimit (query) {

if(query.limit) {
var offset = 0;
if(query.offset) offset = ((query.offset|0)-1)||0;
if(query.offset){
offset = (query.offset|0)||0;
offset = offset<0 ? 0 : offset;
}
var limit;
if(query.percent) {
limit = ((query.data.length*query.limit/100)| 0)+offset;
limit = ((query.data.length*query.limit/100)|0)+offset;
} else {
limit = (query.limit|0) + offset;
}
Expand Down
13 changes: 8 additions & 5 deletions dist/alasql.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! AlaSQL v0.3.9-develop-1512 | © 2014-2016 Andrey Gershun & Mathias Rangel Wulff | License: MIT
//! AlaSQL v0.3.9-develop-1513 | © 2014-2016 Andrey Gershun & Mathias Rangel Wulff | License: MIT
/*
@module alasql
@version 0.3.9-develop-1512
@version 0.3.9-develop-1513

AlaSQL - JavaScript SQL database
© 2014-2016 Andrey Gershun & Mathias Rangel Wulff
Expand Down Expand Up @@ -137,7 +137,7 @@ var alasql = function(sql, params, cb, scope) {
Current version of alasql
@constant {string}
*/
alasql.version = '0.3.9-develop-1512';
alasql.version = '0.3.9-develop-1513';

/**
Debug flag
Expand Down Expand Up @@ -6646,10 +6646,13 @@ function doLimit (query) {

if(query.limit) {
var offset = 0;
if(query.offset) offset = ((query.offset|0)-1)||0;
if(query.offset){
offset = (query.offset|0)||0;
offset = offset<0 ? 0 : offset;
}
var limit;
if(query.percent) {
limit = ((query.data.length*query.limit/100)| 0)+offset;
limit = ((query.data.length*query.limit/100)|0)+offset;
} else {
limit = (query.limit|0) + offset;
}
Expand Down
4 changes: 2 additions & 2 deletions dist/alasql.min.js

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/38query.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,13 @@ function doLimit (query) {
// console.log(query.limit, query.offset)
if(query.limit) {
var offset = 0;
if(query.offset) offset = ((query.offset|0)-1)||0;
if(query.offset){
offset = (query.offset|0)||0;
offset = offset<0 ? 0 : offset;
}
var limit;
if(query.percent) {
limit = ((query.data.length*query.limit/100)| 0)+offset;
limit = ((query.data.length*query.limit/100)|0)+offset;
} else {
limit = (query.limit|0) + offset;
}
Expand Down
2 changes: 1 addition & 1 deletion test/test030.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Test 30', function() {

var sql = 'SELECT COLUMN a FROM test1 LIMIT 3 OFFSET 2';
var res = db.exec(sql);
assert.deepEqual([ 2,3,4 ], res);
assert.deepEqual([ 3,4,5 ], res);

done();
});
Expand Down
4 changes: 2 additions & 2 deletions test/test035.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Test 35 - LIMIT OFFSET', function() {

var sql = 'SELECT COLUMN a FROM test1 LIMIT 3 OFFSET 2';
var res = db.exec(sql);
assert.deepEqual([ 2,3,4 ], res);
assert.deepEqual([ 3,4,5 ], res);

done();
});
Expand All @@ -49,7 +49,7 @@ describe('Test 35 - LIMIT OFFSET', function() {

var sql = 'SELECT COLUMN a FROM test1 LIMIT 5 OFFSET 2';
var res = alasql(sql);
assert.deepEqual([ 2,3,4,5,6 ], res);
assert.deepEqual([ 3,4,5,6,7 ], res);

alasql('drop database test35');
done();
Expand Down
6 changes: 3 additions & 3 deletions test/test368.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ describe('Test 368 OFFSET ... LIMIT', function() {

it('OFFSET LIMIT',function(done){
var res = alasql('SELECT * FROM ? LIMIT 2 OFFSET 3',[data]);
assert.deepEqual(res,[ { a: 3 }, { a: 4 } ]);
assert.deepEqual(res,[ { a: 4 }, { a: 5 } ]);
done();
});

it('OFFSET FETCH',function(done){
var res = alasql('SELECT * FROM ? OFFSET 3 FETCH 2',[data]);
assert.deepEqual(res,[ { a: 3 }, { a: 4 } ]);
assert.deepEqual(res,[ { a: 4 }, { a: 5 } ]);

var res = alasql('SELECT * FROM ? OFFSET 3 ROWS FETCH NEXT 2 ROWS ONLY',[data]);
assert.deepEqual(res,[ { a: 3 }, { a: 4 } ]);
assert.deepEqual(res,[ { a: 4 }, { a: 5 } ]);
done();
});

Expand Down

0 comments on commit c15912d

Please sign in to comment.