Skip to content

Commit de145f7

Browse files
committed
Always parenthesize dynamic SQL expressions.
This is intended to discourage (not prevent) wacky, unstable uses like adding whole clauses/extra statements.
1 parent f968488 commit de145f7

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/Rezoom.SQL.Compiler/DefaultExprTranslator.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,16 @@ type DefaultExprTranslator(statement : StatementTranslator, indexer : IParameter
244244
yield text ")"
245245
}
246246
override __.NeedsParens(expr) =
247-
match expr with
247+
match expr.Value with
248248
| LiteralExpr _
249-
| BindParameterExpr _
250249
| ColumnNameExpr _
251250
| CastExpr _
252251
| FunctionInvocationExpr _
253252
| ScalarSubqueryExpr _ -> false
253+
| BindParameterExpr _ when expr.Info.Type.Type <> RawSQLType -> false
254254
| _ -> true
255255
override this.Expr(expr, _) =
256-
let needsParens = this.NeedsParens(expr.Value)
256+
let needsParens = this.NeedsParens(expr)
257257
seq {
258258
if needsParens then yield text "("
259259
yield!

src/Rezoom.SQL.Compiler/Translators.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ and [<AbstractClass>] ExprTranslator() =
9696
abstract member Case : case : TCaseExpr -> Fragments
9797
abstract member Exists : subquery : TSelectStmt -> Fragments
9898
abstract member ScalarSubquery : subquery : TSelectStmt -> Fragments
99-
abstract member NeedsParens : TExprType -> bool
99+
abstract member NeedsParens : TExpr -> bool
100100
abstract member Expr : expr : TExpr * context : ExprTranslationContext -> Fragments
101101

102102

0 commit comments

Comments
 (0)