Fix quoting identifiers with comma-seperated values

This commit is contained in:
Timothy Warren 2014-10-23 15:49:17 -04:00
parent 1f03c8c0dd
commit 41ef3ebeec
9 changed files with 50 additions and 219 deletions

View File

@ -186,7 +186,11 @@ var d = {
} }
// Handle commas // 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 // Split identifiers by period
hiers = str.split('.').map(d._quote); hiers = str.split('.').map(d._quote);

View File

@ -86,17 +86,6 @@ var h = {
stringTrim: function(str) { stringTrim: function(str) {
return str.trim(); 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 * Get the type of the variable passed
* *

View File

@ -186,7 +186,7 @@ function name, eg isNumber</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="helpers.js.html">helpers.js</a>, <a href="helpers.js.html">helpers.js</a>,
<a href="helpers.js.html#sunlight-1-line-67">line 67</a> <a href="helpers.js.html#sunlight-1-line-56">line 56</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -307,7 +307,7 @@ function name, eg isNumber</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="helpers.js.html">helpers.js</a>, <a href="helpers.js.html">helpers.js</a>,
<a href="helpers.js.html#sunlight-1-line-58">line 58</a> <a href="helpers.js.html#sunlight-1-line-47">line 47</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -351,174 +351,6 @@ function name, eg isNumber</p>
</dd>
<dt>
<h4 class="name" id="splitTrim"><span class="type-signature">&lt;static> </span>splitTrim<span class="signature">(char, string)</span><span class="type-signature"> &rarr; {String}</span></h4>
</dt>
<dd>
<div class="description">
<p>Split a string by a character, trim the string
and rejoin the string</p>
</div>
<h5>Parameters:</h5>
<table class="params table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>char</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>string</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="helpers.js.html">helpers.js</a>,
<a href="helpers.js.html#sunlight-1-line-26">line 26</a>
</li>
</ul>
</dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">String</span>
</dd>
</dl>
</dd> </dd>
@ -769,7 +601,7 @@ and rejoin the string</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="helpers.js.html">helpers.js</a>, <a href="helpers.js.html">helpers.js</a>,
<a href="helpers.js.html#sunlight-1-line-37">line 37</a> <a href="helpers.js.html#sunlight-1-line-26">line 26</a>
</li> </li>
</ul> </ul>
</dd> </dd>

View File

@ -184,7 +184,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-13">line 13</a> <a href="query-builder.js.html#sunlight-1-line-12">line 12</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -305,7 +305,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-388">line 388</a> <a href="query-builder.js.html#sunlight-1-line-387">line 387</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -1427,7 +1427,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-335">line 335</a> <a href="query-builder.js.html#sunlight-1-line-334">line 334</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -1574,7 +1574,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-602">line 602</a> <a href="query-builder.js.html#sunlight-1-line-601">line 601</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -1933,7 +1933,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-461">line 461</a> <a href="query-builder.js.html#sunlight-1-line-460">line 460</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -2408,7 +2408,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-588">line 588</a> <a href="query-builder.js.html#sunlight-1-line-587">line 587</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -2634,7 +2634,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-410">line 410</a> <a href="query-builder.js.html#sunlight-1-line-409">line 409</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -3039,7 +3039,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-423">line 423</a> <a href="query-builder.js.html#sunlight-1-line-422">line 422</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -3154,7 +3154,7 @@
</td> </td>
<td class="description last"><p>The field to order by</p></td> <td class="description last"><p>The field(s) to order by</p></td>
</tr> </tr>
@ -3230,7 +3230,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-625">line 625</a> <a href="query-builder.js.html#sunlight-1-line-624">line 624</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -3503,7 +3503,7 @@ prefixed with 'OR'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-475">line 475</a> <a href="query-builder.js.html#sunlight-1-line-474">line 474</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -3729,7 +3729,7 @@ prefixed with 'OR'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-436">line 436</a> <a href="query-builder.js.html#sunlight-1-line-435">line 435</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -4043,7 +4043,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-449">line 449</a> <a href="query-builder.js.html#sunlight-1-line-448">line 448</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -4228,7 +4228,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-501">line 501</a> <a href="query-builder.js.html#sunlight-1-line-500">line 500</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -4387,7 +4387,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-525">line 525</a> <a href="query-builder.js.html#sunlight-1-line-524">line 524</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -4546,7 +4546,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-549">line 549</a> <a href="query-builder.js.html#sunlight-1-line-548">line 548</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -4685,7 +4685,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-354">line 354</a> <a href="query-builder.js.html#sunlight-1-line-353">line 353</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -4867,7 +4867,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-561">line 561</a> <a href="query-builder.js.html#sunlight-1-line-560">line 560</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -5262,7 +5262,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-489">line 489</a> <a href="query-builder.js.html#sunlight-1-line-488">line 488</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -5421,7 +5421,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-513">line 513</a> <a href="query-builder.js.html#sunlight-1-line-512">line 512</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -5580,7 +5580,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-537">line 537</a> <a href="query-builder.js.html#sunlight-1-line-536">line 536</a>
</li> </li>
</ul> </ul>
</dd> </dd>

View File

@ -72,7 +72,6 @@
class="sunlight-highlight-javascript linenums">'use strict'; class="sunlight-highlight-javascript linenums">'use strict';
/** @module query-builder */ /** @module query-builder */
require('./es6-polyfill');
var getArgs = require('getargs'), var getArgs = require('getargs'),
helpers = require('./helpers'); helpers = require('./helpers');
@ -689,7 +688,7 @@ var QueryBuilder = function(driver, adapter) {
/** /**
* Order the results by the selected field(s) * 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 * @param {String} [type='ASC'] - The order direction, ASC or DESC
* @return this * @return this
*/ */
@ -698,6 +697,7 @@ var QueryBuilder = function(driver, adapter) {
// Set the fields for later manipulation // Set the fields for later manipulation
field = driver.quoteIdentifiers(field); field = driver.quoteIdentifiers(field);
state.orderArray[field] = type; state.orderArray[field] = type;
var orderClauses = []; var orderClauses = [];

View File

@ -115,7 +115,11 @@ var d = {
} }
// Handle commas // 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 // Split identifiers by period
hiers = str.split('.').map(d._quote); hiers = str.split('.').map(d._quote);

View File

@ -15,17 +15,6 @@ var h = {
stringTrim: function(str) { stringTrim: function(str) {
return str.trim(); 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 * Get the type of the variable passed
* *

View File

@ -617,7 +617,7 @@ var QueryBuilder = function(driver, adapter) {
/** /**
* Order the results by the selected field(s) * 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 * @param {String} [type='ASC'] - The order direction, ASC or DESC
* @return this * @return this
*/ */
@ -626,6 +626,7 @@ var QueryBuilder = function(driver, adapter) {
// Set the fields for later manipulation // Set the fields for later manipulation
field = driver.quoteIdentifiers(field); field = driver.quoteIdentifiers(field);
state.orderArray[field] = type; state.orderArray[field] = type;
var orderClauses = []; var orderClauses = [];

View File

@ -68,10 +68,22 @@ module.exports = (function() {
}, },
'Select tests' : { 'Select tests' : {
'Select where get': function(test) { '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') base.qb.select('id, key as k, val')
.where('id !=', 1) .where('id !=', 1)
.get('create_test', 2, 1, base.testCallback.bind(test, test)); .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(); test.done();
} }
}, },