本文整理汇总了C#中System.IO.StreamWriter.CloseCreateTable方法的典型用法代码示例。如果您正苦于以下问题:C# StreamWriter.CloseCreateTable方法的具体用法?C# StreamWriter.CloseCreateTable怎么用?C# StreamWriter.CloseCreateTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StreamWriter
的用法示例。
在下文中一共展示了StreamWriter.CloseCreateTable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateTableScripts
/// <summary>
/// Generate the SQL Server scripts.
/// </summary>
/// <param name="schemaTable">DataTable with all the PostgreSQL schema/table/column info.</param>
/// <param name="seqTable"></param>
/// <param name="conn">PG connection.</param>
private static void GenerateTableScripts(
DataTable schemaTable,
DataTable seqTable,
NpgsqlConnection conn)
{
var createPath = Path.Combine(
_params[Parameters.OtherWorkPath].ToString(), Constants.CreateTables);
var dropPath = Path.Combine(
_params[Parameters.OtherWorkPath].ToString(), Constants.CreateDropTables);
var truncPath = Path.Combine(
_params[Parameters.OtherWorkPath].ToString(), Constants.CreateSTruncateTables);
StreamWriter swCreate = null;
StreamWriter swDrop = null;
StreamWriter swTrunc = null;
try
{
swCreate = new StreamWriter(createPath, false, Encoding.Default);
swDrop = new StreamWriter(dropPath, false, Encoding.Default);
swTrunc = new StreamWriter(truncPath, false, Encoding.Default);
swCreate.WriteBeginTrans();
swDrop.WriteBeginTrans();
swTrunc.WriteBeginTrans();
swCreate.PrepCreateTable();
var savedSchema = "";
var savedTable = "";
var colInfo = new List<ColumnInfo>();
foreach (DataRow row in schemaTable.Rows)
{
var schema = row["schema_name"].ToString();
var table = row["table_name"].ToString();
// Schema or table changed: close table defenition.
if (!savedSchema.Equals(schema) || !savedTable.Equals(table))
{
if (!string.IsNullOrEmpty(savedTable))
{
CloseCreateTable(swCreate, colInfo);
UpdateSeqTable(colInfo, seqTable);
colInfo.Clear();
}
savedSchema = schema;
savedTable = table;
swCreate.OpenCreateTable(schema, table);
swDrop.WriteDropCommand(schema, table);
swTrunc.WriteTruncateCommand(schema, table);
}
else swCreate.WriteLine(",");
// Generate column definition.
ColumnInfo tmpColInfo;
swCreate.GenerateColumn(row, out tmpColInfo);
if (!string.IsNullOrEmpty(tmpColInfo.Schema))
{
colInfo.Add(tmpColInfo);
}
}
if (string.IsNullOrEmpty(savedSchema)) return;
// Complete last writes.
swCreate.CloseCreateTable(colInfo);
swCreate.WriteTableDesc(conn);
swCreate.WriteCommitTrans();
swDrop.WriteCommitTrans();
swTrunc.WriteCommitTrans();
}
catch (Exception ex) {
_log.WriteEx('E', Constants.LogTsType, ex);
}
finally
{
swCreate?.Dispose();
swDrop?.Dispose();
swTrunc?.Dispose();
}
}