我试图在SQLite for Windows Runtime中实现自定义排序规则。在SQLite中为WinRT实现自定义排序规则
的create_collation方法实现如下:
SQLITE_API int sqlite3_create_collation(
sqlite3*,
const char *zName,
int eTextRep,
void *pArg,
int(*xCompare)(void*,int,const void*,int,const void*)
);
到目前为止,我有下面的C#签名:
[DllImport("sqlite3", EntryPoint = "sqlite3_create_collation", CallingConvention = CallingConvention.Cdecl)]
public static extern int CreateCollation(IntPtr db, [MarshalAs(UnmanagedType.LPStr)] string name, int textRep, object state, Compare callback);
public delegate int Compare(object pCompareArg, int size1, IntPtr Key1, int size2, IntPtr Key2);
这是实现:
int i = CreateCollation(db, "unicode_nocase", SQLITE_UTF8, null, CompareMethod);
/* ... */
public static int CompareMethod(object o, int i1, IntPtr s1, int i2, IntPtr s2)
{
return string.Compare(Marshal.PtrToStringUni(s1), Marshal.PtrToStringUni(s2));
}
应用程序编译没有错误。到create_collation调用返回零(SQLITE_OK),但如果我使用归类在一份声明中返回以下错误信息:
no such collation sequence: unicode_nocase
源参考:https://github.com/doo/SQLite3-WinRT/tree/master/SQLite3Component
有人可以帮我吗?
谢谢!
你应该只能使用'SQLITE_UTF8';这是SQLite字符串的本地格式。 – 2013-03-01 15:15:03
谢谢!我会尝试;) – 2013-05-15 21:26:09
因此,只是为了确认我明白,这种自定义整理会相对较慢,因为实现是C#,从C调用?或者,如果使用C#自定义collator执行表扫描,那么可以期望合理的性能? – hyperspasm 2017-01-03 17:17:29