Here's an example skeleton for a custom collation.  (Using UTF8
encoding, change the declarations as necessary.)

        // declarations
        typedef int SQLiteCompare_t (void *, int, const void *, int,
const void *);

        int MyCompare(void *userData, int str1Len, const UTF8 *str1, int
str2Len, const UTF8 *str2)
        {
                // whatever you want here, return < 0 if str1 < str2, 0
if equal, etc.
        } 


        // connecting the function
        int err = sqlite3_create_collation(db, "MyCompare", SQLITE_UTF8,
NULL, (SQLiteCompare_t *)&MyCompare);
        if (err != SQLITE_OK)
        {
                // do something to handle the err -- probably fix your
code, this should work
        }


To use, 'CREATE TABLE foo(bar TEXT COLLATE MyCompare);'

Now you're set -- of course keep in mind that if you open the DB with a
different sqlite (e.g. the command line tool or a GUI browser), the
custom collation sequence won't be available.  Sqlite is fairly robust,
it won't blow up and you can still do pretty much anything with the DB
that doesn't directly call the custom function, e.g. don't try to sort
by the "bar" column or use an index built on that column.

                                                        --Bob

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Mahalakshmi.m
Sent: Monday, May 12, 2008 7:21 AM
To: Sqlite User
Subject: [sqlite] Is this Sorting order right?


Mahalakshmi wrote 
> What about Japanese Kanji?
> Will sqlite sort all the Hiragana,Katakana,Kanji.

Igor Tandetnik wrote

>> Not out of the box. You will have to implement a custom collation. 
>> Or, you can build SQLite with ICU support, then it >> will use ICU 
>> collation functions.

Thanks a lot.
But I didn't get the point.
Do I want to write my own string comparison code and use that as Custom
Collation .If so where can I find the examples.(or) I can use just
sqlite3_create_function( *gpst_SqliteInstance, "shellstatic", 0,
SQLITE_UTF16, 0, shellstaticFunc, 0, 0); My database has UTF16 encoding.

Even if the collation is UTF8, Sqlite will do memcmp() say 1st record
has the Unicode 6B4C and 2nd records has 30A2.If sqlite is comparing
byte by byte means then 30A2 only has to come as first record.Is it
right? But I am not getting.

Please help to clarify this.

Thanks & Regards,
Mahalakshmi

                        




_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to