From 41ef3ebeec4f0f94c65ee9b7dc7c8cd2b6cdfe50 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Thu, 23 Oct 2014 15:49:17 -0400 Subject: [PATCH] Fix quoting identifiers with comma-seperated values --- docs/driver.js.html | 6 +- docs/helpers.js.html | 11 --- docs/module-helpers.html | 174 +-------------------------------- docs/module-query-builder.html | 42 ++++---- docs/query-builder.js.html | 4 +- lib/driver.js | 6 +- lib/helpers.js | 11 --- lib/query-builder.js | 3 +- tests/query-builder-base.js | 12 +++ 9 files changed, 50 insertions(+), 219 deletions(-) diff --git a/docs/driver.js.html b/docs/driver.js.html index 84d2262..fdc9890 100644 --- a/docs/driver.js.html +++ b/docs/driver.js.html @@ -186,7 +186,11 @@ var d = { } // Handle commas - str = helpers.splitTrim(',', str); + if (str.contains(',')) + { + var parts = str.split(',').map(helpers.stringTrim); + str = parts.map(d.quoteIdentifiers).join(','); + } // Split identifiers by period hiers = str.split('.').map(d._quote); diff --git a/docs/helpers.js.html b/docs/helpers.js.html index 47ada29..e47c2bb 100644 --- a/docs/helpers.js.html +++ b/docs/helpers.js.html @@ -86,17 +86,6 @@ var h = { stringTrim: function(str) { return str.trim(); }, - /** - * Split a string by a character, trim the string - * and rejoin the string - * - * @param {String} char - * @param {String} string - * @return {String} - */ - splitTrim: function(char, string) { - return string.split(char).map(h.stringTrim).join(char); - }, /** * Get the type of the variable passed * diff --git a/docs/module-helpers.html b/docs/module-helpers.html index 6649f65..cae136c 100644 --- a/docs/module-helpers.html +++ b/docs/module-helpers.html @@ -186,7 +186,7 @@ function name, eg isNumber

@@ -307,7 +307,7 @@ function name, eg isNumber

@@ -351,174 +351,6 @@ function name, eg isNumber

- - - - -
-

<static> splitTrim(char, string) → {String}

- - -
-
- - -
-

Split a string by a character, trim the string -and rejoin the string

-
- - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
char - - -String - - - -
string - - -String - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - -
Source:
-
- -
- - - - - - - -
- - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -String - - -
-
- - - - -
@@ -769,7 +601,7 @@ and rejoin the string

diff --git a/docs/module-query-builder.html b/docs/module-query-builder.html index 3be2283..42d4134 100644 --- a/docs/module-query-builder.html +++ b/docs/module-query-builder.html @@ -184,7 +184,7 @@ @@ -305,7 +305,7 @@ @@ -1427,7 +1427,7 @@ @@ -1574,7 +1574,7 @@ @@ -1933,7 +1933,7 @@ @@ -2408,7 +2408,7 @@ @@ -2634,7 +2634,7 @@ @@ -3039,7 +3039,7 @@ @@ -3154,7 +3154,7 @@ -

The field to order by

+

The field(s) to order by

@@ -3230,7 +3230,7 @@ @@ -3503,7 +3503,7 @@ prefixed with 'OR'

@@ -3729,7 +3729,7 @@ prefixed with 'OR'

@@ -4043,7 +4043,7 @@ prefixed with 'OR NOT'

@@ -4228,7 +4228,7 @@ prefixed with 'OR NOT'

@@ -4387,7 +4387,7 @@ prefixed with 'OR NOT'

@@ -4546,7 +4546,7 @@ prefixed with 'OR NOT'

@@ -4685,7 +4685,7 @@ prefixed with 'OR NOT'

@@ -4867,7 +4867,7 @@ prefixed with 'OR NOT'

@@ -5262,7 +5262,7 @@ prefixed with 'OR NOT'

@@ -5421,7 +5421,7 @@ prefixed with 'OR NOT'

@@ -5580,7 +5580,7 @@ prefixed with 'OR NOT'

diff --git a/docs/query-builder.js.html b/docs/query-builder.js.html index 6eb3da5..26b483b 100644 --- a/docs/query-builder.js.html +++ b/docs/query-builder.js.html @@ -72,7 +72,6 @@ class="sunlight-highlight-javascript linenums">'use strict'; /** @module query-builder */ -require('./es6-polyfill'); var getArgs = require('getargs'), helpers = require('./helpers'); @@ -689,7 +688,7 @@ var QueryBuilder = function(driver, adapter) { /** * Order the results by the selected field(s) * - * @param {String} field - The field to order by + * @param {String} field - The field(s) to order by * @param {String} [type='ASC'] - The order direction, ASC or DESC * @return this */ @@ -698,6 +697,7 @@ var QueryBuilder = function(driver, adapter) { // Set the fields for later manipulation field = driver.quoteIdentifiers(field); + state.orderArray[field] = type; var orderClauses = []; diff --git a/lib/driver.js b/lib/driver.js index 26c3a3c..b06abec 100755 --- a/lib/driver.js +++ b/lib/driver.js @@ -115,7 +115,11 @@ var d = { } // Handle commas - str = helpers.splitTrim(',', str); + if (str.contains(',')) + { + var parts = str.split(',').map(helpers.stringTrim); + str = parts.map(d.quoteIdentifiers).join(','); + } // Split identifiers by period hiers = str.split('.').map(d._quote); diff --git a/lib/helpers.js b/lib/helpers.js index f69185d..7ad124a 100755 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -15,17 +15,6 @@ var h = { stringTrim: function(str) { return str.trim(); }, - /** - * Split a string by a character, trim the string - * and rejoin the string - * - * @param {String} char - * @param {String} string - * @return {String} - */ - splitTrim: function(char, string) { - return string.split(char).map(h.stringTrim).join(char); - }, /** * Get the type of the variable passed * diff --git a/lib/query-builder.js b/lib/query-builder.js index 5ebb02f..56c3bb7 100755 --- a/lib/query-builder.js +++ b/lib/query-builder.js @@ -617,7 +617,7 @@ var QueryBuilder = function(driver, adapter) { /** * Order the results by the selected field(s) * - * @param {String} field - The field to order by + * @param {String} field - The field(s) to order by * @param {String} [type='ASC'] - The order direction, ASC or DESC * @return this */ @@ -626,6 +626,7 @@ var QueryBuilder = function(driver, adapter) { // Set the fields for later manipulation field = driver.quoteIdentifiers(field); + state.orderArray[field] = type; var orderClauses = []; diff --git a/tests/query-builder-base.js b/tests/query-builder-base.js index 6667d16..d75dd9c 100644 --- a/tests/query-builder-base.js +++ b/tests/query-builder-base.js @@ -68,10 +68,22 @@ module.exports = (function() { }, 'Select tests' : { 'Select where get': function(test) { + base.qb.select(['id', 'key as k', 'val']) + .where('id >', 1) + .where('id <', 900) + .get('create_test', 2, 1, base.testCallback.bind(test, test)); + base.qb.select('id, key as k, val') .where('id !=', 1) .get('create_test', 2, 1, base.testCallback.bind(test, test)); + test.done(); + }, + 'Multi Order By': function(test) { + base.qb.from('create_test') + .orderBy('id, key') + .get(base.testCallback.bind(test, test)); + test.done(); } },