Index: MusicDatabase.cs
===================================================================
--- MusicDatabase.cs	(revision 25928)
+++ MusicDatabase.cs	(working copy)
@@ -112,7 +112,7 @@
       {
         if (MusicDbClient == null)
         {
-          MusicDbClient = new SQLiteClient(Config.GetFile(Config.Dir.Database, "MusicDatabaseV11.db3"));
+          MusicDbClient = new SQLiteClient(Config.GetFile(Config.Dir.Database, "MusicDatabaseV12.db3"));
         }
 
         return MusicDbClient;
@@ -174,21 +174,34 @@
         }
         catch (Exception) { }
 
-        if (!File.Exists(Config.GetFile(Config.Dir.Database, "MusicDatabaseV11.db3")))
+        if (!File.Exists(Config.GetFile(Config.Dir.Database, "MusicDatabaseV12.db3")))
         {
           if (File.Exists(Config.GetFile(Config.Dir.Database, "MusicDatabaseV10.db3")))
           {
             Log.Info("MusicDatabase: Found older version of database. Upgrade to new layout.");
             File.Copy(Config.GetFile(Config.Dir.Database, "MusicDatabaseV10.db3"),
-                      Config.GetFile(Config.Dir.Database, "MusicDatabaseV11.db3"));
+                      Config.GetFile(Config.Dir.Database, "MusicDatabaseV12.db3"));
 
             // Get the DB handle or create it if necessary
             MusicDbClient = DbConnection;
 
-            UpgradeDBV10_V11();
+            UpgradeDBV10_OR_V11_TO_V12();
             return;
           }
+          if (File.Exists(Config.GetFile(Config.Dir.Database, "MusicDatabaseV11.db3")))
+          {
+            Log.Info("MusicDatabase: Found older version of database. Upgrade to new layout.");
+            File.Copy(Config.GetFile(Config.Dir.Database, "MusicDatabaseV11.db3"),
+                      Config.GetFile(Config.Dir.Database, "MusicDatabaseV12.db3"));
 
+            // Get the DB handle or create it if necessary
+            MusicDbClient = DbConnection;
+
+            UpgradeDBV10_OR_V11_TO_V12();
+            return;
+          }
+          
+
           // Get the DB handle or create it if necessary
           MusicDbClient = DbConnection;
 
@@ -213,13 +226,23 @@
       Log.Info("MusicDatabase: Database opened");
     }
 
-    private void UpgradeDBV10_V11()
+    private void UpgradeDBV10_OR_V11_TO_V12()
     {
       try
       {
         // First rename the tracks table
-        string strSQL = "alter table tracks rename to tracksV10";
+        string strSQL = "alter table tracks rename to tracks_existing";
         MusicDbClient.Execute(strSQL);
+        
+        //remove incorrectly name index in V11 database
+        //should be called idxcomposertable_strComposer
+        //and will get re-created by CreateDatabase
+        try
+        {
+          strSQL = "DROP INDEX idxcomposerable_strComposer";
+          MusicDbClient.Execute(strSQL);
+        }
+        catch{}
 
         // Now call the Create Datbase function to create the new table
         if (!CreateDatabase())
@@ -232,12 +255,16 @@
         strSQL =
           "insert into tracks select idTrack, strPath, strArtist, strAlbumArtist, strAlbum, strGenre, '|  |', '', " +
           "strTitle, iTRack, iNumTracks, iDuration, iYear, iTimesPlayed, iRating, iFavorite, iResumeAt, iDisc, iNumDisc, " +
-          "strLyrics, dateLastPlayed, dateAdded from tracksV10";
+          "strLyrics, dateLastPlayed, dateAdded from tracks_existing";
 
         MusicDbClient.Execute(strSQL);
 
-        strSQL = "drop table tracksV10";
+        strSQL = "drop table tracks_existing";
         MusicDbClient.Execute(strSQL);
+        
+        Log.Debug("MusicDatabase: Compacting");
+        //above transaction makes database large so now compact
+        DatabaseUtility.CompactDatabase(MusicDbClient);
 
         Log.Info("MusicDatabase: Finished upgrading database.");
       }
@@ -278,13 +305,6 @@
           ")"
           );
 
