Skip to content

Commit

Permalink
Improve error handling for "order by" (#1588) (#1591)
Browse files Browse the repository at this point in the history
  • Loading branch information
ambujsahu81 authored Dec 24, 2022
1 parent 0448cf5 commit d97ae85
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/10start.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/**
AlaSQL - Main Alasql class
@function
@param {string|function|object} sql - SQL-statement or data object for fuent interface
@param {string|function|object} sql - SQL-statement or data object for fluent interface
@param {object} params - SQL parameters
@param {function} cb - callback function
@param {object} scope - Scope for nested queries
Expand Down Expand Up @@ -120,6 +120,6 @@ alasql.debug = undefined; // Initial debug variable


/*only-for-browser/*
var require = function(){return null}; // as alasqlparser.js is generated, we can not "remove" referenses to
var require = function(){return null}; // as alasqlparser.js is generated, we can not "remove" references to
var __dirname = '';
//*/
2 changes: 1 addition & 1 deletion src/38query.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function queryfn3(query) {

//console.log(85,query.data[0]);

// If groupping, then filter groups with HAVING function
// If grouping, then filter groups with HAVING function
// console.log(query.havingfns);
if (query.groupfn) {
query.data = [];
Expand Down
2 changes: 1 addition & 1 deletion src/39dojoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function doJoin(query, scope, h) {

// var res = query.selectfn(scope, query.params, alasql);
// console.log("last",res);
// If there is a GROUP BY then pipe to groupping function
// If there is a GROUP BY then pipe to grouping function
if (query.groupfn) {
query.groupfn(scope, query.params, alasql);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/423groupby.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ if(false) {
var coljs = col2.split('\t')[1];
// Check, if aggregator exists but GROUP BY is not exists
if (columnid === '') {
return '1'; // Create fictive groupping column for fictive GROUP BY
return '1'; // Create fictive grouping column for fictive GROUP BY
}
// else return "r['"+columnid+"']";
query.ingroup.push(columnid);
Expand Down
5 changes: 5 additions & 0 deletions src/426orderby.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ yy.Select.prototype.compileOrder = function (query, params) {
// console.log(ord.expression instanceof yy.Column);

if (ord.expression instanceof yy.NumValue) {
if (ord.expression.value > self.columns.length) {
throw new Error(
`You are trying to order by column number ${ord.expression.value} but you have only selected ${self.columns.length} columns.`
);
}
var v = self.columns[ord.expression.value - 1];
} else {
var v = ord.expression;
Expand Down
2 changes: 1 addition & 1 deletion test/test238.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"100": 100}]
[{"100":100}]

0 comments on commit d97ae85

Please sign in to comment.