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 :: Parser ValueExpr
> parameter = Parameter <$ questionMark > 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 == function application, aggregates and windows
this represents anything which syntactically looks like regular C 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 :: Parser ValueExpr
> term = choice [literal > term = choice [literal
> ,parameter > ,parameter
> ,hostParameter
> ,caseValue > ,caseValue
> ,cast > ,cast
> ,try specialOpKs > ,try specialOpKs
@ -887,6 +898,12 @@ make this choice.
TODO: add "" inside quoted identifiers 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 todo: work out the symbol parsing better
> symbol :: String -> Parser String > 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 (Iden i) = name i
> valueExpr Star = text "*" > valueExpr Star = text "*"
> valueExpr Parameter = 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)) > 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)') > -- means not in was used ('a not in (1,2)')
> | In Bool ValueExpr InPredValue > | In Bool ValueExpr InPredValue
> | Parameter -- ^ Represents a ? in a parameterized query > | 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) > deriving (Eq,Show,Read,Data,Typeable)
> -- | Represents an identifier name, which can be quoted or unquoted. > -- | Represents an identifier name, which can be quoted or unquoted.

View file

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