Fixes on ExportData.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using VAR.DatabaseExplorer.Code.DataAccess;
|
using VAR.DatabaseExplorer.Code.DataAccess;
|
||||||
using VAR.DatabaseExplorer.Code.DataTransfer;
|
using VAR.DatabaseExplorer.Code.DataTransfer;
|
||||||
|
|
||||||
@@ -71,21 +72,42 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic
|
|||||||
|
|
||||||
// Desactivar todas las FKs
|
// Desactivar todas las FKs
|
||||||
txtWriter.WriteLine("-- Disable all constraints");
|
txtWriter.WriteLine("-- Disable all constraints");
|
||||||
txtWriter.WriteLine("EXEC sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'");
|
foreach (Table t in database.Tables)
|
||||||
|
{
|
||||||
|
if (t.Type != "BASE TABLE") { continue; }
|
||||||
|
|
||||||
|
string tableName = string.Format("[{0}].[{1}]", t.Schema, t.Name);
|
||||||
|
txtWriter.WriteLine(string.Format("ALTER TABLE {0} NOCHECK CONSTRAINT all;", tableName));
|
||||||
|
}
|
||||||
txtWriter.WriteLine("GO");
|
txtWriter.WriteLine("GO");
|
||||||
txtWriter.WriteLine(string.Empty);
|
txtWriter.WriteLine(string.Empty);
|
||||||
|
|
||||||
// Prepara informacion a exportar
|
// Prepara información a exportar
|
||||||
foreach (Table t in database.Tables)
|
foreach (Table t in database.Tables)
|
||||||
{
|
{
|
||||||
|
if (t.Type != "BASE TABLE") { continue; }
|
||||||
|
|
||||||
string tableName = string.Format("{0}.{1}", t.Schema, t.Name);
|
string tableName = string.Format("{0}.{1}", t.Schema, t.Name);
|
||||||
txtWriter.WriteLine(string.Format("PRINT '*** Importing data of {0}....';", tableName));
|
txtWriter.WriteLine(string.Format("PRINT '*** Importing data of {0}....';", tableName));
|
||||||
TableBL.Table_ExportData(txtWriter, connectionString, tableName);
|
if (t.Columns.Any(c => c.Indentity))
|
||||||
|
{
|
||||||
|
TableBL.Table_ExportDataWithIdentity(t, txtWriter, connectionString, tableName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TableBL.Table_ExportData(t, txtWriter, connectionString, tableName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activar todas las FKs
|
// Activar todas las FKs
|
||||||
txtWriter.WriteLine("-- Enable all constraints");
|
txtWriter.WriteLine("-- Enable all constraints");
|
||||||
txtWriter.WriteLine("EXEC sp_MSforeachtable @command1='print ''?''', @command2='ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all'");
|
foreach (Table t in database.Tables)
|
||||||
|
{
|
||||||
|
if (t.Type != "BASE TABLE") { continue; }
|
||||||
|
|
||||||
|
string tableName = string.Format("[{0}].[{1}]", t.Schema, t.Name);
|
||||||
|
txtWriter.WriteLine(string.Format("ALTER TABLE {0} WITH CHECK CHECK CONSTRAINT all;", tableName));
|
||||||
|
}
|
||||||
txtWriter.WriteLine("GO");
|
txtWriter.WriteLine("GO");
|
||||||
txtWriter.WriteLine(string.Empty);
|
txtWriter.WriteLine(string.Empty);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using VAR.DatabaseExplorer.Code.DataAccess;
|
using VAR.DatabaseExplorer.Code.DataAccess;
|
||||||
using VAR.DatabaseExplorer.Code.DataTransfer;
|
using VAR.DatabaseExplorer.Code.DataTransfer;
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic
|
|||||||
return tables;
|
return tables;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Table_ExportData(TextWriter txtWriter, string conectionString, string tableFullName)
|
public static void Table_ExportDataWithIdentity(Table t, TextWriter txtWriter, string conectionString, string tableFullName)
|
||||||
{
|
{
|
||||||
DataTable dtData = TableDA.GetData(conectionString, tableFullName);
|
DataTable dtData = TableDA.GetData(conectionString, tableFullName);
|
||||||
|
|
||||||
@@ -35,5 +36,16 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic
|
|||||||
txtWriter.WriteLine("GO");
|
txtWriter.WriteLine("GO");
|
||||||
txtWriter.WriteLine(string.Empty);
|
txtWriter.WriteLine(string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Table_ExportData(Table t, TextWriter txtWriter, string conectionString, string tableFullName)
|
||||||
|
{
|
||||||
|
DataTable dtData = TableDA.GetData(conectionString, tableFullName);
|
||||||
|
|
||||||
|
txtWriter.WriteLine(string.Format("-- {0}", tableFullName));
|
||||||
|
txtWriter.WriteLine(string.Format("DELETE FROM {0};", tableFullName));
|
||||||
|
DataTableHelper.DataTable_GenerateInserts(txtWriter, dtData, tableFullName);
|
||||||
|
txtWriter.WriteLine("GO");
|
||||||
|
txtWriter.WriteLine(string.Empty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ namespace VAR.DatabaseExplorer.Code
|
|||||||
if (type == "string")
|
if (type == "string")
|
||||||
{
|
{
|
||||||
// Cadenas
|
// Cadenas
|
||||||
sbValues.AppendFormat("'{0}'", ((string)valor).Replace("'", "''"));
|
sbValues.AppendFormat("N'{0}'", ((string)valor).Replace("'", "''"));
|
||||||
}
|
}
|
||||||
else if (type == "short" || type == "int16")
|
else if (type == "short" || type == "int16")
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user