/// <summary> /// Script the database objects to a file. /// </summary> /// <param name="db"></param> /// <param name="file"></param> /// <param name="full"></param> /// <param name="channel"></param> public static void ScriptToFile(Database db, string file, bool full, Channel channel) { if ((new FileInfo(file)).Exists) { // there must be no such file; overwriting not allowed for security throw TracingHelper.Error(TracingHelper.FILE_IO_ERROR, file); } try { DateTime time = DateTime.Now; // only ddl commands; needs not so much memory Result r; if (full) { // no drop, no insert, and no positions for cached tables r = db.GetScript(false, false, false, channel); } else { // no drop, no insert, but positions for cached tables r = db.GetScript(false, false, true, channel); } Record n = r.Root; StreamWriter w = new StreamWriter(file); while (n != null) { writeLine(w, (string) n.Data[0]); n = n.Next; } // inserts are done separetely to save memory ArrayList tables = db.Tables; for (int i = 0; i < tables.Count; i++) { Table t = (Table) tables[i]; // cached tables have the index roots set in the ddl script if (full ||!t.IsCached) { Index primary = t.PrimaryIndex; Node x = primary.First(); while (x != null) { writeLine(w, t.GetInsertStatement(x.GetData())); x = primary.Next(x); } } } w.Close(); TimeSpan execution = DateTime.Now.Subtract(time); if (TracingHelper.TraceEnabled) TracingHelper.Write((Int64)execution.TotalMilliseconds); } catch (IOException e) { TracingHelper.Error(TracingHelper.FILE_IO_ERROR, file + " " + e); } }
/// <summary> /// Script the database objects to a file. /// </summary> /// <param name="db"></param> /// <param name="file"></param> /// <param name="full"></param> /// <param name="channel"></param> public static void ScriptToFile(Database db, string file, bool full, Channel channel) { if ((new FileInfo(file)).Exists) { // there must be no such file; overwriting not allowed for security throw TracingHelper.Error(TracingHelper.FILE_IO_ERROR, file); } try { DateTime time = DateTime.Now; // only ddl commands; needs not so much memory Result r; if (full) { // no drop, no insert, and no positions for cached tables r = db.GetScript(false, false, false, channel); } else { // no drop, no insert, but positions for cached tables r = db.GetScript(false, false, true, channel); } Record n = r.Root; StreamWriter w = new StreamWriter(file); while (n != null) { writeLine(w, (string)n.Data[0]); n = n.Next; } // inserts are done separetely to save memory ArrayList tables = db.Tables; for (int i = 0; i < tables.Count; i++) { Table t = (Table)tables[i]; // cached tables have the index roots set in the ddl script if (full || !t.IsCached) { Index primary = t.PrimaryIndex; Node x = primary.First(); while (x != null) { writeLine(w, t.GetInsertStatement(x.GetData())); x = primary.Next(x); } } } w.Close(); TimeSpan execution = DateTime.Now.Subtract(time); if (TracingHelper.TraceEnabled) { TracingHelper.Write((Int64)execution.TotalMilliseconds); } } catch (IOException e) { TracingHelper.Error(TracingHelper.FILE_IO_ERROR, file + " " + e); } }