add support for ? for parameterized queries
This commit is contained in:
parent
72d7b9428f
commit
b68c116839
|
@ -78,6 +78,7 @@ the fixity code.
|
|||
> -- TODO fix me
|
||||
> (SpecialOpK {}) -> str ('v':show e)
|
||||
> Iden {} -> str ('v':show e)
|
||||
> Parameter -> str ('v':show e)
|
||||
> StringLit {} -> str ('v':show e)
|
||||
> NumLit {} -> str ('v':show e)
|
||||
> App n es -> HSE.App (var ('f':name n)) $ ltoh es
|
||||
|
|
|
@ -137,6 +137,13 @@ in any scalar expression context.
|
|||
> star :: P ScalarExpr
|
||||
> star = Star <$ symbol "*"
|
||||
|
||||
== parameter
|
||||
|
||||
use in e.g. select * from t where a = ?
|
||||
|
||||
> parameter :: P ScalarExpr
|
||||
> parameter = Parameter <$ symbol "?"
|
||||
|
||||
== function application, aggregates and windows
|
||||
|
||||
this represents anything which syntactically looks like regular C
|
||||
|
@ -591,6 +598,7 @@ could at least do with some heavy explanation.
|
|||
|
||||
> factor :: P ScalarExpr
|
||||
> factor = choice [literal
|
||||
> ,parameter
|
||||
> ,scase
|
||||
> ,cast
|
||||
> ,try specialOpKs
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
> <+> maybe empty (parens . text . show ) p
|
||||
> scalarExpr (Iden i) = name i
|
||||
> scalarExpr Star = text "*"
|
||||
> scalarExpr Parameter = text "?"
|
||||
|
||||
> scalarExpr (App f es) = name f <> parens (commaSep (map scalarExpr es))
|
||||
|
||||
|
|
|
@ -115,6 +115,7 @@
|
|||
> -- | in list literal and in subquery, if the bool is false it
|
||||
> -- means not in was used ('a not in (1,2)')
|
||||
> | In Bool ScalarExpr InPredValue
|
||||
> | Parameter -- ^ Represents a ? in a parameterized query
|
||||
> deriving (Eq,Show,Read)
|
||||
|
||||
> -- | Represents an identifier name, which can be quoted or unquoted.
|
||||
|
|
|
@ -12,6 +12,7 @@ Tests for parsing scalar expressions
|
|||
> [literals
|
||||
> ,identifiers
|
||||
> ,star
|
||||
> ,parameter
|
||||
> ,dots
|
||||
> ,app
|
||||
> ,caseexp
|
||||
|
@ -56,6 +57,12 @@ Tests for parsing scalar expressions
|
|||
> --,("ROW(t.*,42)", App "ROW" [Star2 "t", NumLit "42"])
|
||||
> ]
|
||||
|
||||
> parameter :: TestItem
|
||||
> parameter = Group "parameter" $ map (uncurry TestScalarExpr)
|
||||
> [("?", Parameter)
|
||||
> ]
|
||||
|
||||
|
||||
> dots :: TestItem
|
||||
> dots = Group "dot" $ map (uncurry TestScalarExpr)
|
||||
> [("t.a", BinOp (Iden "t") "." (Iden "a"))
|
||||
|
|
Loading…
Reference in a new issue