by urbandive » Sat Nov 07, 2009 4:33 am
Hi folks,
I have been working on my music genres and it was a bit of a headache to do it manually in MM because I had thousands of them. So I decided to get them, sort / clean in Excel and then flag the genres that I needed to delete.
I can manage C#, so I downloaded SQLLite, but encountered this issue with IUNICODE collation, and was very disappointed at not being able to transfer my changes to MediaMonkey after so much work.
Luckily, by surfing the web, I managed to put together this piece of code which worked wonderfully. Thought I'd share it around in case someone else needs it :
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SQL=System.Data.SQLite;
namespace MediaMonkeyDB
{
class Program
{
static void Main(string[] args)
{
List<Int32> listIDGenresToDelete = new List<int> { 17, 67, 214, ...};
SQL.SQLiteConnection cn = new System.Data.SQLite.SQLiteConnection(@"data source=C:\Temp\MediaMonkey\MM.DB");
cn.Open();
SQL.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand(cn);
try
{
foreach (Int32 IDGenre in listIDGenresToDelete)
{
cmd.CommandText = string.Format("DELETE FROM [GenresSongs] WHERE [IDGenre] = {0};", IDGenre);
cmd.ExecuteNonQuery();
}
Console.WriteLine("Finished");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Console.ReadLine();
}
}
/// <summary>
/// User-defined collating sequence.
/// </summary>
[SQL.SQLiteFunction(Name = "IUNICODE", FuncType = SQL.FunctionType.Collation)]
class IUNICODE : SQL.SQLiteFunction
{
public override int Compare(string param1, string param2)
{
return String.Compare(param1.ToLower(), param2.ToLower(), true);
}
}
}
}
Hi folks,
I have been working on my music genres and it was a bit of a headache to do it manually in MM because I had thousands of them. So I decided to get them, sort / clean in Excel and then flag the genres that I needed to delete.
I can manage C#, so I downloaded SQLLite, but encountered this issue with IUNICODE collation, and was very disappointed at not being able to transfer my changes to MediaMonkey after so much work.
Luckily, by surfing the web, I managed to put together this piece of code which worked wonderfully. Thought I'd share it around in case someone else needs it :
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SQL=System.Data.SQLite;
namespace MediaMonkeyDB
{
class Program
{
static void Main(string[] args)
{
List<Int32> listIDGenresToDelete = new List<int> { 17, 67, 214, ...};
SQL.SQLiteConnection cn = new System.Data.SQLite.SQLiteConnection(@"data source=C:\Temp\MediaMonkey\MM.DB");
cn.Open();
SQL.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand(cn);
try
{
foreach (Int32 IDGenre in listIDGenresToDelete)
{
cmd.CommandText = string.Format("DELETE FROM [GenresSongs] WHERE [IDGenre] = {0};", IDGenre);
cmd.ExecuteNonQuery();
}
Console.WriteLine("Finished");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Console.ReadLine();
}
}
/// <summary>
/// User-defined collating sequence.
/// </summary>
[SQL.SQLiteFunction(Name = "IUNICODE", FuncType = SQL.FunctionType.Collation)]
class IUNICODE : SQL.SQLiteFunction
{
public override int Compare(string param1, string param2)
{
return String.Compare(param1.ToLower(), param2.ToLower(), true);
}
}
}
}
[/code]