1
Fork 0

add support for ? for parameterized queries

This commit is contained in:
Jake Wheat 2013-12-19 10:44:20 +02:00
parent 72d7b9428f
commit b68c116839
5 changed files with 18 additions and 0 deletions

View file

@ -78,6 +78,7 @@ the fixity code.
> -- TODO fix me > -- TODO fix me
> (SpecialOpK {}) -> str ('v':show e) > (SpecialOpK {}) -> str ('v':show e)
> Iden {} -> str ('v':show e) > Iden {} -> str ('v':show e)
> Parameter -> str ('v':show e)
> StringLit {} -> str ('v':show e) > StringLit {} -> str ('v':show e)
> NumLit {} -> str ('v':show e) > NumLit {} -> str ('v':show e)
> App n es -> HSE.App (var ('f':name n)) $ ltoh es > App n es -> HSE.App (var ('f':name n)) $ ltoh es

View file

@ -137,6 +137,13 @@ in any scalar expression context.
> star :: P ScalarExpr > star :: P ScalarExpr
> star = Star <$ symbol "*" > star = Star <$ symbol "*"
== parameter
use in e.g. select * from t where a = ?
> parameter :: P ScalarExpr
> parameter = Parameter <$ symbol "?"
== function application, aggregates and windows == function application, aggregates and windows
this represents anything which syntactically looks like regular C 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 :: P ScalarExpr
> factor = choice [literal > factor = choice [literal
> ,parameter
> ,scase > ,scase
> ,cast > ,cast
> ,try specialOpKs > ,try specialOpKs

View file

@ -40,6 +40,7 @@
> <+> maybe empty (parens . text . show ) p > <+> maybe empty (parens . text . show ) p
> scalarExpr (Iden i) = name i > scalarExpr (Iden i) = name i
> scalarExpr Star = text "*" > scalarExpr Star = text "*"
> scalarExpr Parameter = text "?"
> scalarExpr (App f es) = name f <> parens (commaSep (map scalarExpr es)) > scalarExpr (App f es) = name f <> parens (commaSep (map scalarExpr es))

View file

@ -115,6 +115,7 @@
> -- | in list literal and in subquery, if the bool is false it > -- | in list literal and in subquery, if the bool is false it
> -- means not in was used ('a not in (1,2)') > -- means not in was used ('a not in (1,2)')
> | In Bool ScalarExpr InPredValue > | In Bool ScalarExpr InPredValue
> | Parameter -- ^ Represents a ? in a parameterized query
> deriving (Eq,Show,Read) > deriving (Eq,Show,Read)
> -- | Represents an identifier name, which can be quoted or unquoted. > -- | Represents an identifier name, which can be quoted or unquoted.

View file

@ -12,6 +12,7 @@ Tests for parsing scalar expressions
> [literals > [literals
> ,identifiers > ,identifiers
> ,star > ,star
> ,parameter
> ,dots > ,dots
> ,app > ,app
> ,caseexp > ,caseexp
@ -56,6 +57,12 @@ Tests for parsing scalar expressions
> --,("ROW(t.*,42)", App "ROW" [Star2 "t", NumLit "42"]) > --,("ROW(t.*,42)", App "ROW" [Star2 "t", NumLit "42"])
> ] > ]
> parameter :: TestItem
> parameter = Group "parameter" $ map (uncurry TestScalarExpr)
> [("?", Parameter)
> ]
> dots :: TestItem > dots :: TestItem
> dots = Group "dot" $ map (uncurry TestScalarExpr) > dots = Group "dot" $ map (uncurry TestScalarExpr)
> [("t.a", BinOp (Iden "t") "." (Iden "a")) > [("t.a", BinOp (Iden "t") "." (Iden "a"))