File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -117,11 +117,27 @@ module.exports = {
117117 debug ( 'Bindings: ' + bindings ) ;
118118 debug ( 'Connection Id: ' + inputs . connection . id ) ;
119119
120+ // Process SQL template, escaping bindings.
121+ // This converts `$1`, `$2`, etc. into the escaped binding.
122+ sql = sql . replace ( / \$ [ 1 - 9 ] [ 0 - 9 ] * / g, function ( substr ) {
123+
124+ // e.g. `'$3'` => `'3'` => `3` => `2`
125+ var idx = + ( substr . slice ( 1 ) ) - 1 ;
126+
127+ // If no such binding exists, then just leave the original
128+ // template string (e.g. "$3") alone.
129+ if ( idx >= bindings . length ) {
130+ return substr ;
131+ }
132+
133+ // But otherwise, replace it with the escaped binding.
134+ return inputs . connection . escape ( bindings [ idx ] ) ;
135+ } ) ;
136+
137+ debug ( 'Compiled (final) SQL: ' + sql ) ;
138+
120139 // Send native query to the database using node-mysql.
121- inputs . connection . query ( {
122- sql : sql ,
123- values : bindings
124- } , function query ( ) {
140+ inputs . connection . query ( sql , function query ( ) {
125141 // The exact format of the arguments for this callback are not part of
126142 // the officially documented behavior of node-mysql (at least not as
127143 // of March 2016 when this comment is being written).
You can’t perform that action at this time.
0 commit comments