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 {
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 @@ -6175,6 +6175,20 @@ impl<'a> Parser<'a> {
6175
6175
Ok ( Some ( ColumnOption :: DialectSpecific ( vec ! [
6176
6176
Token :: make_keyword( "AUTOINCREMENT" ) ,
6177
6177
] ) ) )
6178
+ } else if self . parse_keyword ( Keyword :: ASC )
6179
+ && self . dialect . supports_asc_desc_in_column_definition ( )
6180
+ {
6181
+ // Support ASC for SQLite
6182
+ Ok ( Some ( ColumnOption :: DialectSpecific ( vec ! [
6183
+ Token :: make_keyword( "ASC" ) ,
6184
+ ] ) ) )
6185
+ } else if self . parse_keyword ( Keyword :: DESC )
6186
+ && self . dialect . supports_asc_desc_in_column_definition ( )
6187
+ {
6188
+ // Support DESC for SQLite
6189
+ Ok ( Some ( ColumnOption :: DialectSpecific ( vec ! [
6190
+ Token :: make_keyword( "DESC" ) ,
6191
+ ] ) ) )
6178
6192
} else if self . parse_keywords ( & [ Keyword :: ON , Keyword :: UPDATE ] )
6179
6193
&& dialect_of ! ( self is MySqlDialect | GenericDialect )
6180
6194
{
Original file line number Diff line number Diff line change @@ -237,6 +237,43 @@ fn parse_create_table_auto_increment() {
237
237
}
238
238
}
239
239
240
+ #[ test]
241
+ fn parse_create_table_primary_key_asc_desc ( ) {
242
+ let expected_column_def = |kind| ColumnDef {
243
+ name : "bar" . into ( ) ,
244
+ data_type : DataType :: Int ( None ) ,
245
+ collation : None ,
246
+ options : vec ! [
247
+ ColumnOptionDef {
248
+ name: None ,
249
+ option: ColumnOption :: Unique {
250
+ is_primary: true ,
251
+ characteristics: None ,
252
+ } ,
253
+ } ,
254
+ ColumnOptionDef {
255
+ name: None ,
256
+ option: ColumnOption :: DialectSpecific ( vec![ Token :: make_keyword( kind) ] ) ,
257
+ } ,
258
+ ] ,
259
+ } ;
260
+
261
+ let sql = "CREATE TABLE foo (bar INT PRIMARY KEY ASC)" ;
262
+ match sqlite_and_generic ( ) . verified_stmt ( sql) {
263
+ Statement :: CreateTable ( CreateTable { columns, .. } ) => {
264
+ assert_eq ! ( vec![ expected_column_def( "ASC" ) ] , columns) ;
265
+ }
266
+ _ => unreachable ! ( ) ,
267
+ }
268
+ let sql = "CREATE TABLE foo (bar INT PRIMARY KEY DESC)" ;
269
+ match sqlite_and_generic ( ) . verified_stmt ( sql) {
270
+ Statement :: CreateTable ( CreateTable { columns, .. } ) => {
271
+ assert_eq ! ( vec![ expected_column_def( "DESC" ) ] , columns) ;
272
+ }
273
+ _ => unreachable ! ( ) ,
274
+ }
275
+ }
276
+
240
277
#[ test]
241
278
fn parse_create_sqlite_quote ( ) {
242
279
let sql = "CREATE TABLE `PRIMARY` (\" KEY\" INT, [INDEX] INT)" ;
You can’t perform that action at this time.
0 commit comments