@@ -17,6 +17,7 @@ package sql
1717import (
1818 "fmt"
1919 "io"
20+ "strings"
2021 "unicode/utf8"
2122
2223 "github.com/cespare/xxhash"
@@ -33,9 +34,16 @@ type Collation struct {
3334 IsCompiled bool
3435 SortLength uint8
3536 PadAttribute string
36- Sorter func ( r rune ) int32
37+ Sorter CollationSorter
3738}
3839
40+ // CollationSorter is a collation's sort function. When given a rune, an integer is returned that represents that rune's
41+ // order when sorted against all other runes. That integer is referred to as a sort order. When two runes have the same
42+ // sort order, they are considered equivalent. For example, case-insensitive collations return the same sort order for
43+ // uppercase and lowercase variants of a character, while case-sensitive collations return different sort orders.
44+ // Comparing sort orders from different collations is meaningless, and therefore represents a logical error.
45+ type CollationSorter func (r rune ) int32
46+
3947// CollationsIterator iterates over every collation available, ordered by their ID (ascending).
4048type CollationsIterator struct {
4149 idx int
@@ -758,7 +766,7 @@ func ParseCollation(characterSetStr *string, collationStr *string, binaryAttribu
758766 if collationStr == nil || len (* collationStr ) == 0 {
759767 return Collation_Unspecified , nil
760768 }
761- if collation , ok := collationStringToID [* collationStr ]; ok {
769+ if collation , ok := collationStringToID [strings . ToLower ( * collationStr ) ]; ok {
762770 if binaryAttribute {
763771 return collation .CharacterSet ().BinaryCollation (), nil
764772 }
@@ -776,7 +784,7 @@ func ParseCollation(characterSetStr *string, collationStr *string, binaryAttribu
776784 }
777785 return characterSet .DefaultCollation (), nil
778786 }
779- collation , exists := collationStringToID [* collationStr ]
787+ collation , exists := collationStringToID [strings . ToLower ( * collationStr ) ]
780788 if ! exists {
781789 return Collation_Unspecified , ErrCollationUnknown .New (* collationStr )
782790 }
@@ -911,7 +919,7 @@ func (c CollationID) HashToBytes(str string) ([]byte, error) {
911919
912920// Sorter returns this collation's sort function. As collations are a work-in-progress, it is recommended to avoid
913921// using any collations that return a nil sort function.
914- func (c CollationID ) Sorter () func ( r rune ) int32 {
922+ func (c CollationID ) Sorter () CollationSorter {
915923 return collationArray [c ].Sorter
916924}
917925
0 commit comments