Skip to content
Open
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
7 changes: 5 additions & 2 deletions src/50expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,15 +523,18 @@
}

toString() {
return '@' + this.variable;
return (this.system ? '@@' : '@') + this.variable;
}

toType() {
return 'unknown';
}

toJS() {
return "alasql.vars['" + escapeq(this.variable) + "']";
// @@name reads a system variable (#2862)
return (
(this.system ? 'alasql.sysvars' : 'alasql.vars') + "['" + escapeq(this.variable) + "']"
);
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/79set.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
//
*/

// System variables, read as @@name and set with SET name = ..., SET @@name = ... or SET GLOBAL name = ...
alasql.sysvars = {};

yy.SetVariable = function (params) {
return Object.assign(this, params);
};
Expand Down Expand Up @@ -70,8 +73,12 @@ yy.SetVariable.prototype.execute = function (databaseid, params, cb) {
} else {
if (this.method === '@') {
alasql.vars[this.variable] = res;
} else if (this.method === '@@') {
alasql.sysvars[this.variable] = res;
} else {
params[this.variable] = res;
// MySQL reads SET name = value back as @@name (#2862)
if (!this.method) alasql.sysvars[this.variable.toLowerCase()] = res;
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/alasqlparser.jison
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ SCHEMA(S)? return 'DATABASE'

'SEMI' return 'SEMI'
'SEPARATOR' return 'SEPARATOR'
/* MySQL system variables (#2862): SET GLOBAL x = 1, SET SESSION x = 1, SET NAMES utf8 */
SET\s+(GLOBAL|SESSION|LOCAL|PERSIST)\s+(?=[a-zA-Z_]\w*\s*\=) return 'SET_SYSVAR'
SET\s+NAMES\b return 'SET_NAMES'
SET return 'SET'
SETS return 'SET'
'SHOW' return 'SHOW'
Expand Down Expand Up @@ -325,6 +328,7 @@ SETS return 'SET'

'~' return 'TILDA'

'@@'((GLOBAL|SESSION|LOCAL)'.')?[a-zA-Z_]\w* { yytext = yytext.replace(/^@@((GLOBAL|SESSION|LOCAL)\.)?/i, ''); return 'SYSVAR'; }
'@' return 'AT'
<<EOF>> return 'EOF'
. return 'INVALID'
Expand Down Expand Up @@ -1637,6 +1641,8 @@ NullValue
VarValue
: AT Literal
{ $$ = new yy.VarValue({variable:$2}); }
| SYSVAR
{ $$ = new yy.VarValue({variable:$1.toLowerCase(), system:true}); }
;

ExistsValue
Expand Down Expand Up @@ -2818,6 +2824,14 @@ SetVariable
{ $$ = new yy.SetVariable({variable:$3, expression:$5, method:$2});}
| SET AtDollar Literal SetPropsList EQ Expression
{ $$ = new yy.SetVariable({variable:$3, props: $4, expression:$6, method:$2});}
| SET SYSVAR EQ Expression
{ $$ = new yy.SetVariable({variable:$2.toLowerCase(), expression:$4, method:'@@'});}
| SET_SYSVAR Literal EQ Expression
{ $$ = new yy.SetVariable({variable:$2.toLowerCase(), expression:$4, method:'@@'});}
| SET_NAMES Literal
{ $$ = new yy.SetVariable({variable:'names', expression:new yy.StringValue({value:$2}), method:'@@'});}
| SET_NAMES StringValue
{ $$ = new yy.SetVariable({variable:'names', expression:$2, method:'@@'});}
;

AtDollar
Expand Down
Loading
Loading