Merge pull request #148 from CartoDB/CDB-2754

Removes ending semicolons from SQL queries. Fixes #147
This commit is contained in:
Raul Ochoa 2014-04-15 16:02:03 +02:00
commit 051269383f
2 changed files with 19 additions and 1 deletions

View File

@ -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: ''

View File

@ -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);
});
}); });