1
Fork 0

add support for typenames with precision and scale

This commit is contained in:
Jake Wheat 2013-12-17 19:52:14 +02:00
parent 60d1b446db
commit 558d44140a
5 changed files with 31 additions and 8 deletions
Language/SQL/SimpleSQL

View file

@ -327,7 +327,13 @@ that SQL supports.
> <$ try (keyword_ "double" <* keyword_ "precision")
> ,TypeName "character varying"
> <$ try (keyword_ "character" <* keyword_ "varying")
> ,TypeName <$> identifierString]
> ,TypeName <$> identifierString] >>= optionSuffix precision
> where
> precision t = try (parens (commaSep integerLiteral)) >>= makeWrap t
> makeWrap (TypeName t) [a] = return $ PrecTypeName t a
> makeWrap (TypeName t) [a,b] = return $ Prec2TypeName t a b
> makeWrap _ _ = fail "there must be one or two precision components"
== scalar parens and row ctor

View file

@ -128,13 +128,13 @@
> <+> text "then" <+> nest 5 (scalarExpr t1)
> e el = text "else" <+> nest 5 (scalarExpr el)
> scalarExpr (Parens e) = parens $ scalarExpr e
> scalarExpr (Cast e (TypeName tn)) =
> scalarExpr (Cast e tn) =
> text "cast" <> parens (sep [scalarExpr e
> ,text "as"
> ,text tn])
> ,typeName tn])
> scalarExpr (TypedLit (TypeName tn) s) =
> text tn <+> quotes (text s)
> scalarExpr (TypedLit tn s) =
> typeName tn <+> quotes (text s)
> scalarExpr (SubQueryExpr ty qe) =
> (case ty of
@ -162,6 +162,13 @@
> name (QName n) = doubleQuotes $ text n
> name (Name n) = text n
> typeName :: TypeName -> Doc
> typeName (TypeName t) = text t
> typeName (PrecTypeName t a) = text t <+> parens (text $ show a)
> typeName (Prec2TypeName t a b) =
> text t <+> parens (text (show a) <+> comma <+> text (show b))
= query expressions
> queryExpr :: QueryExpr -> Doc

View file

@ -121,7 +121,10 @@
> deriving (Eq,Show,Read)
> -- | Represents a type name, used in casts.
> data TypeName = TypeName String deriving (Eq,Show,Read)
> data TypeName = TypeName String
> | PrecTypeName String Int
> | Prec2TypeName String Int Int
> deriving (Eq,Show,Read)
> -- | Used for 'expr in (scalar expression list)', and 'expr in