@@ -198,7 +198,7 @@ import Text.Megaparsec
198
198
,hidden
199
199
,failure
200
200
,ErrorItem (.. )
201
-
201
+
202
202
,(<|>)
203
203
,token
204
204
,choice
@@ -233,11 +233,11 @@ import Control.Applicative ((<**>))
233
233
import Data.Char (isDigit )
234
234
import Data.List (sort ,groupBy )
235
235
import Data.Function (on )
236
- import Data.Maybe (catMaybes , isJust , mapMaybe )
236
+ import Data.Maybe (catMaybes , isJust , mapMaybe , fromMaybe )
237
237
import Data.Text (Text )
238
238
import qualified Data.Text as T
239
239
240
- import Language.SQL.SimpleSQL.Syntax
240
+ import Language.SQL.SimpleSQL.Syntax
241
241
import Language.SQL.SimpleSQL.Dialect
242
242
import qualified Language.SQL.SimpleSQL.Lex as L
243
243
-- import Text.Megaparsec.Debug (dbg)
@@ -332,7 +332,7 @@ wrapParse :: Parser a
332
332
-> Either ParseError a
333
333
wrapParse parser d f p src = do
334
334
lx <- either (Left . LexError ) Right $ L. lexSQLWithPositions d True f p src
335
- either (Left . ParseError ) Right $
335
+ either (Left . ParseError ) Right $
336
336
runReader (runParserT (parser <* (hidden eof)) (T. unpack f)
337
337
$ L. SQLStream (T. unpack src) $ filter notSpace lx) d
338
338
where
@@ -584,7 +584,7 @@ typeName' hideArg =
584
584
reservedTypeNames = do
585
585
stn <- askDialect diSpecialTypeNames
586
586
(: [] ) . Name Nothing . T. unwords <$> makeKeywordTree stn
587
-
587
+
588
588
589
589
{-
590
590
= Scalar expressions
@@ -1589,7 +1589,7 @@ queryExpr :: Parser QueryExpr
1589
1589
queryExpr = label " query expr" $ E. makeExprParser qeterm qeOpTable
1590
1590
where
1591
1591
qeterm = label " query expr" (with <|> select <|> table <|> values)
1592
-
1592
+
1593
1593
select = keyword_ " select" >>
1594
1594
mkSelect
1595
1595
<$> hoption SQDefault duplicates
@@ -1615,7 +1615,7 @@ queryExpr = label "query expr" $ E.makeExprParser qeterm qeOpTable
1615
1615
cq o d c q0 q1 = QueryExprSetOp q0 o d c q1
1616
1616
corr = hoption Respectively (Corresponding <$ keyword_ " corresponding" )
1617
1617
1618
-
1618
+
1619
1619
{-
1620
1620
local data type to help with parsing the bit after the select list,
1621
1621
called 'table expression' in the ansi sql grammar. Maybe this should
@@ -1707,21 +1707,25 @@ createSchema = keyword_ "schema" >>
1707
1707
CreateSchema <$> names " schema name"
1708
1708
1709
1709
createTable :: Parser Statement
1710
- createTable = do
1710
+ createTable = do
1711
1711
d <- askDialect id
1712
- let
1713
- parseColumnDef = TableColumnDef <$> columnDef
1712
+ let
1713
+ parseColumnDef = TableColumnDef <$> columnDef
1714
1714
parseConstraintDef = uncurry TableConstraintDef <$> tableConstraintDef
1715
1715
separator = if diNonCommaSeparatedConstraints d
1716
1716
then optional comma
1717
1717
else Just <$> comma
1718
1718
constraints = sepBy parseConstraintDef (hidden separator)
1719
1719
entries = ((:) <$> parseColumnDef <*> ((comma >> entries) <|> pure [] )) <|> constraints
1720
+ withoutRowid = if diWithoutRowidTables d
1721
+ then fromMaybe False <$> optional (keywords_ [" without" , " rowid" ] >> pure True )
1722
+ else pure False
1720
1723
1721
1724
keyword_ " table" >>
1722
1725
CreateTable
1723
1726
<$> names " table name"
1724
1727
<*> parens entries
1728
+ <*> withoutRowid
1725
1729
1726
1730
createIndex :: Parser Statement
1727
1731
createIndex =
@@ -1804,9 +1808,9 @@ colConstraintDef =
1804
1808
notNull = ColNotNullConstraint <$ keywords_ [" not" , " null" ]
1805
1809
unique = ColUniqueConstraint <$ keyword_ " unique"
1806
1810
primaryKey = do
1807
- keywords_ [" primary" , " key" ]
1811
+ keywords_ [" primary" , " key" ]
1808
1812
d <- askDialect id
1809
- autoincrement <- if diAutoincrement d
1813
+ autoincrement <- if diAutoincrement d
1810
1814
then optional (keyword_ " autoincrement" )
1811
1815
else pure Nothing
1812
1816
pure $ ColPrimaryKeyConstraint $ isJust autoincrement
@@ -1998,7 +2002,7 @@ delete = keywords_ ["delete","from"] >>
1998
2002
<*> optional (hoptional (keyword_ " as" ) *> name " alias" )
1999
2003
<*> optional (keyword_ " where" *> scalarExpr)
2000
2004
2001
- truncateSt :: Parser Statement
2005
+ truncateSt :: Parser Statement
2002
2006
truncateSt = keywords_ [" truncate" , " table" ] >>
2003
2007
Truncate
2004
2008
<$> names " table name"
@@ -2011,7 +2015,7 @@ insert = keywords_ ["insert", "into"] >>
2011
2015
Insert
2012
2016
<$> names " table name"
2013
2017
<*> (hoptional (parens $ commaSep1 $ name " column name" ))
2014
- <*>
2018
+ <*>
2015
2019
-- slight hack
2016
2020
(DefaultInsertValues <$ label " values" (keywords_ [" default" , " values" ])
2017
2021
<|> InsertQuery <$> queryExpr)
0 commit comments