@@ -63,7 +63,14 @@ public void ConnectionOpened(DbConnection connection, ConnectionEndEventData eve
6363 //setup general use collation
6464 sqliteConnection . CreateCollation ( SqlSortingExtensions . CollateUnicodeNoCase ,
6565 CultureInfo . CurrentCulture . CompareInfo ,
66- ( compareInfo , x , y ) => compareInfo . Compare ( x , y , CompareOptions . IgnoreCase ) ) ;
66+ ( compareInfo , x , y ) =>
67+ {
68+ var caseInsensitiveResult = compareInfo . Compare ( x , y , CompareOptions . IgnoreCase ) ;
69+ if ( caseInsensitiveResult != 0 )
70+ return caseInsensitiveResult ;
71+ // When case-insensitively equal, sort lowercase before uppercase
72+ return compareInfo . Compare ( x , y , CompareOptions . None ) ;
73+ } ) ;
6774 }
6875
6976 public Task ConnectionOpenedAsync ( DbConnection connection ,
@@ -127,7 +134,14 @@ private void SetupCollation(SqliteConnection connection, WritingSystem writingSy
127134 //todo use custom comparison based on the writing system
128135 CreateSpanCollation ( connection , SqlSortingExtensions . CollationName ( writingSystem . WsId ) ,
129136 compareInfo ,
130- static ( compareInfo , x , y ) => compareInfo . Compare ( x , y , CompareOptions . IgnoreCase ) ) ;
137+ static ( compareInfo , x , y ) =>
138+ {
139+ var caseInsensitiveResult = compareInfo . Compare ( x , y , CompareOptions . IgnoreCase ) ;
140+ if ( caseInsensitiveResult != 0 )
141+ return caseInsensitiveResult ;
142+ // When case-insensitively equal, sort lowercase before uppercase
143+ return compareInfo . Compare ( x , y , CompareOptions . None ) ;
144+ } ) ;
131145 }
132146
133147 //this is a premature optimization, but it avoids creating strings for each comparison and instead uses spans which avoids allocations
0 commit comments