@@ -9,7 +9,7 @@ public partial class Compiler
99 {
1010 private readonly ConditionsCompilerProvider _compileConditionMethodsProvider ;
1111 protected virtual string parameterPlaceholder { get ; set ; } = "?" ;
12- protected virtual string parameterPlaceholderPrefix { get ; set ; } = "@p" ;
12+ protected virtual string parameterPrefix { get ; set ; } = "@p" ;
1313 protected virtual string OpeningIdentifier { get ; set ; } = "\" " ;
1414 protected virtual string ClosingIdentifier { get ; set ; } = "\" " ;
1515 protected virtual string ColumnAsKeyword { get ; set ; } = "AS " ;
@@ -48,13 +48,13 @@ protected Compiler()
4848 protected Dictionary < string , object > generateNamedBindings ( object [ ] bindings )
4949 {
5050 return Helper . Flatten ( bindings ) . Select ( ( v , i ) => new { i , v } )
51- . ToDictionary ( x => parameterPlaceholderPrefix + x . i , x => x . v ) ;
51+ . ToDictionary ( x => parameterPrefix + x . i , x => x . v ) ;
5252 }
5353
5454 protected SqlResult PrepareResult ( SqlResult ctx )
5555 {
5656 ctx . NamedBindings = generateNamedBindings ( ctx . Bindings . ToArray ( ) ) ;
57- ctx . Sql = Helper . ReplaceAll ( ctx . RawSql , parameterPlaceholder , i => parameterPlaceholderPrefix + i ) ;
57+ ctx . Sql = Helper . ReplaceAll ( ctx . RawSql , parameterPlaceholder , i => parameterPrefix + i ) ;
5858 return ctx ;
5959 }
6060
@@ -79,7 +79,7 @@ private Query TransformAggregateQuery(Query query)
7979
8080 var outerClause = new AggregateClause ( )
8181 {
82- Columns = new List < string > { "*" } ,
82+ Columns = new List < string > { "*" } ,
8383 Type = clause . Type
8484 } ;
8585
@@ -129,6 +129,13 @@ protected virtual SqlResult CompileRaw(Query query)
129129 return ctx ;
130130 }
131131
132+ /// <summary>
133+ /// Add the passed operator(s) to the white list so they can be used with
134+ /// the Where/Having methods, this prevent passing arbitrary operators
135+ /// that opens the door for SQL injections.
136+ /// </summary>
137+ /// <param name="operators"></param>
138+ /// <returns></returns>
132139 public Compiler Whitelist ( params string [ ] operators )
133140 {
134141 foreach ( var op in operators )
@@ -300,9 +307,10 @@ protected virtual SqlResult CompileInsertQuery(Query query)
300307
301308 if ( inserts [ 0 ] is InsertClause insertClause )
302309 {
303- ctx . RawSql = $ "INSERT INTO { table } "
304- + " (" + string . Join ( ", " , WrapArray ( insertClause . Columns ) ) + ") "
305- + "VALUES (" + string . Join ( ", " , Parameterize ( ctx , insertClause . Values ) ) + ")" ;
310+ var columns = string . Join ( ", " , WrapArray ( insertClause . Columns ) ) ;
311+ var values = string . Join ( ", " , Parameterize ( ctx , insertClause . Values ) ) ;
312+
313+ ctx . RawSql = $ "INSERT INTO { table } ({ columns } ) VALUES ({ values } )";
306314
307315 if ( insertClause . ReturnId && ! string . IsNullOrEmpty ( LastId ) )
308316 {
@@ -817,11 +825,11 @@ public virtual string WrapIdentifiers(string input)
817825 return input
818826
819827 // deprecated
820- . ReplaceIdentifierUnlessEscaped ( this . EscapeCharacter , "{" , this . OpeningIdentifier )
821- . ReplaceIdentifierUnlessEscaped ( this . EscapeCharacter , "}" , this . ClosingIdentifier )
828+ . ReplaceIdentifierUnlessEscaped ( this . EscapeCharacter , "{" , this . OpeningIdentifier )
829+ . ReplaceIdentifierUnlessEscaped ( this . EscapeCharacter , "}" , this . ClosingIdentifier )
822830
823- . ReplaceIdentifierUnlessEscaped ( this . EscapeCharacter , "[" , this . OpeningIdentifier )
824- . ReplaceIdentifierUnlessEscaped ( this . EscapeCharacter , "]" , this . ClosingIdentifier ) ;
831+ . ReplaceIdentifierUnlessEscaped ( this . EscapeCharacter , "[" , this . OpeningIdentifier )
832+ . ReplaceIdentifierUnlessEscaped ( this . EscapeCharacter , "]" , this . ClosingIdentifier ) ;
825833 }
826834 }
827835}
0 commit comments