This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +42
-4
lines changed
tests/ServiceStack.OrmLite.Tests Expand file tree Collapse file tree 3 files changed +42
-4
lines changed Original file line number Diff line number Diff line change @@ -1155,10 +1155,17 @@ public virtual List<string> ToCreateIndexStatements(Type tableType)
1155
1155
if ( sb . Length > 0 )
1156
1156
sb . Append ( ", " ) ;
1157
1157
1158
- var parts = fieldName . SplitOnFirst ( ' ' ) ;
1159
- sb . Append ( GetQuotedColumnName ( parts [ 0 ] ) )
1160
- . Append ( ' ' )
1161
- . Append ( parts . Length > 1 ? parts [ 1 ] : "ASC" ) ;
1158
+ var parts = fieldName . SplitOnLast ( ' ' ) ;
1159
+ if ( parts . Length == 2 && ( parts [ 1 ] . ToLower ( ) . StartsWith ( "desc" ) || parts [ 1 ] . ToLower ( ) . StartsWith ( "asc" ) ) )
1160
+ {
1161
+ sb . Append ( GetQuotedColumnName ( parts [ 0 ] ) )
1162
+ . Append ( ' ' )
1163
+ . Append ( parts [ 1 ] ) ;
1164
+ }
1165
+ else
1166
+ {
1167
+ sb . Append ( GetQuotedColumnName ( fieldName ) ) ;
1168
+ }
1162
1169
}
1163
1170
1164
1171
sqlIndexes . Add (
Original file line number Diff line number Diff line change @@ -78,6 +78,25 @@ public void Can_create_ModelWithCompositeIndexFieldsDesc_table()
78
78
}
79
79
}
80
80
81
+ [ Test ]
82
+ public void Can_create_ModelWithCompositeIndexOnFieldSpacesDesc_table ( )
83
+ {
84
+ using ( var db = OpenDbConnection ( ) )
85
+ {
86
+ db . CreateTable < ModelWithCompositeIndexOnFieldSpacesDesc > ( true ) ;
87
+ db . GetLastSql ( ) . Print ( ) ;
88
+
89
+ var sql = OrmLiteConfig . DialectProvider . ToCreateIndexStatements ( typeof ( ModelWithCompositeIndexOnFieldSpacesDesc ) ) . Join ( ) ;
90
+
91
+ var compositeName = "idx_modelwithcompositeindexonfieldspacesdesc_field_field" ;
92
+
93
+ if ( Dialect == Dialect . Oracle || Dialect == Dialect . Firebird )
94
+ compositeName = OrmLiteConfig . DialectProvider . NamingStrategy . ApplyNameRestrictions ( compositeName ) . ToLower ( ) ;
95
+
96
+ Assert . That ( sql , Is . StringContaining ( compositeName ) ) ;
97
+ }
98
+ }
99
+
81
100
[ Test ]
82
101
public void Can_create_ModelWithNamedCompositeIndex_table ( )
83
102
{
Original file line number Diff line number Diff line change @@ -37,4 +37,16 @@ public class ModelWithCompositeIndexFieldsDesc
37
37
38
38
public string Composite2 { get ; set ; }
39
39
}
40
+
41
+ [ CompositeIndex ( "Field WithSpace1" , "Field WithSpace2 DESC" ) ]
42
+ public class ModelWithCompositeIndexOnFieldSpacesDesc
43
+ {
44
+ public string Id { get ; set ; }
45
+
46
+ [ Alias ( "Field WithSpace1" ) ]
47
+ public string FieldWithSpace1 { get ; set ; }
48
+
49
+ [ Alias ( "Field WithSpace2" ) ]
50
+ public string FieldWithSpace2 { get ; set ; }
51
+ }
40
52
}
You can’t perform that action at this time.
0 commit comments