sqlite türkçe harf sıralaması, sqlite turkish collation

sqlite türkçe harf sıralaması, sqlite turkish collation

10. January 2010

Read this article in your language IT | EN | DE | ES

Kullandığım projelerde ACCESS yerine SQLite kullanmayı uzun zamandır düşünüyordum. Fakat SQLite altında sorgu yaptığımda harfleri Türkçe sıralayamıyordu.

Bu sorunu çözmek için önce SQLite ve ICU bileşenlerini kendim derlemeyi denedim. Fakat C bilgim olmadığı için bu konuda başarılı olamadım.

Ardından yılmadım ve denemelerime devam ettim.

En sonunda bu adresteki kodu kullanarak sorunumu çözebildim.

Öncelikle Bir class oluşturuyoruz ve bu Class başlığına şı satırlaır ekliyoruz:

using System.Data.SQLite;
using System.Globalization;

Ardından Class ın kod alanına bu satırları ekliyoruz:

namespace SQLiteUTF8CIComparison
{
    ///
    /// This function adds case-insensitive sort feature to SQLite engine
    /// To initialize, use SQLiteFunction.RegisterFunction() before all connections are open
    ///
    [SQLiteFunction(FuncType = FunctionType.Collation, Name = "UTF8CI")]
    public class SQLiteCaseInsensitiveCollation : SQLiteFunction
    {
        ///
        /// CultureInfo for comparing strings in case insensitive manner
        ///
        private static readonly CultureInfo _cultureInfo = CultureInfo.CreateSpecificCulture("tr-TR");
        ///
        /// Does case-insensitive comparison using _cultureInfo
        ///
        /// Left string
        /// Right string
        /// The result of a comparison
        public override int Compare(string x, string y)
        {
            return string.Compare(x, y, _cultureInfo, CompareOptions.IgnoreCase);
        }
    }
}

Şimdi bu fonksiyonu kullanabilmemiz için programın başlangıcına şu satırları ekliyoruz:

Header kısmına :

using System.Data.SQLite;
using SQLiteUTF8CIComparison;

 Form Load Event'ına:

SQLiteFunction.RegisterFunction(typeof(SQLiteCaseInsensitiveCollation));

Eğer tabloları herhangi bir SQLite Yönetim programıyla oluşturduysanız Türkçe sıralama yine çalışmayacaktır.

Tabloları kendimiz program içinde oluşturmalıyız. SQL konusunda iyi değilseniz SQLite yönetim programlarını herhangi biriyle oluşturduğunuz tabloyu EXPORT ederek SQL kodlarını elde edebilirsiniz. 

Burada sıralama yapacağınız (ORDER BY) FIELD'ların oluşturma koduna COLLATE UTF8CI kelimelerini ekliyoruz:

CREATE TABLE `tablom` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
`adi` TEXT NULL COLLATE UTF8CI,
`soyadi` TEXT)

 Bundan sonra yapacağınız insert ve select sorgularında sıralama Türkçe oalcaktır.

Eğer 

No such collation: UTF8CI

şeklinde hata alırsanız select sorgusunun sonuna COLLATE BINARY kelimelerini ekleyin :

select * from tablom order by adi COLLATE BINARY

İyi kodlamalar.

Kaynak   : http://www.egeonline.com/index.php/yazilimgelistirme/c/179-sqlite-tuerkce-harf-sralamas-sqlite-turkish-collation.html

Bu Güzel Makkale için Teşekkürler İlyas Bey 

FacebookDigg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

SQLite ,

Comments

4/7/2010 12:13:42 AM #
Stumbled into this site by chance but I’m sure glad I clicked on that link. You definitely answered all the questions I’ve been dying to answer for some time now.  Will definitely come back for more of this. Thank you so much
4/7/2010 5:40:34 PM #
4/18/2010 10:05:45 PM #
Thank you in advance for your rapid reply !. Really nice article.
4/21/2010 11:52:11 AM #
reclama pe net - advertise on the internet
4/24/2010 12:39:07 PM #
I wanted to say that it's nice to know that someone else also mentioned this as I had trouble finding the same info elsewhere. This was the first place that told me the answer. Thanks.
5/6/2010 1:20:24 AM #
Mini-Forex Brokers allow investors to open their forex accounts by putting down a comparatively smaller down payment. The minimum requirement for actual forex trading is $100,000. Mini forex brokers may accept contracts as small as $10,000. Also, the margin in real forex trading is 1%, where as mini accounts may operate at around 0.5%. Many mini forex accounts can be opened with a deposit as low as $100.
5/7/2010 5:24:57 AM #
thanx sqlite
5/17/2010 12:50:50 AM #
This was the first place that told me the answer. Thanks.
5/29/2010 10:58:29 AM #
Hi
I think you're on to something about your post sqlite türkçe harf siralamasi, sqlite turkish collation. I will definitely be reading your website more.
Bye
Red Dead Redemption How to Duel

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Sayfa 0.03125 saniyede yuklendi.