Removes ending semicolons from SQL queries. Fixes #147
This commit is contained in:
parent
ff70d8bcf9
commit
8dbf1d9c45
@ -7,7 +7,7 @@ var _ = require('underscore'),
|
||||
REGEX_INTO = /\sINTO\s+([^\s]+|"([^"]|"")*")\s*$/i;
|
||||
|
||||
function PSQLWrapper(sql) {
|
||||
this.sqlQuery = sql;
|
||||
this.sqlQuery = sql.replace(/;\s*$/, '');
|
||||
this.sqlClauses = {
|
||||
orderBy: '',
|
||||
limit: ''
|
||||
|
@ -94,4 +94,22 @@ suite('psql_wrapper', function() {
|
||||
|
||||
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