From 56e53b83431a008b0d6f63935c5066b6b9606de3 Mon Sep 17 00:00:00 2001 From: Sven Klemm <31455525+svenklemm@users.noreply.github.com> Date: Tue, 24 Oct 2017 14:05:41 +0200 Subject: [PATCH] dont quote variables for mysql and postgres datasource (#9611) --- .../plugins/datasource/mysql/datasource.ts | 2 +- .../mysql/specs/datasource_specs.ts | 4 ++-- .../plugins/datasource/postgres/datasource.ts | 4 ++-- .../postgres/specs/datasource_specs.ts | 20 +++++++++++++++++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/public/app/plugins/datasource/mysql/datasource.ts b/public/app/plugins/datasource/mysql/datasource.ts index 6a255d63d52..e35896c0d04 100644 --- a/public/app/plugins/datasource/mysql/datasource.ts +++ b/public/app/plugins/datasource/mysql/datasource.ts @@ -17,7 +17,7 @@ export class MysqlDatasource { interpolateVariable(value) { if (typeof value === 'string') { - return '\'' + value + '\''; + return value; } if (typeof value === 'number') { diff --git a/public/app/plugins/datasource/mysql/specs/datasource_specs.ts b/public/app/plugins/datasource/mysql/specs/datasource_specs.ts index 6ff1f9d47ac..f579ad15410 100644 --- a/public/app/plugins/datasource/mysql/specs/datasource_specs.ts +++ b/public/app/plugins/datasource/mysql/specs/datasource_specs.ts @@ -196,8 +196,8 @@ describe('MySQLDatasource', function() { describe('When interpolating variables', () => { describe('and value is a string', () => { - it('should return a quoted value', () => { - expect(ctx.ds.interpolateVariable('abc')).to.eql('\'abc\''); + it('should return an unquoted value', () => { + expect(ctx.ds.interpolateVariable('abc')).to.eql('abc'); }); }); diff --git a/public/app/plugins/datasource/postgres/datasource.ts b/public/app/plugins/datasource/postgres/datasource.ts index d75aecbc281..68471f035ff 100644 --- a/public/app/plugins/datasource/postgres/datasource.ts +++ b/public/app/plugins/datasource/postgres/datasource.ts @@ -17,11 +17,11 @@ export class PostgresDatasource { interpolateVariable(value) { if (typeof value === 'string') { - return '\'' + value + '\''; + return value; } if (typeof value === 'number') { - return value.toString(); + return value; } var quotedValues = _.map(value, function(val) { diff --git a/public/app/plugins/datasource/postgres/specs/datasource_specs.ts b/public/app/plugins/datasource/postgres/specs/datasource_specs.ts index 5510e138f63..3f83bb76e7b 100644 --- a/public/app/plugins/datasource/postgres/specs/datasource_specs.ts +++ b/public/app/plugins/datasource/postgres/specs/datasource_specs.ts @@ -193,4 +193,24 @@ describe('PostgreSQLDatasource', function() { expect(results[0].value).to.be('same'); }); }); + + describe('When interpolating variables', () => { + describe('and value is a string', () => { + it('should return an unquoted 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\''); + }); + }); + }); });