Merge pull request #148 from CartoDB/CDB-2754
Removes ending semicolons from SQL queries. Fixes #147
This commit is contained in:
commit
051269383f
@ -7,7 +7,7 @@ var _ = require('underscore'),
|
|||||||
REGEX_INTO = /\sINTO\s+([^\s]+|"([^"]|"")*")\s*$/i;
|
REGEX_INTO = /\sINTO\s+([^\s]+|"([^"]|"")*")\s*$/i;
|
||||||
|
|
||||||
function PSQLWrapper(sql) {
|
function PSQLWrapper(sql) {
|
||||||
this.sqlQuery = sql;
|
this.sqlQuery = sql.replace(/;\s*$/, '');
|
||||||
this.sqlClauses = {
|
this.sqlClauses = {
|
||||||
orderBy: '',
|
orderBy: '',
|
||||||
limit: ''
|
limit: ''
|
||||||
|
@ -94,4 +94,22 @@ suite('psql_wrapper', function() {
|
|||||||
|
|
||||||
assert.equal(outputSql, expectedSql);
|
assert.equal(outputSql, expectedSql);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Query with ending semicolon returns without it', function() {
|
||||||
|
var expectedSql = 'select a, ( a - min(a) over() ) / ( ( max(a) over () - min(a) over () ) / 4 ) as interval from ( select test as a from quantile_test ) as f',
|
||||||
|
query = expectedSql + ';';
|
||||||
|
|
||||||
|
var outputSql = new PSQLWrapper(query).query();
|
||||||
|
|
||||||
|
assert.equal(outputSql, expectedSql);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Several queries with semicolon get only last semicolon removed', function() {
|
||||||
|
var expectedSql = 'SELECT 1; SELECT 2; SELECT 3',
|
||||||
|
query = expectedSql + ';';
|
||||||
|
|
||||||
|
var outputSql = new PSQLWrapper(query).query();
|
||||||
|
|
||||||
|
assert.equal(outputSql, expectedSql);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user