DatabaseBL.Database_ExportData: Split data files.
This commit is contained in:
@@ -67,6 +67,10 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic
|
||||
|
||||
public static void Database_ExportData(TextWriter txtWriter, string connectionString, Database database)
|
||||
{
|
||||
const int OneMegaByte = 1 * 1024 * 1024;
|
||||
const int MaxSizePerBatch = OneMegaByte;
|
||||
const int MaxSizePerFile = OneMegaByte * 32;
|
||||
|
||||
// Preparar cabecera del script
|
||||
txtWriter.WriteLine("SET NOCOUNT ON;");
|
||||
txtWriter.WriteLine(string.Empty);
|
||||
@@ -84,9 +88,30 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic
|
||||
txtWriter.WriteLine(string.Empty);
|
||||
|
||||
// Prepara información a exportar
|
||||
long batchLength = 0;
|
||||
long fileLength = 0;
|
||||
foreach (Table table in database.Tables)
|
||||
{
|
||||
TableBL.Table_ExportData(table, txtWriter, connectionString);
|
||||
TableBL.Table_ExportData(table, txtWriter, connectionString, (lenght) =>
|
||||
{
|
||||
batchLength += lenght;
|
||||
fileLength += lenght;
|
||||
|
||||
if (batchLength > MaxSizePerBatch)
|
||||
{
|
||||
txtWriter.WriteLine("PRINT '...';");
|
||||
txtWriter.WriteLine("GO");
|
||||
batchLength = 0;
|
||||
}
|
||||
if (fileLength > MaxSizePerFile)
|
||||
{
|
||||
txtWriter.WriteLine("PRINT '...';");
|
||||
txtWriter.WriteLine("GO");
|
||||
SplittingStreamWriter.Split(txtWriter);
|
||||
fileLength = 0;
|
||||
batchLength = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Activar todas las FKs
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using VAR.DatabaseExplorer.Code;
|
||||
using VAR.DatabaseExplorer.Code.BusinessLogic;
|
||||
using VAR.DatabaseExplorer.Code.DataAccess;
|
||||
using VAR.DatabaseExplorer.Code.DataTransfer;
|
||||
@@ -116,7 +117,7 @@ namespace VAR.DatabaseExplorer.UI
|
||||
|
||||
Database database = DatabaseBL.Database_GetSchema(connectionString: _connectionString, fillTableDefinitions: true);
|
||||
string fixedDatabaseName = database.Name.Replace(' ', '_');
|
||||
var streamWriter = new StreamWriter("05." + fixedDatabaseName + ".Data.sql");
|
||||
var streamWriter = new SplittingStreamWriter("05." + fixedDatabaseName + ".{0:000}.Data.sql");
|
||||
DatabaseBL.Database_ExportData(streamWriter, _connectionString, database);
|
||||
streamWriter.Close();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user