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


C# StringWriter.AppendQuote方法代码示例

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


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

示例1: GenerateUpdateSQL

        private string GenerateUpdateSQL(IList<RdbColumn> lobColumns)
        {
            var sql = new StringWriter();
            sql.Write("UPDATE ");
            sql.AppendQuoteName(this);
            sql.Write(" SET ");

            bool comma = false;
            var paramIndex = 0;

            //先更新所有非 lob 字段。
            for (int i = 0, c = _columns.Count; i < c; i++)
            {
                var column = _columns[i];
                if (!column.Info.IsPrimaryKey && !column.IsLOB)
                {
                    if (comma) { sql.Write(','); }
                    else { comma = true; }

                    sql.AppendQuote(this, column.Name).Write(" = {");
                    sql.Write(paramIndex++);
                    sql.Write('}');
                }
            }
            //再更新所有 lob 字段。
            if (lobColumns != null)
            {
                for (int i = 0, c = lobColumns.Count; i < c; i++)
                {
                    if (comma) { sql.Write(','); }
                    else { comma = true; }

                    var column = lobColumns[i];
                    sql.AppendQuote(this, column.Name);
                    sql.Write(" = {");
                    sql.Write(paramIndex++);
                    sql.Write('}');
                }
            }
            sql.Write(" WHERE ");
            sql.AppendQuote(this, _pkColumn.Name);
            sql.Write(" = {");
            sql.Write(paramIndex);
            sql.Write('}');

            return sql.ToString();
        }
开发者ID:hardCTE,项目名称:Rafy,代码行数:47,代码来源:RdbTable.cs

示例2: ReplaceLOBColumns

        private string ReplaceLOBColumns(string sql)
        {
            //如果 sql 中编写了 LOBColumnsToken 这个符号,则表示需要进行列名替换。
            var tokenIndex = sql.IndexOf(LOBColumnsToken);
            if (tokenIndex < 0) return sql;

            var res = new StringWriter();

            var tableName = string.Empty;

            //如果使用了 XXX.{*},则表示指定了表的名称,这时需要在每个字段前使用这个表的名称。
            var hasTablePrefix = sql[tokenIndex - 1] == '.';
            if (hasTablePrefix)
            {
                var tablePrefixIndex = tokenIndex - 1;
                while (true)
                {
                    tablePrefixIndex--;
                    if (tablePrefixIndex < 0) throw new InvalidOperationException("sql 语句格式有误。");
                    var c = sql[tablePrefixIndex];
                    if (c == ' ')
                    {
                        tablePrefixIndex++;
                        tableName = sql.Substring(tablePrefixIndex, tokenIndex - 1 - tablePrefixIndex);

                        var before = sql.Substring(0, tablePrefixIndex);
                        res.Write(before);

                        break;
                    }
                }
            }
            else
            {
                var before = sql.Substring(0, tokenIndex);
                res.Write(before);

                tableName = this.GetQuoteName();
            }

            //输出所有非 lob 列的列名。
            bool comma = false;
            for (int i = 0, c = _columns.Count; i < c; i++)
            {
                var column = _columns[i];
                if (column.IsLOB) { continue; }
                if (comma) { res.Write(','); }
                else { comma = true; }

                res.Write(tableName);
                res.Write('.');
                res.AppendQuote(this, column.Name);
            }

            var after = sql.Substring(tokenIndex + LOBColumnsToken.Length);
            res.Write(after);

            return res.ToString();
        }
开发者ID:hardCTE,项目名称:Rafy,代码行数:59,代码来源:RdbTable.cs

示例3: GenerateDeleteSQL

 private string GenerateDeleteSQL()
 {
     var sql = new StringWriter();
     sql.Write("DELETE FROM ");
     sql.AppendQuoteName(this);
     sql.Write(" WHERE ");
     sql.AppendQuote(this, this.PKColumn.Name).Write(" = {0}");
     return sql.ToString();
 }
开发者ID:hardCTE,项目名称:Rafy,代码行数:9,代码来源:RdbTable.cs