-        // Add a Trigger for inserting the Date into the song table, whenever we do an update
-        string strSQL = "CREATE TRIGGER IF NOT EXISTS insert_song_timeStamp AFTER INSERT ON tracks " +
-                        "BEGIN " +
-                        " UPDATE tracks SET dateAdded = DATETIME('NOW') " +
-                        " WHERE rowid = new.rowid; " +
-                        "END;";
-        MusicDbClient.Execute(strSQL);
 
         // Indices for Tracks table
         DatabaseUtility.AddIndex(MusicDbClient, "idxpath_strPath", "CREATE INDEX idxpath_strPath ON tracks(strPath ASC)");
@@ -324,7 +344,7 @@
         DatabaseUtility.AddTable(MusicDbClient, "composer",
                                  "CREATE TABLE composer ( idComposer integer primary key autoincrement, strComposer text)");
         DatabaseUtility.AddIndex(MusicDbClient, "idxcomposertable_strComposer",
-                                 "CREATE INDEX idxcomposerable_strComposer ON composer(strComposer ASC)");
+                                 "CREATE INDEX idxcomposertable_strComposer ON composer(strComposer ASC)");
 
         // Artist Info and Album Info
         DatabaseUtility.AddTable(MusicDbClient, "albuminfo",
Index: MusicDatabase.Updates.cs
===================================================================
--- MusicDatabase.Updates.cs	(revision 25928)
+++ MusicDatabase.Updates.cs	(working copy)
@@ -1088,6 +1088,7 @@
       MusicTag tag = GetTag(strFileName);
       if (tag != null)
       {
+        DateTime createdDate = File.GetCreationTimeUtc(strFileName);
         DatabaseUtility.RemoveInvalidChars(ref strFileName);
 
         strSQL =
@@ -1095,14 +1096,14 @@
             @"insert into tracks (
                                strPath, strArtist, strAlbumArtist, strAlbum, strGenre, strComposer, strConductor, strTitle, 
                                iTrack, iNumTracks, iDuration, iYear, iTimesPlayed, iRating, iFavorite, 
-                               iResumeAt, iDisc, iNumDisc, strLyrics, dateLastPlayed) 
+                               iResumeAt, iDisc, iNumDisc, strLyrics, dateLastPlayed, dateAdded) 
                                values ( 
                                '{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}',
                                {8}, {9}, {10}, {11}, {12}, {13}, {14}, 
-                               {15}, {16}, {17}, '{18}', '{19}' )",
+                               {15}, {16}, {17}, '{18}', '{19}', '{20}' )",
             strFileName, tag.Artist, tag.AlbumArtist, tag.Album, tag.Genre, tag.Composer, tag.Conductor, tag.Title,
             tag.Track, tag.TrackTotal, tag.Duration, tag.Year, 0, tag.Rating, 0,
-            0, tag.DiscID, tag.DiscTotal, tag.Lyrics, DateTime.MinValue
+            0, tag.DiscID, tag.DiscTotal, tag.Lyrics, DateTime.MinValue, createdDate
             );
         try
         {
@@ -1178,6 +1179,7 @@
         MusicTag tag = GetTag(strFileName);
         if (tag != null)
         {
+          DateTime createdDate = File.GetCreationTimeUtc(strFileName);
           DatabaseUtility.RemoveInvalidChars(ref strFileName);
 
           strSQL =
@@ -1186,13 +1188,13 @@
                                  set strArtist = '{0}', strAlbumArtist = '{1}', strAlbum = '{2}', 
                                  strGenre = '{3}', strTitle = '{4}', iTrack = {5}, iNumTracks = {6}, 
                                  iDuration = {7}, iYear = {8}, iRating = {9}, iDisc = {10}, iNumDisc = {11}, 
-                                 strLyrics = '{12}', strComposer = '{13}', strConductor = '{14}' 
+                                 strLyrics = '{12}', strComposer = '{13}', strConductor = '{14}', dateAdded = '{16}'
                                  where strPath = '{15}'",
               tag.Artist, tag.AlbumArtist, tag.Album,
               tag.Genre, tag.Title, tag.Track, tag.TrackTotal,
               tag.Duration, tag.Year, tag.Rating, tag.DiscID, tag.DiscTotal,
               tag.Lyrics, tag.Composer, tag.Conductor,
-              strFileName
+              strFileName, createdDate
               );
           try
           {
