本文整理汇总了C#中SQLiteConnection.CreateCollation方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.CreateCollation方法的具体用法?C# SQLiteConnection.CreateCollation怎么用?C# SQLiteConnection.CreateCollation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLiteConnection
的用法示例。
在下文中一共展示了SQLiteConnection.CreateCollation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCollation
public void TestCollation()
{
var numRecords = this.rnd.Next(1, 11);
var insertedRecords = new List<Tuple<int, string>>(numRecords);
var queriedRecords = new List<Tuple<int, string>>(numRecords);
var queriedRecordsReverse = new List<Tuple<int, string>>(numRecords);
for (var i = 0; i < numRecords; i++)
{
insertedRecords.Add(new Tuple<int, string>(i, this.GetRandomString()));
}
using (var connection = new SQLiteConnection(this.databaseRelativePath))
{
connection.CreateCollation(
"CUSTOMCOLL",
new Collation((first, second) =>
{
return string.Compare(first, second);
}));
connection.CreateCollation(
"CUSTOMCOLLREVERSE",
new Collation((first, second) =>
{
return string.Compare(second, first);
}));
using (var statement = connection.Prepare("DROP TABLE IF EXISTS TestCollation;"))
{
statement.Step();
}
using (var statement = connection.Prepare("CREATE TABLE TestCollation(id INTEGER, t TEXT);"))
{
statement.Step();
}
foreach (var record in insertedRecords)
{
var command = "INSERT INTO TestCollation(id, t) VALUES(" + record.Item1.ToString(this.invClt) + ",'" + record.Item2 + "');";
using (var statement = connection.Prepare(command))
{
statement.Step();
}
}
using (var statement = connection.Prepare("SELECT id, t FROM TestCollation ORDER BY t COLLATE CUSTOMCOLL, id;"))
{
while (statement.Step() == SQLiteResult.ROW)
{
var id = (long)statement[0];
var t = (string)statement[1];
queriedRecords.Add(new Tuple<int, string>((int)id, t));
}
}
using (var statement = connection.Prepare("SELECT id, t FROM TestCollation ORDER BY t COLLATE CUSTOMCOLLREVERSE, id;"))
{
while (statement.Step() == SQLiteResult.ROW)
{
var id = (long)statement[0];
var t = (string)statement[1];
queriedRecordsReverse.Add(new Tuple<int, string>((int)id, t));
}
}
using (var statement = connection.Prepare("DROP TABLE TestCollation;"))
{
statement.Step();
}
}
Assert.AreEqual(insertedRecords.Count, queriedRecords.Count);
Assert.AreEqual(insertedRecords.Count, queriedRecordsReverse.Count);
insertedRecords.Sort((x, y) => { return string.Compare(x.Item2, y.Item2) != 0 ? string.Compare(x.Item2, y.Item2) : x.Item1 - y.Item1; });
for (var i = 0; i < insertedRecords.Count; i++)
{
var insertedRecord = insertedRecords[i];
var queriedRecord = queriedRecords[i];
Assert.AreEqual(insertedRecord.Item1, queriedRecord.Item1);
Assert.AreEqual(insertedRecord.Item2, queriedRecord.Item2);
}
insertedRecords.Sort((x, y) => { return string.Compare(y.Item2, x.Item2) != 0 ? string.Compare(y.Item2, x.Item2) : x.Item1 - y.Item1; });
for (var i = 0; i < insertedRecords.Count; i++)
{
var insertedRecord = insertedRecords[i];
var queriedRecord = queriedRecordsReverse[i];
Assert.AreEqual(insertedRecord.Item1, queriedRecord.Item1);
Assert.AreEqual(insertedRecord.Item2, queriedRecord.Item2);
//.........这里部分代码省略.........