File tree 5 files changed +63
-0
lines changed
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 {
103
103
fn supports_limit_comma ( & self ) -> bool {
104
104
true
105
105
}
106
+
107
+ fn supports_asc_desc_in_column_definition ( & self ) -> bool {
108
+ true
109
+ }
106
110
}
Original file line number Diff line number Diff line change @@ -557,6 +557,10 @@ pub trait Dialect: Debug + Any {
557
557
fn supports_explain_with_utility_options ( & self ) -> bool {
558
558
false
559
559
}
560
+
561
+ fn supports_asc_desc_in_column_definition ( & self ) -> bool {
562
+ false
563
+ }
560
564
}
561
565
562
566
/// 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 {
77
77
fn supports_limit_comma ( & self ) -> bool {
78
78
true
79
79
}
80
+
81
+ fn supports_asc_desc_in_column_definition ( & self ) -> bool {
82
+ true
83
+ }
80
84
}
Original file line number Diff line number Diff line change @@ -6192,6 +6192,20 @@ impl<'a> Parser<'a> {
6192
6192
Ok ( Some ( ColumnOption :: DialectSpecific ( vec ! [
6193
6193
Token :: make_keyword( "AUTOINCREMENT" ) ,
6194
6194
] ) ) )
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
+ ] ) ) )
6195
6209
} else if self . parse_keywords ( & [ Keyword :: ON , Keyword :: UPDATE ] )
6196
6210
&& dialect_of ! ( self is MySqlDialect | GenericDialect )
6197
6211
{
Original file line number Diff line number Diff line change @@ -238,6 +238,43 @@ fn parse_create_table_auto_increment() {
238
238
}
239
239
}
240
240
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
+
241
278
#[ test]
242
279
fn parse_create_sqlite_quote ( ) {
243
280
let sql = "CREATE TABLE `PRIMARY` (\" KEY\" INT, [INDEX] INT)" ;
You can’t perform that action at this time.
0 commit comments