1
Fork 0

remove ref typename for consistency

support t and p multipliers in lob lengths
update a few tests
This commit is contained in:
Jake Wheat 2014-04-20 19:24:03 +03:00
parent c50b3e7839
commit 9b2ba2fb36
7 changed files with 114 additions and 98 deletions

View file

@ -420,7 +420,7 @@ TODO: this code needs heavy refactoring
> typeName :: Parser TypeName > typeName :: Parser TypeName
> typeName = > typeName =
> (rowTypeName <|> intervalTypeName <|> ref <|> otherTypeName) > (rowTypeName <|> intervalTypeName <|> otherTypeName)
> >>= tnSuffix > >>= tnSuffix
> <?> "typename" > <?> "typename"
> where > where
@ -432,11 +432,6 @@ TODO: this code needs heavy refactoring
> intervalTypeName = > intervalTypeName =
> keyword_ "interval" >> > keyword_ "interval" >>
> uncurry IntervalTypeName <$> intervalQualifier > uncurry IntervalTypeName <$> intervalQualifier
> ref =
> keyword_ "ref" >>
> RefTypeName
> <$> parens (names)
> <*> optionMaybe (keyword_ "scope" *> names)
> -- other type names, which includes: > -- other type names, which includes:
> -- precision, scale, lob scale and units, timezone, character > -- precision, scale, lob scale and units, timezone, character
> -- set and collations > -- set and collations
@ -478,6 +473,8 @@ TODO: this code needs heavy refactoring
> x <- choice [Just LobK <$ keyword_ "k" > x <- choice [Just LobK <$ keyword_ "k"
> ,Just LobM <$ keyword_ "m" > ,Just LobM <$ keyword_ "m"
> ,Just LobG <$ keyword_ "g" > ,Just LobG <$ keyword_ "g"
> ,Just LobT <$ keyword_ "t"
> ,Just LobP <$ keyword_ "p"
> ,return Nothing] > ,return Nothing]
> return (p,x) > return (p,x)
> lobUnits = choice [LobCharacters <$ keyword_ "characters" > lobUnits = choice [LobCharacters <$ keyword_ "characters"

View file

@ -263,7 +263,9 @@ which have been changed to try to improve the layout of the output.
> <> me (\x -> case x of > <> me (\x -> case x of
> LobK -> text "K" > LobK -> text "K"
> LobM -> text "M" > LobM -> text "M"
> LobG -> text "G") m > LobG -> text "G"
> LobT -> text "T"
> LobP -> text "P") m
> <+> me (\x -> case x of > <+> me (\x -> case x of
> LobCharacters -> text "CHARACTERS" > LobCharacters -> text "CHARACTERS"
> LobOctets -> text "OCTETS") u) > LobOctets -> text "OCTETS") u)
@ -297,11 +299,6 @@ which have been changed to try to improve the layout of the output.
> typeName (MultisetTypeName tn) = > typeName (MultisetTypeName tn) =
> typeName tn <+> text "multiset" > typeName tn <+> text "multiset"
> typeName (RefTypeName rt sc) =
> text "ref"
> <> parens (names rt)
> <+> me (\x -> text "scope" <+> names x) sc
> intervalTypeField :: IntervalTypeField -> Doc > intervalTypeField :: IntervalTypeField -> Doc
> intervalTypeField (Itf n p) = > intervalTypeField (Itf n p) =
> text n > text n

View file

@ -167,8 +167,6 @@
> | UQName String > | UQName String
> deriving (Eq,Show,Read,Data,Typeable) > deriving (Eq,Show,Read,Data,Typeable)
TODO: add ref and scope, any others?
> -- | Represents a type name, used in casts. > -- | Represents a type name, used in casts.
> data TypeName > data TypeName
> = TypeName [Name] > = TypeName [Name]
@ -182,13 +180,12 @@ TODO: add ref and scope, any others?
> | IntervalTypeName IntervalTypeField (Maybe IntervalTypeField) > | IntervalTypeName IntervalTypeField (Maybe IntervalTypeField)
> | ArrayTypeName TypeName (Maybe Integer) > | ArrayTypeName TypeName (Maybe Integer)
> | MultisetTypeName TypeName > | MultisetTypeName TypeName
> | RefTypeName [Name] (Maybe [Name])
> deriving (Eq,Show,Read,Data,Typeable) > deriving (Eq,Show,Read,Data,Typeable)
> data IntervalTypeField = Itf String (Maybe (Integer, Maybe Integer)) > data IntervalTypeField = Itf String (Maybe (Integer, Maybe Integer))
> deriving (Eq,Show,Read,Data,Typeable) > deriving (Eq,Show,Read,Data,Typeable)
> data LobMultiplier = LobK | LobM | LobG > data LobMultiplier = LobK | LobM | LobG | LobT | LobP
> deriving (Eq,Show,Read,Data,Typeable) > deriving (Eq,Show,Read,Data,Typeable)
> data LobUnits = LobCharacters > data LobUnits = LobCharacters
> | LobOctets > | LobOctets

