From ff3dcb814c98a6c51826db16f0744b6951b3400a Mon Sep 17 00:00:00 2001 From: Jake Wheat Date: Wed, 10 Aug 2016 11:27:30 +0300 Subject: [PATCH] add support for oracle type size units 'char' and 'byte', example: varchar2(55 byte) --- Language/SQL/SimpleSQL/Parse.lhs | 4 ++++ simple-sql-parser.cabal | 1 + tools/Language/SQL/SimpleSQL/Oracle.lhs | 29 +++++++++++++++++++++++++ tools/Language/SQL/SimpleSQL/Tests.lhs | 2 ++ 4 files changed, 36 insertions(+) create mode 100644 tools/Language/SQL/SimpleSQL/Oracle.lhs diff --git a/Language/SQL/SimpleSQL/Parse.lhs b/Language/SQL/SimpleSQL/Parse.lhs index 21f620f..8639d5c 100644 --- a/Language/SQL/SimpleSQL/Parse.lhs +++ b/Language/SQL/SimpleSQL/Parse.lhs @@ -490,7 +490,11 @@ factoring in this function, and it is a little dense. > <|> PrecT <$ keyword_ "t" > <|> PrecP <$ keyword_ "p" > lobUnits = PrecCharacters <$ keyword_ "characters" +> -- char and byte are the oracle spelling +> -- todo: move these to oracle dialect +> <|> PrecCharacters <$ keyword_ "char" > <|> PrecOctets <$ keyword_ "octets" +> <|> PrecOctets <$ keyword_ "byte" > tz = True <$ keywords_ ["with", "time","zone"] > <|> False <$ keywords_ ["without", "time","zone"] > charSet = keywords_ ["character", "set"] *> names diff --git a/simple-sql-parser.cabal b/simple-sql-parser.cabal index ec9a889..a2a7548 100644 --- a/simple-sql-parser.cabal +++ b/simple-sql-parser.cabal @@ -72,6 +72,7 @@ Test-Suite Tests Language.SQL.SimpleSQL.GroupBy, Language.SQL.SimpleSQL.MySQL, Language.SQL.SimpleSQL.Postgres, + Language.SQL.SimpleSQL.Oracle, Language.SQL.SimpleSQL.QueryExprComponents, Language.SQL.SimpleSQL.QueryExprs, Language.SQL.SimpleSQL.SQL2011Queries, diff --git a/tools/Language/SQL/SimpleSQL/Oracle.lhs b/tools/Language/SQL/SimpleSQL/Oracle.lhs new file mode 100644 index 0000000..e9318c7 --- /dev/null +++ b/tools/Language/SQL/SimpleSQL/Oracle.lhs @@ -0,0 +1,29 @@ + +Tests for oracle dialect parsing + +> module Language.SQL.SimpleSQL.Oracle (oracleTests) where + +> import Language.SQL.SimpleSQL.TestTypes +> import Language.SQL.SimpleSQL.Syntax + +> oracleTests :: TestItem +> oracleTests = Group "oracle dialect" +> [oracleLobUnits] + + +> oracleLobUnits :: TestItem +> oracleLobUnits = Group "oracleLobUnits" (map (uncurry (TestScalarExpr oracle)) +> [("cast (a as varchar2(3 char))" +> ,Cast (Iden [Name Nothing "a"]) ( +> PrecLengthTypeName [Name Nothing "varchar2"] 3 Nothing (Just PrecCharacters))) +> ,("cast (a as varchar2(3 byte))" +> ,Cast (Iden [Name Nothing "a"]) ( +> PrecLengthTypeName [Name Nothing "varchar2"] 3 Nothing (Just PrecOctets))) +> ] +> ++ [TestStatement oracle +> "create table t (a varchar2(55 BYTE));" +> $ CreateTable [Name Nothing "t"] +> [TableColumnDef $ ColumnDef (Name Nothing "a") +> (PrecLengthTypeName [Name Nothing "varchar2"] 55 Nothing (Just PrecOctets)) +> Nothing []]] +> ) diff --git a/tools/Language/SQL/SimpleSQL/Tests.lhs b/tools/Language/SQL/SimpleSQL/Tests.lhs index 8e2cf99..8b5baf1 100644 --- a/tools/Language/SQL/SimpleSQL/Tests.lhs +++ b/tools/Language/SQL/SimpleSQL/Tests.lhs @@ -37,6 +37,7 @@ test data to the Test.Framework tests. > import Language.SQL.SimpleSQL.SQL2011Schema > import Language.SQL.SimpleSQL.MySQL +> import Language.SQL.SimpleSQL.Oracle Order the tests to start from the simplest first. This is also the order on the generated documentation. @@ -60,6 +61,7 @@ order on the generated documentation. > ,sql2011AccessControlTests > ,sql2011BitsTests > ,mySQLTests +> ,oracleTests > ] > tests :: T.TestTree