diff --git a/VAR.DatabaseExplorer/Code/BusinessLogic/DatabaseBL.cs b/VAR.DatabaseExplorer/Code/BusinessLogic/DatabaseBL.cs index 4f39245..864d8f1 100644 --- a/VAR.DatabaseExplorer/Code/BusinessLogic/DatabaseBL.cs +++ b/VAR.DatabaseExplorer/Code/BusinessLogic/DatabaseBL.cs @@ -65,7 +65,7 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic txtWriter.WriteLine(""); } - public static void Database_ExportData(TextWriter txtWriter, string connectionString, Database database) + public static void Database_ExportData(TextWriter txtWriter, string connectionString, Database database, List tablesToExportData) { const int OneMegaByte = 1 * 1024 * 1024; const int MaxSizePerBatch = OneMegaByte; @@ -75,9 +75,18 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic txtWriter.WriteLine("SET NOCOUNT ON;"); txtWriter.WriteLine(string.Empty); + List
tables = database.Tables; + if (tablesToExportData.Any()) + { + tables = tables.Where(t => + tablesToExportData.Select(tted => tted.Schema).Contains(t.Schema) && + tablesToExportData.Select(tted => tted.Name).Contains(t.Name) && + tablesToExportData.Select(tted => tted.Type).Contains(t.Type)).ToList(); + } + // Desactivar todas las FKs txtWriter.WriteLine("-- Disable all constraints"); - foreach (Table table in database.Tables) + foreach (Table table in tables) { if (table.Type != "BASE TABLE") { continue; } @@ -90,7 +99,7 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic // Prepara información a exportar long batchLength = 0; long fileLength = 0; - foreach (Table table in database.Tables) + foreach (Table table in tables) { TableBL.Table_ExportData(table, txtWriter, connectionString, (lenght, onSplit) => { @@ -118,7 +127,7 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic // Activar todas las FKs txtWriter.WriteLine("-- Enable all constraints"); - foreach (Table table in database.Tables) + foreach (Table table in tables) { if (table.Type != "BASE TABLE") { continue; } diff --git a/VAR.DatabaseExplorer/UI/FrmDatabase.cs b/VAR.DatabaseExplorer/UI/FrmDatabase.cs index 93a1e9d..ccfdc9b 100644 --- a/VAR.DatabaseExplorer/UI/FrmDatabase.cs +++ b/VAR.DatabaseExplorer/UI/FrmDatabase.cs @@ -116,10 +116,22 @@ namespace VAR.DatabaseExplorer.UI { Parent.Enabled = false; + List
tablesToExportData = new List
(); + foreach (ListViewItem checkedItem in lsvTablas.CheckedItems) + { + Table tableToExportData = new Table() + { + Schema = checkedItem.SubItems[0].Text.ToString(), //Schema + Name = checkedItem.SubItems[1].Text.ToString(), //Name + Type = checkedItem.SubItems[2].Text.ToString(), //Type + }; + tablesToExportData.Add(tableToExportData); + } + Database database = DatabaseBL.Database_GetSchema(connectionString: _connectionString, fillTableDefinitions: true); string fixedDatabaseName = database.Name.Replace(' ', '_'); var streamWriter = new SplittingStreamWriter("05." + fixedDatabaseName + ".{0:000}.Data.sql"); - DatabaseBL.Database_ExportData(streamWriter, _connectionString, database); + DatabaseBL.Database_ExportData(streamWriter, _connectionString, database, tablesToExportData); streamWriter.Close(); Parent.Enabled = true;