/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
samples/snippets/standard/data/sqlite/CollationSample/Program.cs
45 строк
1 KB
Genevieve Warren
Fix nullability warnings (samples/snippets/standard) (#35190)
02 май 2023, 00:08
Не верифицирован
02 май 2023, 00:08
1097bb0
Код
Авторство
О чём код?
using System; using Microsoft.Data.Sqlite; namespace CollationSample { class Program { static void Main() { var connection = new SqliteConnection("Data Source=:memory:"); connection.Open(); var createCommand = connection.CreateCommand(); createCommand.CommandText = @" CREATE TABLE greek_letter ( value TEXT ); INSERT INTO greek_letter VALUES ('Λ'), ('λ'); "; createCommand.ExecuteNonQuery(); // Without this, the query returns one since the built-in NOCASE collation only // handles ASCII characters (A-Z) #region snippet_Collation connection.CreateCollation("NOCASE", (x, y) => string.Compare(x, y, ignoreCase: true)); var queryCommand = connection.CreateCommand(); queryCommand.CommandText = @" SELECT count() FROM greek_letter WHERE value = 'λ' COLLATE NOCASE "; var oCount = queryCommand.ExecuteScalar(); var count = (oCount is not null) ? (int)oCount : -1; #endregion Console.WriteLine($"Results: {count}"); } } }