/// <summary> /// Merge multiple .db files into a single .db file. /// </summary> /// <param name="fileSpec">The file specification for the .db files to merge.</param> /// <param name="recurse">Recursively search for matching .db files in child directories?</param> /// <param name="outFileName">The name of the new output file.</param> public static void MergeFiles(string fileSpec, bool recurse, string outFileName) { File.Delete(outFileName); string[] filesToMerge = DirectoryUtilities.FindFiles(fileSpec, recurse); if (filesToMerge.Length > 1) { File.Copy(filesToMerge[0], outFileName, overwrite: true); var destination = new SQLite(); destination.OpenDatabase(outFileName, readOnly: false); try { foreach (var sourceFileName in filesToMerge.Where(file => file != filesToMerge[0])) { var source = new SQLite(); source.OpenDatabase(sourceFileName, readOnly: true); try { Merge(source, destination); } finally { source.CloseDatabase(); } } } finally { destination.CloseDatabase(); } } }
/// <summary> /// Merge multiple .db files into a single .db file. /// </summary> /// <param name="fileSpec">The file specification for the .db files to merge.</param> /// <param name="recurse">Recursively search for matching .db files in child directories?</param> /// <param name="outFileName">The name of the new output file.</param> public static void MergeFiles(string fileSpec, bool recurse, string outFileName) { File.Delete(outFileName); string[] filesToMerge = DirectoryUtilities.FindFiles(fileSpec, recurse); MergeFiles(filesToMerge, outFileName); }
/// <summary> /// Merge multiple .db files into a single .db file. /// </summary> /// <param name="fileSpec">The file specification for the .db files to merge.</param> /// <param name="recurse">Recursively search for matching .db files in child directories?</param> /// <param name="outFileName">The name of the new output file.</param> public static void MergeFiles(string fileSpec, bool recurse, string outFileName) { File.Delete(outFileName); string[] filesToMerge = DirectoryUtilities.FindFiles(fileSpec, recurse); if (filesToMerge.Length > 1) { File.Copy(filesToMerge[0], outFileName, overwrite: true); var destination = new SQLite(); destination.OpenDatabase(outFileName, readOnly: false); try { foreach (var sourceFileName in filesToMerge.Where(file => file != filesToMerge[0])) { var source = new SQLite(); // If readOnly is true then .db-shm files are not removed on close. Bug in SqLite. // http://sqlite.1065341.n5.nabble.com/journal-files-not-always-removed-td83700.html source.OpenDatabase(sourceFileName, readOnly: false); try { Merge(source, destination); } finally { source.CloseDatabase(); } } } finally { destination.CloseDatabase(); } } else if (filesToMerge.Length == 1) { File.Copy(filesToMerge[0], outFileName, true); } }