File tree Expand file tree Collapse file tree 5 files changed +63
-0
lines changed Expand file tree Collapse file tree 5 files changed +63
-0
lines changed Original file line number Diff line number Diff line change @@ -103,4 +103,8 @@ impl Dialect for GenericDialect {
103103 fn supports_limit_comma ( & self ) -> bool {
104104 true
105105 }
106+
107+ fn supports_asc_desc_in_column_definition ( & self ) -> bool {
108+ true
109+ }
106110}
Original file line number Diff line number Diff line change @@ -557,6 +557,10 @@ pub trait Dialect: Debug + Any {
557557 fn supports_explain_with_utility_options ( & self ) -> bool {
558558 false
559559 }
560+
561+ fn supports_asc_desc_in_column_definition ( & self ) -> bool {
562+ false
563+ }
560564}
561565
562566/// This represents the operators for which precedence must be defined
Original file line number Diff line number Diff line change @@ -77,4 +77,8 @@ impl Dialect for SQLiteDialect {
7777 fn supports_limit_comma ( & self ) -> bool {
7878 true
7979 }
80+
81+ fn supports_asc_desc_in_column_definition ( & self ) -> bool {
82+ true
83+ }
8084}
Original file line number Diff line number Diff line change @@ -6192,6 +6192,20 @@ impl<'a> Parser<'a> {
61926192 Ok ( Some ( ColumnOption :: DialectSpecific ( vec ! [
61936193 Token :: make_keyword( "AUTOINCREMENT" ) ,
61946194 ] ) ) )
6195+ } else if self . parse_keyword ( Keyword :: ASC )
6196+ && self . dialect . supports_asc_desc_in_column_definition ( )
6197+ {
6198+ // Support ASC for SQLite
6199+ Ok ( Some ( ColumnOption :: DialectSpecific ( vec ! [
6200+ Token :: make_keyword( "ASC" ) ,
6201+ ] ) ) )
6202+ } else if self . parse_keyword ( Keyword :: DESC )
6203+ && self . dialect . supports_asc_desc_in_column_definition ( )
6204+ {
6205+ // Support DESC for SQLite
6206+ Ok ( Some ( ColumnOption :: DialectSpecific ( vec ! [
6207+ Token :: make_keyword( "DESC" ) ,
6208+ ] ) ) )
61956209 } else if self . parse_keywords ( & [ Keyword :: ON , Keyword :: UPDATE ] )
61966210 && dialect_of ! ( self is MySqlDialect | GenericDialect )
61976211 {
Original file line number Diff line number Diff line change @@ -238,6 +238,43 @@ fn parse_create_table_auto_increment() {
238238 }
239239}
240240
241+ #[ test]
242+ fn parse_create_table_primary_key_asc_desc ( ) {
243+ let expected_column_def = |kind| ColumnDef {
244+ name : "bar" . into ( ) ,
245+ data_type : DataType :: Int ( None ) ,
246+ collation : None ,
247+ options : vec ! [
248+ ColumnOptionDef {
249+ name: None ,
250+ option: ColumnOption :: Unique {
251+ is_primary: true ,
252+ characteristics: None ,
253+ } ,
254+ } ,
255+ ColumnOptionDef {
256+ name: None ,
257+ option: ColumnOption :: DialectSpecific ( vec![ Token :: make_keyword( kind) ] ) ,
258+ } ,
259+ ] ,
260+ } ;
261+
262+ let sql = "CREATE TABLE foo (bar INT PRIMARY KEY ASC)" ;
263+ match sqlite_and_generic ( ) . verified_stmt ( sql) {
264+ Statement :: CreateTable ( CreateTable { columns, .. } ) => {
265+ assert_eq ! ( vec![ expected_column_def( "ASC" ) ] , columns) ;
266+ }
267+ _ => unreachable ! ( ) ,
268+ }
269+ let sql = "CREATE TABLE foo (bar INT PRIMARY KEY DESC)" ;
270+ match sqlite_and_generic ( ) . verified_stmt ( sql) {
271+ Statement :: CreateTable ( CreateTable { columns, .. } ) => {
272+ assert_eq ! ( vec![ expected_column_def( "DESC" ) ] , columns) ;
273+ }
274+ _ => unreachable ! ( ) ,
275+ }
276+ }
277+
241278#[ test]
242279fn parse_create_sqlite_quote ( ) {
243280 let sql = "CREATE TABLE `PRIMARY` (\" KEY\" INT, [INDEX] INT)" ;
You can’t perform that action at this time.
0 commit comments