Click here to Skip to main content
15,894,405 members
Articles / Mobile Apps / Windows Mobile

Case-Insensitive Sort of UTF8 Data Using System.Data.SQLite

Rate me:
Please Sign up or sign in to vote.
4.92/5 (20 votes)
22 Nov 2009CPOL4 min read 77.8K   821   28  
SQLite lacks case-insensitive sort of UTF8 data. In this article, you will see how to get rid of this limitation in .NET.
using System.Data.SQLite;
using System.Globalization;

namespace SQLiteUTF8CIComparison {
    /// <summary>
    /// This function adds case-insensitive sort feature to SQLite engine 
    /// To initialize, use SQLiteFunction.RegisterFunction() before all connections are open 
    /// </summary>
    [SQLiteFunction(FuncType = FunctionType.Collation, Name = "UTF8CI")]
    public class SQLiteCaseInsensitiveCollation : SQLiteFunction {
        /// <summary>
        /// CultureInfo for comparing strings in case insensitive manner 
        /// </summary>
        private static readonly CultureInfo _cultureInfo = CultureInfo.CreateSpecificCulture("ru-RU");

        /// <summary>
        /// Does case-insensitive comparison using _cultureInfo 
        /// </summary>
        /// <param name="x">Left string</param>
        /// <param name="y">Right string</param>
        /// <returns>The result of a comparison</returns>
        public override int Compare(string x, string y) {
            return string.Compare(x, y, _cultureInfo, CompareOptions.IgnoreCase);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions