1
Fork 0

add support for named host parameters

This commit is contained in:
Jake Wheat 2014-04-17 19:27:18 +03:00
parent 19df6f18aa
commit 6720d3e3a3
4 changed files with 33 additions and 5 deletions
Language/SQL/SimpleSQL

View file

@ -152,6 +152,16 @@ use in e.g. select * from t where a = ?
> parameter :: Parser ValueExpr
> parameter = Parameter <$ questionMark
named parameter:
select x from t where x > :param
> hostParameter :: Parser ValueExpr
> hostParameter =
> HostParameter
> <$> hostParameterToken
> <*> optionMaybe (keyword "indicator" *> hostParameterToken)
== function application, aggregates and windows
this represents anything which syntactically looks like regular C
@ -572,6 +582,7 @@ fragile and could at least do with some heavy explanation.
> term :: Parser ValueExpr
> term = choice [literal
> ,parameter
> ,hostParameter
> ,caseValue
> ,cast
> ,try specialOpKs
@ -887,6 +898,12 @@ make this choice.
TODO: add "" inside quoted identifiers
parses an identifier with a : prefix. The : isn't included in the
return value
> hostParameterToken :: Parser String
> hostParameterToken = lexeme $ char ':' *> identifier
todo: work out the symbol parsing better
> symbol :: String -> Parser String

View file

@ -46,6 +46,11 @@ which have been changed to try to improve the layout of the output.
> valueExpr (Iden i) = name i
> valueExpr Star = text "*"
> valueExpr Parameter = text "?"
> valueExpr (HostParameter p i) =
> text (':':p)
> <+> maybe empty
> (\i' -> text "indicator" <+> text (':':i'))
> i
> valueExpr (App f es) = name f <> parens (commaSep (map valueExpr es))

View file

@ -121,6 +121,11 @@
> -- means not in was used ('a not in (1,2)')
> | In Bool ValueExpr InPredValue
> | Parameter -- ^ Represents a ? in a parameterized query
> | HostParameter String (Maybe String) -- ^ represents a host
> -- parameter, e.g. :a. The
> -- Maybe String is for the
> -- indicator, e.g. :var
> -- indicator :nl
> deriving (Eq,Show,Read,Data,Typeable)
> -- | Represents an identifier name, which can be quoted or unquoted.