@@ -1522,6 +1522,8 @@ impl<'a> Parser<'a> {
15221522 query : None ,
15231523 without_rowid : false ,
15241524 like : None ,
1525+ default_charset : None ,
1526+ engine : None ,
15251527 } )
15261528 }
15271529
@@ -1696,6 +1698,26 @@ impl<'a> Parser<'a> {
16961698 None
16971699 } ;
16981700
1701+ let engine = if self . parse_keyword ( Keyword :: ENGINE ) {
1702+ self . expect_token ( & Token :: Eq ) ?;
1703+ match self . next_token ( ) {
1704+ Token :: Word ( w) => Some ( w. value ) ,
1705+ unexpected => self . expected ( "identifier" , unexpected) ?,
1706+ }
1707+ } else {
1708+ None
1709+ } ;
1710+
1711+ let default_charset = if self . parse_keywords ( & [ Keyword :: DEFAULT , Keyword :: CHARSET ] ) {
1712+ self . expect_token ( & Token :: Eq ) ?;
1713+ match self . next_token ( ) {
1714+ Token :: Word ( w) => Some ( w. value ) ,
1715+ unexpected => self . expected ( "identifier" , unexpected) ?,
1716+ }
1717+ } else {
1718+ None
1719+ } ;
1720+
16991721 Ok ( Statement :: CreateTable {
17001722 name : table_name,
17011723 temporary,
@@ -1713,6 +1735,8 @@ impl<'a> Parser<'a> {
17131735 query,
17141736 without_rowid,
17151737 like,
1738+ engine,
1739+ default_charset,
17161740 } )
17171741 }
17181742
@@ -1778,8 +1802,15 @@ impl<'a> Parser<'a> {
17781802 }
17791803
17801804 pub fn parse_optional_column_option ( & mut self ) -> Result < Option < ColumnOption > , ParserError > {
1781- if self . parse_keywords ( & [ Keyword :: NOT , Keyword :: NULL ] ) {
1805+ if self . parse_keywords ( & [ Keyword :: CHARACTER , Keyword :: SET ] ) {
1806+ Ok ( Some ( ColumnOption :: CharacterSet ( self . parse_object_name ( ) ?) ) )
1807+ } else if self . parse_keywords ( & [ Keyword :: NOT , Keyword :: NULL ] ) {
17821808 Ok ( Some ( ColumnOption :: NotNull ) )
1809+ } else if self . parse_keywords ( & [ Keyword :: COMMENT ] ) {
1810+ match self . next_token ( ) {
1811+ Token :: SingleQuotedString ( value, ..) => Ok ( Some ( ColumnOption :: Comment ( value) ) ) ,
1812+ unexpected => self . expected ( "string" , unexpected) ,
1813+ }
17831814 } else if self . parse_keyword ( Keyword :: NULL ) {
17841815 Ok ( Some ( ColumnOption :: Null ) )
17851816 } else if self . parse_keyword ( Keyword :: DEFAULT ) {
@@ -2301,6 +2332,8 @@ impl<'a> Parser<'a> {
23012332 let ( precision, scale) = self . parse_optional_precision_scale ( ) ?;
23022333 Ok ( DataType :: Decimal ( precision, scale) )
23032334 }
2335+ Keyword :: ENUM => Ok ( DataType :: Enum ( self . parse_string_values ( ) ?) ) ,
2336+ Keyword :: SET => Ok ( DataType :: Set ( self . parse_string_values ( ) ?) ) ,
23042337 _ => {
23052338 self . prev_token ( ) ;
23062339 let type_name = self . parse_object_name ( ) ?;
@@ -2311,6 +2344,23 @@ impl<'a> Parser<'a> {
23112344 }
23122345 }
23132346
2347+ pub fn parse_string_values ( & mut self ) -> Result < Vec < String > , ParserError > {
2348+ self . expect_token ( & Token :: LParen ) ?;
2349+ let mut values = Vec :: new ( ) ;
2350+ loop {
2351+ match self . next_token ( ) {
2352+ Token :: SingleQuotedString ( value) => values. push ( value) ,
2353+ unexpected => self . expected ( "a string" , unexpected) ?,
2354+ }
2355+ match self . next_token ( ) {
2356+ Token :: Comma => ( ) ,
2357+ Token :: RParen => break ,
2358+ unexpected => self . expected ( ", or }" , unexpected) ?,
2359+ }
2360+ }
2361+ Ok ( values)
2362+ }
2363+
23142364 /// Parse `AS identifier` (or simply `identifier` if it's not a reserved keyword)
23152365 /// Some examples with aliases: `SELECT 1 foo`, `SELECT COUNT(*) AS cnt`,
23162366 /// `SELECT ... FROM t1 foo, t2 bar`, `SELECT ... FROM (...) AS bar`
0 commit comments