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


C# StreamWriter.WriteIndex方法代码示例

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


在下文中一共展示了StreamWriter.WriteIndex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateBuildIndexes

        /// <summary>
        ///     Write the different create indeces/key constraint statements. 
        /// </summary>
        /// <param name="conn"></param>
        private static void GenerateBuildIndexes(NpgsqlConnection conn)
        {
            var indexPath = Path.Combine(
                _params[Parameters.OtherWorkPath].ToString(), Constants.CreateIndexesEtAl);

            // option column values:
            // INDOPTION_DESC			0x0001 = values are in reverse order (DESC)
            // INDOPTION_NULLS_FIRST	0x0002 = NULLs are first instead of last
            const string sql =
                @"SELECT n.nspname AS schema_name, c.relname AS table_name,
                        d.relname AS index_name, i.indisprimary,
                        i.indisunique, a.attname AS column_name,
                        i.indoption[a.attnum - 1] as option
                FROM	pg_index i
                        LEFT JOIN pg_attribute a
                              ON a.attrelid = i.indrelid
                                 AND a.attnum = ANY ( i.indkey )
                        LEFT JOIN pg_class c
                              ON c.oid = i.indrelid
                        LEFT JOIN pg_class d
                              ON d.oid = i.indexrelid
                        LEFT JOIN pg_namespace n
                              ON n.oid = c.relnamespace
                WHERE  n.nspname NOT IN('pg_toast', 'pg_catalog', 'information_schema', 'public')
                ORDER  BY n.nspname ASC, c.relname ASC, d.relname ASC, a.attnum";

            using (var cmd = new NpgsqlCommand(sql, conn))
            using (var sw = new StreamWriter(indexPath, false, Encoding.Default))
            {
                sw.WriteBeginTrans();

                var savedSchema = "";
                var savedTable = "";
                var savedIndex = "";
                var savedType = ' ';

                using (var reader = cmd.ExecuteReader())
                {
                    var sb = new StringBuilder();

                    while (reader.Read())
                    {
                        var schema = reader["schema_name"].ToString();
                        var table = reader["table_name"].ToString();
                        var index = reader["index_name"].ToString();

                        // Schema, table or index changed: close index defenition.
                        if (!savedSchema.Equals(schema) || !savedTable.Equals(table)
                            || !savedIndex.Equals(index))
                        {
                            if (sb.Length > 0)
                                sw.WriteIndex(
                                    savedSchema,
                                    savedTable,
                                    savedIndex,
                                    savedType,
                                    sb.ToString());
                            sb.Clear();

                            savedSchema = schema;
                            savedTable = table;
                            savedIndex = index;

                            if ((bool) reader["indisprimary"]) { savedType = 'P'; }
                            else if ((bool) reader["indisunique"]) { savedType = 'U'; }
                            else savedType = 'I';
                        }
                        else sb.Append(", ");

                        sb.Append("[" + reader["column_name"] + "]");

                        if (reader["option"] == DBNull.Value) continue;
                        switch ((short) reader["option"])
                        {
                            case 0:
                                sb.Append(" ASC");
                                break;
                            case 1:
                                sb.Append(" DESC");
                                break;
                        }
                    }

                    if (sb.Length > 0)
                        sw.WriteIndex(
                            savedSchema,
                            savedTable,
                            savedIndex,
                            savedType,
                            sb.ToString());

                    sw.WriteCommitTrans();
                }
            }
        }
开发者ID:mvrolijk,项目名称:ConvertPG2SS,代码行数:99,代码来源:ProcessPgSchema.cs


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