TableDA.GetData: Convert to coroutine of TableRow.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -41,13 +42,13 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic
|
||||
return tables;
|
||||
}
|
||||
|
||||
public static void Table_ExportData(Table t, TextWriter txtWriter, string conectionString)
|
||||
public static void Table_ExportData(Table t, TextWriter txtWriter, string conectionString, Action<int> notifyLenght = null)
|
||||
{
|
||||
if (t.Type != "BASE TABLE") { return; }
|
||||
|
||||
string tableName = string.Format("{0}.{1}", t.Schema, t.Name);
|
||||
txtWriter.WriteLine(string.Format("PRINT '*** Importing data of {0}....';", tableName));
|
||||
DataTable dtData = TableDA.GetData(conectionString, tableName);
|
||||
IEnumerable<TableRow> rows = TableDA.GetData(conectionString, tableName);
|
||||
if (t.Columns.Any(c => c.Indentity))
|
||||
{
|
||||
txtWriter.WriteLine(string.Format("-- {0}", tableName));
|
||||
@@ -55,7 +56,11 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic
|
||||
txtWriter.WriteLine(string.Format("DBCC CHECKIDENT ('{0}', RESEED, 0);", tableName));
|
||||
txtWriter.WriteLine(string.Format("SET IDENTITY_INSERT {0} ON;", tableName));
|
||||
txtWriter.WriteLine("GO");
|
||||
DataTableHelper.DataTable_GenerateInserts(txtWriter, dtData, tableName);
|
||||
foreach (TableRow row in rows)
|
||||
{
|
||||
int lenght = TableRowHelper.TableRow_GenerateInsert(txtWriter, row, tableName);
|
||||
notifyLenght?.Invoke(lenght);
|
||||
}
|
||||
txtWriter.WriteLine("GO");
|
||||
txtWriter.WriteLine(string.Format("SET IDENTITY_INSERT {0} OFF;", tableName));
|
||||
txtWriter.WriteLine("GO");
|
||||
@@ -66,7 +71,11 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic
|
||||
txtWriter.WriteLine(string.Format("-- {0}", tableName));
|
||||
txtWriter.WriteLine(string.Format("DELETE FROM {0};", tableName));
|
||||
txtWriter.WriteLine("GO");
|
||||
DataTableHelper.DataTable_GenerateInserts(txtWriter, dtData, tableName);
|
||||
foreach (TableRow row in rows)
|
||||
{
|
||||
int lenght = TableRowHelper.TableRow_GenerateInsert(txtWriter, row, tableName);
|
||||
notifyLenght?.Invoke(lenght);
|
||||
}
|
||||
txtWriter.WriteLine("GO");
|
||||
txtWriter.WriteLine(string.Empty);
|
||||
}
|
||||
|
||||
@@ -81,17 +81,19 @@ namespace VAR.DatabaseExplorer.Code.DataAccess
|
||||
return definitions;
|
||||
}
|
||||
|
||||
public static DataTable GetData(string connectionString, string tableFullName)
|
||||
public static IEnumerable<TableRow> GetData(string connectionString, string tableFullName)
|
||||
{
|
||||
var cnx = new SqlConnection(connectionString);
|
||||
string strCmd = string.Format("SELECT * FROM {0}", tableFullName);
|
||||
var da = new SqlDataAdapter(strCmd, cnx);
|
||||
var dt = new DataTable();
|
||||
var cmd = new SqlCommand(strCmd, cnx);
|
||||
cnx.Open();
|
||||
da.Fill(dt);
|
||||
SqlDataReader reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
TableRow row = TableRowHelper.ConvertFromDataRecord(reader);
|
||||
yield return row;
|
||||
}
|
||||
cnx.Close();
|
||||
|
||||
return dt;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user