private static void DrFillSongVerseObj(OleDbDataReader dr, MigrationSongVerse vo) { vo.autoNumber = dr.GetInt32(0); vo.orderNumber = dr.GetInt32(1); vo.isChorus = dr.GetBoolean(2); vo.verse = dr.GetString(3); }
public bool Compare(MigrationSongVerse v1, MigrationSongVerse v2) { return(v1.autoNumber == v2.autoNumber && v1.orderNumber == v2.orderNumber && v1.isChorus == v2.isChorus && v1.verse == v2.verse); }
private bool GetDifSongVerses(string oldRoot, Dictionary <string, MigrationSongVerse> mVerses) { // Approach: // - open two database connection and send identical sorted queries // - add each result to the list // - if two results have no changes then drop them from the list // - if there are changes mark what kind // - after queries are finished execute add / update queries using (FBirdTask told = new FBirdTask()) using (FBirdTask tnew = new FBirdTask()) { // Set old connection string string path2olddb = Path.Combine(oldRoot, "bibdata.fdb"); string oldConstring = "ServerType=1;Database=" + path2olddb + ";User=SYSDBA;Password=masterkey;Charset=WIN1251"; told.Connection = new FbConnection(oldConstring); string fbQuery = "SELECT " + "\"SongVerses\".\"AutoNumber\", " + "\"SongVerses\".\"OrderNum\", " + "\"SongVerses\".\"IsChorus\", " + "\"SongVerses\".\"Verse\" " + "FROM " + "\"SongVerses\" " + "ORDER BY " + "\"SongVerses\".\"AutoNumber\", " + "\"SongVerses\".\"OrderNum\""; string jtQuery = "SELECT " + "[SongVerses].[AutoNumber], " + "[SongVerses].[OrderNum], " + "[SongVerses].[IsChorus], " + "[SongVerses].[Verse] " + "FROM " + "[SongVerses] " + "ORDER BY " + "[SongVerses].[AutoNumber], " + "[SongVerses].[OrderNum]"; told.CommandText = fbQuery; tnew.CommandText = jtQuery; told.ExecuteReader(); tnew.ExecuteReader(); if (told.DR == null || tnew.DR == null) { this.TopMost = false; MessageBox.Show(this, "Migration failed to migrate song data", "Error"); return(false); } bool oldAvailable = true; bool newAvailable = true; while (oldAvailable || newAvailable) { oldAvailable = told.DR.Read(); newAvailable = tnew.DR.Read(); // Old data if (oldAvailable) { MigrationSongVerse vo = new MigrationSongVerse(); DrFillSongVerseObj(told.DR, vo); vo.foundInOld = true; string id = vo.GetId(); if (mVerses.ContainsKey(id)) { MigrationSongVerse v2 = mVerses[id]; v2.foundInOld = true; // Drop if the two are the same if (v2.Compare(vo, v2)) { mVerses.Remove(id); } } else { mVerses[id] = vo; } } // New data if (newAvailable) { MigrationSongVerse vn = new MigrationSongVerse(); DrFillSongVerseObj(tnew.DR, vn); vn.foundInNew = true; string id = vn.GetId(); if (mVerses.ContainsKey(id)) { MigrationSongVerse v2 = mVerses[id]; v2.foundInNew = true; // Drop if the two are the same if (v2.Compare(vn, v2)) { mVerses.Remove(id); } } else { mVerses[id] = vn; } } } } return(true); }