示例4: GenerateInsertSQL

        internal string GenerateInsertSQL()
        {
            var sql = new StringWriter();
            sql.Write("INSERT INTO ");
            sql.AppendQuote(this, this.Name).Write(" (");

            var values = new StringBuilder();
            bool comma = false;
            var index = 0;
            for (int i = 0, c = _columns.Count; i < c; i++)
            {
                var column = _columns[i];
                if (column.CanInsert)
                {
                    if (comma)
                    {
                        sql.Write(',');
                        values.Append(',');
                    }
                    else { comma = true; }

                    sql.AppendQuote(this, column.Name);
                    values.Append('{').Append(index++).Append('}');
                }
            }

            sql.Write(") VALUES (");
            sql.Write(values.ToString());
            sql.Write(")");

            return sql.ToString();
        }
开发者ID:hardCTE,项目名称:Rafy,代码行数:32,代码来源:RdbTable.cs

示例5: GenerateUpdateSQL

        /// <summary>
        /// 生成 Update 语句。
        /// 注意,此方法不会更新 LOB 字段。
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        private string GenerateUpdateSQL(RdbTable table)
        {
            //代码参考 RdbTable.GenerateUpdateSQL() 方法。

            var sql = new StringWriter();
            sql.Write("UPDATE ");
            sql.AppendQuoteName(table);
            sql.Write(" SET ");

            var updateLOB = this.UpdateLOB;
            bool comma = false;
            var columns = table.Columns;
            for (int i = 0, c = columns.Count; i < c; i++)
            {
                var column = columns[i];
                if (!column.Info.IsPrimaryKey && (updateLOB || !column.IsLOB))
                {
                    if (comma) { sql.Write(','); }
                    else { comma = true; }

                    sql.AppendQuote(table, column.Name).Write(" = @");
                    sql.Write(column.Name);
                }
            }

            sql.Write(" WHERE ");
            sql.AppendQuote(table, table.PKColumn.Name);
            sql.Write(" = @");
            sql.Write(table.PKColumn.Name);

            return sql.ToString();
        }
开发者ID:hardCTE,项目名称:Rafy,代码行数:38,代码来源:SqlBatchImporter.cs

示例6: GetEntityValue

        /// <summary>
        /// 子类重写此方法,来实现自己的 GetEntityValue 方法的数据层代码。
        /// </summary>
        /// <param name="entityId"></param>
        /// <param name="property"></param>
        /// <returns></returns>
        public override LiteDataTable GetEntityValue(object entityId, string property)
        {
            var table = this.DbTable;
            var idColumn = table.PKColumn.Name;
            var column = table.Translate(property);

            var sql = new StringWriter();
            sql.Write("SELECT ");
            sql.AppendQuote(table, column);
            sql.Write(" FROM ");
            sql.AppendQuoteName(table);
            sql.Write(" WHERE ");
            sql.AppendQuote(table, idColumn);
            sql.Write(" = {0}");

            return this.QueryTable(new TableQueryArgs
            {
                FormattedSql = sql.ToString(),
                Parameters = new object[] { entityId },
            });
        }
开发者ID:569550384,项目名称:Rafy,代码行数:27,代码来源:RdbDataProvider.cs

示例7: GenerateInsertSQL

        internal string GenerateInsertSQL()
        {
            var sql = new StringWriter();
            sql.Write("INSERT INTO ");
            sql.AppendQuote(this, this.Name).Write(" (");
            var values = new StringBuilder();
            bool comma = false;
            var index = 0;
            foreach (RdbColumn column in _columns)
            {
                if (this.CanInsert(column))
                {
                    if (comma)
                    {
                        sql.Write(',');
                        values.Append(',');
                    }
                    else { comma = true; }

                    sql.AppendQuote(this, column.Name);
                    values.Append('{').Append(index++).Append('}');
                }
            }
            sql.Write(") VALUES (");
            sql.Write(values.ToString());
            sql.Write(")");

            return sql.ToString();
        }
开发者ID:569550384,项目名称:Rafy,代码行数:29,代码来源:RdbTable.cs


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