当前位置: 首页>>代码示例>>C#>>正文


C# StreamWriter.PrepCreateTable方法代码示例

本文整理汇总了C#中System.IO.StreamWriter.PrepCreateTable方法的典型用法代码示例。如果您正苦于以下问题:C# StreamWriter.PrepCreateTable方法的具体用法?C# StreamWriter.PrepCreateTable怎么用?C# StreamWriter.PrepCreateTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StreamWriter的用法示例。


在下文中一共展示了StreamWriter.PrepCreateTable方法的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();
            }
        }
开发者ID:mvrolijk,项目名称:ConvertPG2SS,代码行数:89,代码来源:ProcessPgSchema.cs


注:本文中的System.IO.StreamWriter.PrepCreateTable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。