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


C# SqlStatement.ToString方法代码示例

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


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

示例1: BuildFrom

        protected virtual SqlStatement BuildFrom(IList<TableExpression> tables, QueryContext queryContext)
        {
            var sqlProvider = queryContext.DataContext.Vendor.SqlProvider;
            var fromClauses = new List<SqlStatement>();
            foreach (var tableExpression in tables)
            {
                if (!MustDeclareAsJoin(tables, tableExpression))
                {
                    if (tableExpression.Alias != null)
                    {
                        string tableAlias;

                        // All subqueries has an alias in FROM
                        SubSelectExpression subquery = tableExpression as SubSelectExpression;
                        if (subquery == null)
                            tableAlias = sqlProvider.GetTableAsAlias(tableExpression.Name, tableExpression.Alias);
                        else
                        {
                            var subqueryStatements = new SqlStatement(Build(subquery.Select, queryContext));
                            tableAlias = sqlProvider.GetSubQueryAsAlias(subqueryStatements.ToString(), tableExpression.Alias);
                        }

                        if ((tableExpression.JoinType & TableJoinType.LeftOuter) != 0)
                            tableAlias = "/* LEFT OUTER */ " + tableAlias;
                        if ((tableExpression.JoinType & TableJoinType.RightOuter) != 0)
                            tableAlias = "/* RIGHT OUTER */ " + tableAlias;
                        fromClauses.Add(tableAlias);
                    }
                    else
                    {
                        fromClauses.Add(sqlProvider.GetTable(tableExpression.Name));
                    }
                }
            }
            return sqlProvider.GetFromClause(fromClauses.ToArray());
        }
开发者ID:nlhepler,项目名称:mono,代码行数:36,代码来源:SqlBuilder.cs

示例2: GetLiteralAndBitwise

 /// <summary>
 /// Gets the literal and.
 /// </summary>
 /// <param name="a">A.</param>
 /// <param name="b">The b.</param>
 /// <returns></returns>
 protected virtual SqlStatement GetLiteralAndBitwise(SqlStatement a, SqlStatement b)
 {
     var strA = a.ToString();
       if (a.Count > 1) strA = "(" + strA + ")";
       var strB = string.Empty + b;
       if (b.Count > 1) strB = "(" + strB + ")";
       return strA + " & " + strB;
 }
开发者ID:yuanfei05,项目名称:vita,代码行数:14,代码来源:LinqSqlProvider.cs

示例3: GetLiteralLimit

        public override SqlStatement GetLiteralLimit(SqlStatement select, SqlStatement limit, SqlStatement offset, SqlStatement offsetAndLimit)
        {
            var strOffset = string.Empty + offset;
              if(string.IsNullOrWhiteSpace(strOffset))
            strOffset = "0";
              if (ServerVersion != MsSqlVersion.V2008) {
            return SqlStatement.Format("{0} \r\n OFFSET {1} ROWS FETCH NEXT {2} ROWS ONLY", select, strOffset, limit);
              }

              //V2008
              //TODO: fix this, get rid of all this string matching
              var sql = select.ToString();
              var from = "\r\nFROM ";
              var orderBy = "\r\nORDER BY ";
              var selectK = "SELECT ";
              int fromIdx = sql.IndexOf(from);
              int orderByIdx = sql.IndexOf(orderBy);

              if (fromIdx < 0)
            throw new ArgumentException("S0051: Unknown select format: " + sql);

              string orderByClause = null;
              string sourceClause = null;
              if (orderByIdx >= 0) {
            orderByClause = sql.Substring(orderByIdx);
            sourceClause = sql.Substring(fromIdx, orderByIdx - fromIdx);
              } else {
            orderByClause = "ORDER BY " + sql.Substring(selectK.Length, fromIdx - selectK.Length);
            sourceClause = sql.Substring(fromIdx);
              }
              orderByClause = orderByClause.Replace("\r\n", string.Empty);

              var selectFieldsClause = sql.Substring(0, fromIdx);

              var finalSql = SqlStatement.Format(
            "SELECT *{0}" +
            "FROM ({0}" +
            "    {1},{0}" +
            "    ROW_NUMBER() OVER({2}) AS [__ROW_NUMBER]{0}" +
            "    {3}" +
            "    ) AS [t0]{0}" +
            "WHERE [__ROW_NUMBER] BETWEEN {4}+1 AND {4}+{5}{0}" +
            "ORDER BY [__ROW_NUMBER]",
            NewLine, selectFieldsClause, orderByClause, sourceClause, offset, limit);
              return finalSql;
        }
开发者ID:yuanfei05,项目名称:vita,代码行数:46,代码来源:MsSqlLinqSqlProvider.cs

示例4: EncloseParenth

 protected virtual string EncloseParenth(SqlStatement s)
 {
     var str = s.ToString();
       //RI: I know, it is really sloppy, should be refactored with big engine refactoring
       if(str.StartsWith("(") && str.EndsWith(")"))
     return str;
       if(str.IndexOfAny(_operators) >= 0)
     return "(" + str + ")";
       return str;
 }
开发者ID:yuanfei05,项目名称:vita,代码行数:10,代码来源:LinqSqlProvider.cs

示例5: BuildFrom

        protected virtual SqlStatement BuildFrom(IList<TableExpression> tables)
        {
            var sqlProvider = this._dbModel.LinqSqlProvider;
            var fromClauses = new List<SqlStatement>();
            foreach (var tableExpression in tables)
            {
                if (!MustDeclareAsJoin(tables, tableExpression))
                {
                    if (tableExpression.Alias != null)
                    {
                        string tableRef;

                        // All subqueries has an alias in FROM
                        SubSelectExpression subquery = tableExpression as SubSelectExpression;
                        if (subquery == null)
                            tableRef = _sqlProvider.GetTable(tableExpression);
                        else
                        {
                            var subqueryStatements = new SqlStatement(BuildSelectSql(subquery.Select));
                            tableRef = _sqlProvider.GetSubQueryAsAlias(subqueryStatements.ToString(), tableExpression.Alias);
                        }

                        if ((tableExpression.JoinType & TableJoinType.LeftOuter) != 0)
                            tableRef = "/* LEFT OUTER */ " + tableRef;
                        if ((tableExpression.JoinType & TableJoinType.RightOuter) != 0)
                            tableRef = "/* RIGHT OUTER */ " + tableRef;
                        fromClauses.Add(tableRef);
                    }
                    else
                    {
                        fromClauses.Add(_sqlProvider.GetTable(tableExpression));
                    }
                }
            }
            return _sqlProvider.GetFromClause(fromClauses.ToArray());
        }
开发者ID:yuanfei05,项目名称:vita,代码行数:36,代码来源:SqlBuilder.cs


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