116
TODO
View file

@ -1,4 +1,4 @@
continue 2003 review and tests continue 2011 review and tests
1. start replacing the 2003 stuff with 2011 1. start replacing the 2003 stuff with 2011
2. create an error message document for the website 2. create an error message document for the website
@ -62,76 +62,58 @@ rules for changing the multi keyword parsing:
recursive, then don't do this. recursive, then don't do this.
rough SQL 2003 todo, including tests to write: rough SQL 2011 todo, including tests to write:
switch to SQL 2011
now:
review the commented out reserved keyword entries and work out how to review the commented out reserved keyword entries and work out how to
fix fix
go through all? the functions
go through almost all the predicates
window functions missing bits, window clauses
from: more tests, review missing
tablesample, unnest, etc.
rows review
match missing bit
between symmetric
case review
detail list from the grammar, LNR = maybe leave until after next big areas:
release, otherwise planned for next release window functions
nested window functions
case
table ref
joined table
group by
window clause
LNR support needed MODULE syntax in identifiers - already covered? other areas:
LNR decide how to represent special identifiers including the session unicode escape, strings and idens
variables or whatever they are called like current_user character set behaviour review
LNR grouping - needs special syntax? datetime literals
LNR next value for mixed quoting identifier chains
LNR subtypes, methods, new /routine, dereference names/identifiers careful review
LNR double check associativity, precedence (value exprs, joins, set ops) typenames: lengths, binary
position expressions general value bits
length expressions collate for
extract expression numeric val fn
cardinality expression? string exp fn
check concatenations datetime exp fn
substring expressions interval exp fn
regular expression substring function rows
convert table value constructor
translate interval qualifier
trim query spec
overlay with
LNR specifictype setop
row value constructors, expressions review explicit table
review table value constructor exactly what is allowed order/offset/fetch
lots more tests for from clause variations search/cycle
tablesamples preds:
unnest between
table function derived table in
only spec like
join variations, including union join similar
review group by regex like?
window clauses null
LNR all fields reference with alias 'select * as (a,b,c) ... ' normalize
search or cycle clause match
between symmetric/asymmetric overlaps
in predicate review distinct
escape for like member
escape for [not] similar to submultiset
LNR regular expression syntax? period
normalized predicate
overlaps predicate
distinct from predicate
member predicate
submultiset predicate
set predicate
LNR type predicate
additional stuff review:
complete the list of keywords/reserved keywords and check everything
still works ok. The parser will reject all unquoted identifiers
which are the same as reserved or unreserved keywords.
LNR select into
LNR other language format identifiers for host params?
create list of unsupported syntax: xml, ref, subtypes, modules?
--- ---
@ -248,6 +230,10 @@ string literals
full number literals -> other bases? full number literals -> other bases?
apply, pivot apply, pivot
maybe add dml and ddl, source poses, quasi quotes
leave: type check, dialects, procedural, separate lexing?
other dialect targets: other dialect targets:
postgres postgres
oracle oracle

View file

@ -1,7 +1,10 @@
name: simple-sql-parser name: simple-sql-parser
version: 0.4.0 version: 0.4.0
synopsis: A parser for SQL queries synopsis: A parser for SQL queries
description: A parser for SQL queries. Please see the homepage for more information <http://jakewheat.github.io/simple-sql-parser/>.
description: A parser for SQL queries. Parses most SQL:2011
queries. Please see the homepage for more information
<http://jakewheat.github.io/simple-sql-parser/>.
homepage: http://jakewheat.github.io/simple-sql-parser/ homepage: http://jakewheat.github.io/simple-sql-parser/
license: BSD3 license: BSD3
@ -36,6 +39,7 @@ library
default-language: Haskell2010 default-language: Haskell2010
ghc-options: -Wall ghc-options: -Wall
other-extensions: TupleSections,DeriveDataTypeable other-extensions: TupleSections,DeriveDataTypeable
Test-Suite Tests Test-Suite Tests
type: exitcode-stdio-1.0 type: exitcode-stdio-1.0
main-is: RunTests.lhs main-is: RunTests.lhs
@ -67,7 +71,7 @@ Test-Suite Tests
Language.SQL.SimpleSQL.Tpch, Language.SQL.SimpleSQL.Tpch,
Language.SQL.SimpleSQL.ValueExprs Language.SQL.SimpleSQL.ValueExprs
other-extensions: TupleSections,OverloadedStrings,DeriveDataTypeable other-extensions: TupleSections,DeriveDataTypeable
default-language: Haskell2010 default-language: Haskell2010
ghc-options: -Wall ghc-options: -Wall
@ -78,6 +82,7 @@ executable SQLIndent
parsec >=3.1 && <3.2, parsec >=3.1 && <3.2,
mtl >=2.1 && <2.2, mtl >=2.1 && <2.2,
pretty >= 1.1 && < 1.2 pretty >= 1.1 && < 1.2
other-extensions: TupleSections,DeriveDataTypeable
default-language: Haskell2010 default-language: Haskell2010
ghc-options: -Wall ghc-options: -Wall
if flag(sqlindent) if flag(sqlindent)

