Thanks Dan. Replacing “Compare” with L”Compare” and casting to wchar_t* inside the function solved the problem.
Thanks for all the replies. From: Dan Kennedy<mailto:danielk1...@gmail.com> Sent: 02 February 2017 08:42 To: sqlite-users@mailinglists.sqlite.org<mailto:sqlite-users@mailinglists.sqlite.org> Subject: Re: [sqlite] Help with custom collation On 02/02/2017 02:08 AM, x wrote: > Thanks Clemens. You’re right about changing the UTF8String* to char* as it > now works but when trying it with a column containing Unicode characters it > didn’t. I’d have liked to have tried it with windows wchar_t* type but If I > try using > > > > if (sqlite3_create_collation16(SQLiteDB, "Compare", SQLITE_UTF16, > NULL, &Compare) != SQLITE_OK) > > throw Exception("Collation creation error"); > > > > I get the message “no such collation sequence: Compare” when running the > query. The second argument passed to sqlite3_create_collation16() should point to a buffer containing a utf-16 string. Not utf-8. Dan. > > > > > > > > From: Clemens Ladisch<mailto:clem...@ladisch.de> > Sent: 01 February 2017 17:32 > To: > sqlite-users@mailinglists.sqlite.org<mailto:sqlite-users@mailinglists.sqlite.org> > Subject: Re: [sqlite] Help with custom collation > > > > x wrote: >> int Compare(void* Data, int Len1, const void *s1, int Len2, const void *s2) >> { >> const UTF8String *S1 = static_cast<const UTF8String*>(s1), >> *S2 = static_cast<const UTF8String*>(s2); >> return 0; >> } >> >> if (sqlite3_create_collation(SQLiteDB, "Compare", SQLITE_UTF8, >> NULL, &Compare) != SQLITE_OK) >> throw Exception("Collation creation error"); >> >> S1 and S2 appear to point to NULL values. > What is "UTF8String"? If it is anything different from "char", the code is > wrong. > >> If I change the select to ‘select ID from IDTbl order by ID collate Compare’ >> the Compare function is never entered. >> Is this because ID is an integer column? > No, it is because the values in that column are integer values. > >> Is there no way to implement a custom collation on an integer column? > There is no way to implement a custom collation for integer values. > Collations are used only for string values. > > > Regards, > Clemens > _______________________________________________ > sqlite-users mailing list > sqlite-users@mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ > sqlite-users mailing list > sqlite-users@mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users