Read/Write to SQLLite via .NET - Solved

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

Read/Write to SQLLite via .NET - Solved

Postby Guest » Sat May 10, 2008 9:35 am

OK, so apparently there have been some people wanting to have read/write database access to the new mediamonkey database format, only to be met with some frustrating IUNICODE collation errors.

I did a little digging, and turned up the following links regarding this subject.

Python script for defining a collation sequence:
http://www.mediamonkey.com/forum/viewtopic.php?p=127635#127635

and another snippet for defining a collation sequence in C#
http://sqlite.phxsoftware.com/forums/p/207/757.aspx#757

so, I took the concepts in those articles to see if I could apply them using the ADO.NET 2.0 Provider for SQLite found here:

http://sourceforge.net/project/showfiles.php?group_id=132486&package_id=145568&release_id=564661

When I tried using the .NET provider out of the box in a project, it gave me the same IUNICODE issue as has been reported here in the past, until I added the following class to the project (in C#):

Code: Select all
    [SQLiteFunction(Name = "IUNICODE", FuncType = FunctionType.Collation)]
    class IUNICODE : SQLiteFunction
    {

        public override int Compare(string param1, string param2)
        {
            return String.Compare(param1, param2, true);
        }

    }


Voila! it worked. Apparently the attributes on the function are enough to tell SqlLite how to find the function without any other code settings.

I'll try to post a solution file that illustrates this usage when I get a chance to clean it up.

Enjoy!
Guest
 

Postby taschell » Sat May 10, 2008 9:40 am

OK, immediately after posting that, I realized I wasn't logged in. :o

In any case, is there any way/where I can post that solution file as an example of usage here on the forum?

Thanks!
taschell
 
Posts: 1
Joined: Sat May 10, 2008 9:12 am

Postby nohitter151 » Sat May 10, 2008 6:33 pm

taschell wrote:OK, immediately after posting that, I realized I wasn't logged in. :o

In any case, is there any way/where I can post that solution file as an example of usage here on the forum?

Thanks!


Not on the forum, but you could probably upload it to the wiki and create a new page explaining everything:

http://www.mediamonkey.com/wiki
MediaMonkey user since 2006
Need help? Got a suggestion? Can't find something?
nohitter151
 
Posts: 21464
Joined: Wed Aug 09, 2006 10:20 am
Location: NJ, USA

Re: Read/Write to SQLLite via .NET - Solved

Postby MMuser2011 » Tue May 22, 2012 7:16 am

Maybe this code snippet could help if you need the above for VB.NET (tested in 2010 Express).
Add a new class to your VB.NET project with the following content:
Code: Select all
Imports System.Data.SQLite

<SQLiteFunction(Name:="iUNICODE", FuncType:=FunctionType.Collation)> _
Class iUNICODE
    Inherits SQLiteFunction

    Public Overrides Function Compare(param1 As String, param2 As String) As Integer
        Return [String].Compare(param1, param2, True)
    End Function

End Class

You have to add the following line in the beginning of your application:
Code: Select all
SQLiteFunction.RegisterFunction(GetType(iUNICODE))



JFYI:
If you use SQL-Queries with the suffix-workaround COLLATE NOCASE you will find the following problem:
"Loredana Bertè" <> "LOREDANA BERTÈ"
Even if you compare the uppercased values with something like
...WHERE UPPER(artist) = '" & lsArtistName.ToUpper & "' COLLATE NOCASE"
you don't get the needed result!! :oops:


All the credits and a BIG 'thank you' to taschell!!
Magic Nodes v4.2 (2011-07-01) Album Art Tagger v4.9 (2011-02-27)
ExternalTools v1.4 (2011-05-09) MusicBrainz NGS + AcoustId Tagger v1.25 (2012-01-29)
Calculate Cover Size v1.5 (2010-05-03) RegExp Find & Replace v4.3 (2011-07-06)
MMuser2011
 
Posts: 525
Joined: Mon Oct 17, 2011 8:28 am
Location: Central Europe


Return to Need Help with Addons?

Who is online

Users browsing this forum: No registered users and 7 guests