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

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.

View file

@ -26,7 +26,7 @@ large amount of the SQL.
> --,identifiers
> --,typeNames
> --,parenthesizedValueExpression
> --,targetSpecification
> ,targetSpecification
> --,contextuallyTypeValueSpec
> --,nextValueExpression
> --,arrayElementReference
@ -1069,10 +1069,11 @@ TODO: review how the special keywords are parsed and add tests for these
> targetSpecification :: TestItem
> targetSpecification = Group "target specification" $ map (uncurry TestValueExpr)
> [(":hostparam", undefined)
> ,(":hostparam indicator :another_host_param", undefined)
> ,("?", undefined)
> ,(":h[3]", undefined)
> [(":hostparam", HostParameter "hostparam" Nothing)
> ,(":hostparam indicator :another_host_param"
> ,HostParameter "hostparam" $ Just "another_host_param")
> ,("?", Parameter)
> --,(":h[3]", Array (HostParameter "h" Nothing) [NumLit "3"])
> ]
TODO: modules stuff, not sure what current_collation is