View file

@ -1130,8 +1130,6 @@ create a list of type name variations:
> ,("interval year(4) to second(2,3)" > ,("interval year(4) to second(2,3)"
> ,IntervalTypeName (Itf "year" $ Just (4,Nothing)) > ,IntervalTypeName (Itf "year" $ Just (4,Nothing))
> (Just $ Itf "second" $ Just (2, Just 3))) > (Just $ Itf "second" $ Just (2, Just 3)))
> ,("ref (t)", RefTypeName [Name "t"] Nothing)
> ,("ref (t) scope q", RefTypeName [Name "t"] (Just [Name "q"]))
> ] > ]
Now test each variation in both cast expression and typed literal Now test each variation in both cast expression and typed literal

View file

@ -16,6 +16,7 @@ which parts aren't currently supported.
> [literals > [literals
> ,identifiers > ,identifiers
> ,typeNameTests > ,typeNameTests
> ,fieldDefinition
> ,valueExpressions > ,valueExpressions
> ,queryExpressions > ,queryExpressions
> ,scalarSubquery > ,scalarSubquery
@ -494,6 +495,11 @@ Specify a non-null value.
> ,StringLit "a quote: ', stuff") > ,StringLit "a quote: ', stuff")
> ,("''" > ,("''"
> ,StringLit "") > ,StringLit "")
I'm not sure how this should work. Maybe the parser should reject non
ascii characters in strings and identifiers unless the current SQL
character set allows them.
> ,("_francais 'français'" > ,("_francais 'français'"
> ,TypedLit (TypeName [Name "_francais"]) "français") > ,TypedLit (TypeName [Name "_francais"]) "français")
> ] > ]
@ -1055,6 +1061,8 @@ create a list of type name variations:
> ,("decimal(15,2)", PrecScaleTypeName [Name "decimal"] 15 2) > ,("decimal(15,2)", PrecScaleTypeName [Name "decimal"] 15 2)
> -- lob prec + with multiname > -- lob prec + with multiname
> ,("blob(3M)", LobTypeName [Name "blob"] 3 (Just LobM) Nothing) > ,("blob(3M)", LobTypeName [Name "blob"] 3 (Just LobM) Nothing)
> ,("blob(3T)", LobTypeName [Name "blob"] 3 (Just LobT) Nothing)
> ,("blob(3P)", LobTypeName [Name "blob"] 3 (Just LobP) Nothing)
> ,("blob(4M characters) " > ,("blob(4M characters) "
> ,LobTypeName [Name "blob"] 4 (Just LobM) (Just LobCharacters)) > ,LobTypeName [Name "blob"] 4 (Just LobM) (Just LobCharacters))
> ,("blob(6G octets) " > ,("blob(6G octets) "
@ -1145,8 +1153,6 @@ create a list of type name variations:
> ,("interval year(4) to second(2,3)" > ,("interval year(4) to second(2,3)"
> ,IntervalTypeName (Itf "year" $ Just (4,Nothing)) > ,IntervalTypeName (Itf "year" $ Just (4,Nothing))
> (Just $ Itf "second" $ Just (2, Just 3))) > (Just $ Itf "second" $ Just (2, Just 3)))
> ,("ref (t)", RefTypeName [Name "t"] Nothing)
> ,("ref (t) scope q", RefTypeName [Name "t"] (Just [Name "q"]))
> ] > ]
Now test each variation in both cast expression and typed literal Now test each variation in both cast expression and typed literal
@ -1169,7 +1175,13 @@ Define a field of a row type.
<field definition> ::= <field name> <data type> <field definition> ::= <field name> <data type>
Tested in the row type above. > fieldDefinition :: TestItem
> fieldDefinition = Group "field definition"
> $ map (uncurry TestValueExpr)
> [("cast('(1,2)' as row(a int,b char))"
> ,Cast (StringLit "(1,2)")
> $ RowTypeName [(Name "a", TypeName [Name "int"])
> ,(Name "b", TypeName [Name "char"])])]
== 6.3 <value expression primary> == 6.3 <value expression primary>
@ -1214,6 +1226,8 @@ Specify a value that is syntactically self-delimited.
> [generalValueSpecification > [generalValueSpecification
> ,parameterSpecification > ,parameterSpecification
> ,contextuallyTypedValueSpecification > ,contextuallyTypedValueSpecification
> ,identifierChain
> ,columnReference
> ,setFunctionSpecification > ,setFunctionSpecification
> ,windowFunction > ,windowFunction
> ,nestedWindowFunction > ,nestedWindowFunction
@ -1384,7 +1398,10 @@ Disambiguate a <period>-separated chain of identifiers.
<basic identifier chain> ::= <identifier chain> <basic identifier chain> ::= <identifier chain>
tested with the identifier tests above > identifierChain :: TestItem
> identifierChain = Group "identifier chain"
> $ map (uncurry TestValueExpr)
> [("a.b", Iden [Name "a",Name "b"])]
== 6.7 <column reference> == 6.7 <column reference>
@ -1395,7 +1412,10 @@ Reference a column.
<basic identifier chain> <basic identifier chain>
| MODULE <period> <qualified identifier> <period> <column name> | MODULE <period> <qualified identifier> <period> <column name>
tested with the identifier tests above > columnReference :: TestItem
> columnReference = Group "column reference"
> $ map (uncurry TestValueExpr)
> [("module.a.b", Iden [Name "module",Name "a",Name "b"])]
== 6.8 <SQL parameter reference> == 6.8 <SQL parameter reference>
@ -1404,8 +1424,6 @@ Reference an SQL parameter.
<SQL parameter reference> ::= <basic identifier chain> <SQL parameter reference> ::= <basic identifier chain>
tested with the identifier tests above
== 6.9 <set function specification> == 6.9 <set function specification>
Function Function
@ -1590,6 +1608,11 @@ Specify a conditional value.
| <set predicate part 2> | <set predicate part 2>
| <type predicate part 2> | <type predicate part 2>
I haven't seen these part 2 style when operands in the wild. It
doesn't even allow all the binary operators here. We will allow them
all, and parser and represent these expressions by considering all the
binary ops as unary prefix ops.
<result> ::= <result expression> | NULL <result> ::= <result expression> | NULL
<result expression> ::= <value expression> <result expression> ::= <value expression>
@ -1611,8 +1634,6 @@ Specify a data conversion.
<cast target> ::= <domain name> | <data type> <cast target> ::= <domain name> | <data type>
This is already tested with the type name tests
> castSpecification :: TestItem > castSpecification :: TestItem
> castSpecification = Group "cast specification" > castSpecification = Group "cast specification"
> $ map (uncurry TestValueExpr) > $ map (uncurry TestValueExpr)
@ -2230,7 +2251,6 @@ Specify an interval value.
> intervalValueExpression :: TestItem > intervalValueExpression :: TestItem
> intervalValueExpression = Group "interval value expression" > intervalValueExpression = Group "interval value expression"
> [-- todo: interval value expression > [-- todo: interval value expression
> intervalValueFunction
> ] > ]
@ -2334,7 +2354,6 @@ Specify an array value.
> arrayValueExpression :: TestItem > arrayValueExpression :: TestItem
> arrayValueExpression = Group "array value expression" > arrayValueExpression = Group "array value expression"
> [-- todo: array value expression > [-- todo: array value expression
> arrayValueFunction
> ] > ]
== 6.37 <array value function> == 6.37 <array value function>
@ -3080,7 +3099,9 @@ the result of recursive query expressions.
== 7.15 <subquery> == 7.15 <subquery>
Function Function
Specify a scalar value, a row, or a table derived from a <query expression>.
Specify a scalar value, a row, or a table derived from a <query
expression>.
<scalar subquery> ::= <subquery> <scalar subquery> ::= <subquery>
@ -3169,9 +3190,24 @@ Specify a comparison of two row values.
> comparisonPredicates :: TestItem > comparisonPredicates :: TestItem
> comparisonPredicates = Group "comparison predicates" > comparisonPredicates = Group "comparison predicates"
> [-- todo: comparison predicates > $ map (uncurry TestValueExpr)
> $ map mkOp ["=", "<>", "<", ">", "<=", ">="]
> ++ [("ROW(a) = ROW(b)"
> ,BinOp (App [Name "ROW"] [a])
> [Name "="]
> (App [Name "ROW"] [b]))
> ,("(a,b) = (c,d)"
> ,BinOp (SpecialOp [Name "rowctor"] [a,b])
> [Name "="]
> (SpecialOp [Name "rowctor"] [Iden [Name "c"], Iden [Name "d"]]))
> ] > ]
> where
> mkOp nm = ("a " ++ nm ++ " b"
> ,BinOp a [Name nm] b)
> a = Iden [Name "a"]
> b = Iden [Name "b"]
TODO: what other tests, more complex expressions with comparisons?
== 8.3 <between predicate> == 8.3 <between predicate>