From 002b4d34038e1b585c30f84e200f71a91a90e078 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Tue, 10 Oct 2017 11:59:44 +0200 Subject: [PATCH] mysql: fix interpolation for numbers in temp vars --- .../plugins/datasource/mysql/datasource.ts | 8 ++++++++ .../mysql/specs/datasource_specs.ts | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/public/app/plugins/datasource/mysql/datasource.ts b/public/app/plugins/datasource/mysql/datasource.ts index 652c21c1013..6a255d63d52 100644 --- a/public/app/plugins/datasource/mysql/datasource.ts +++ b/public/app/plugins/datasource/mysql/datasource.ts @@ -20,7 +20,15 @@ export class MysqlDatasource { return '\'' + value + '\''; } + if (typeof value === 'number') { + return value; + } + var quotedValues = _.map(value, function(val) { + if (typeof value === 'number') { + return value; + } + return '\'' + val + '\''; }); return quotedValues.join(','); diff --git a/public/app/plugins/datasource/mysql/specs/datasource_specs.ts b/public/app/plugins/datasource/mysql/specs/datasource_specs.ts index 989d3d59395..6ff1f9d47ac 100644 --- a/public/app/plugins/datasource/mysql/specs/datasource_specs.ts +++ b/public/app/plugins/datasource/mysql/specs/datasource_specs.ts @@ -193,4 +193,24 @@ describe('MySQLDatasource', function() { expect(results[0].value).to.be('same'); }); }); + + describe('When interpolating variables', () => { + describe('and value is a string', () => { + it('should return a quoted value', () => { + expect(ctx.ds.interpolateVariable('abc')).to.eql('\'abc\''); + }); + }); + + describe('and value is a number', () => { + it('should return an unquoted value', () => { + expect(ctx.ds.interpolateVariable(1000)).to.eql(1000); + }); + }); + + describe('and value is an array of strings', () => { + it('should return comma separated quoted values', () => { + expect(ctx.ds.interpolateVariable(['a', 'b', 'c'])).to.eql('\'a\',\'b\',\'c\''); + }); + }); + }); });