0
某些德語單詞包含「ß」字符。SQLite德語特殊字符
但是,有時候人們會寫「ss」,反之亦然。 雖然不完全合法,但這是一種常見做法。
例如,一些人例如寫「außer」,有些人寫「ausser」。
我想在我的SQLite數據庫中處理這很好。
所以我創建了一個自定義的LATIN_NOCASE整理,但預計它不工作:
我已經插入一個名爲「außer」字,我想能夠找到它,當我搜索「 s「或」ss「。
但是,我的選擇沒有返回結果。
有人看到我出錯了嗎? 下面的比較是否足夠或我需要做一些額外的特殊?
謝謝。
Imports System.Data.SQLite
Imports System.Globalization
<SQLiteFunction(FuncType:=FunctionType.Collation, Name:="LATIN_NOCASE")> _
Public Class SQLiteCaseInsensitiveCollation
Inherits SQLiteFunction
Private Shared ReadOnly _cultureInfo As CultureInfo = CultureInfo.CreateSpecificCulture("de-DE")
Public Overrides Function Compare(x As String, y As String) As Integer
Return String.Compare(x, y, _cultureInfo, CompareOptions.IgnoreCase)
End Function
End Class
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
SQLiteFunction.RegisterFunction(GetType(SQLiteCaseInsensitiveCollation))
Dim c As New SQLite.SQLiteConnection("Data source=:memory:")
c.Open()
Using nCmd As SQLite.SQLiteCommand = c.CreateCommand
With nCmd
.CommandText = "CREATE TABLE foo (word TEXT COLLATE LATIN_NOCASE)"
.ExecuteNonQuery()
End With
End Using
Using nCmd As SQLite.SQLiteCommand = c.CreateCommand
With nCmd
.CommandText = "CREATE INDEX 'idx_foo_word' ON 'foo' (word COLLATE LATIN_NOCASE)"
.ExecuteNonQuery()
End With
End Using
Using nCmd As SQLite.SQLiteCommand = c.CreateCommand
With nCmd
.CommandText = "INSERT INTO foo (word) VALUES ('außer')"
.ExecuteNonQuery()
End With
End Using
Using nCmdSel As SQLite.SQLiteCommand = c.CreateCommand
With nCmdSel
.CommandText = "SELECT * FROM foo WHERE word LIKE '%ss%' COLLATE LATIN_NOCASE"
Using r As SQLite.SQLiteDataReader = .ExecuteReader
Do While r.Read
MsgBox(r("word"))
Loop
End Using
End With
End Using
End Sub
End Class
我不確定SQLite是否支持/使用LIKE表達式的排序規則。可能想檢查一下。 - 而且,在一般情況下,「ß」無論如何都不會被轉換成德文的「s」。 – JimmyB