• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ISqlExpression类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ISqlExpression的典型用法代码示例。如果您正苦于以下问题:C# ISqlExpression类的具体用法?C# ISqlExpression怎么用?C# ISqlExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ISqlExpression类属于命名空间,在下文中一共展示了ISqlExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: BuildFunction

        protected override void BuildFunction(StringBuilder sb, SqlFunction func)
        {
            func = ConvertFunctionParameters(func);

            switch (func.Name)
            {
                case "CASE"     : func = ConvertCase(func.SystemType, func.Parameters, 0); break;
                case "Coalesce" :

                    if (func.Parameters.Length > 2)
                    {
                        var parms = new ISqlExpression[func.Parameters.Length - 1];

                        Array.Copy(func.Parameters, 1, parms, 0, parms.Length);
                        BuildFunction(sb, new SqlFunction(func.SystemType, func.Name, func.Parameters[0],
                                          new SqlFunction(func.SystemType, func.Name, parms)));
                        return;
                    }

                    var sc = new SqlQuery.SearchCondition();

                    sc.Conditions.Add(new SqlQuery.Condition(false, new SqlQuery.Predicate.IsNull(func.Parameters[0], false)));

                    func = new SqlFunction(func.SystemType, "IIF", sc, func.Parameters[1], func.Parameters[0]);

                    break;
            }

            base.BuildFunction(sb, func);
        }
开发者ID:henleygao,项目名称:linq2db,代码行数:30,代码来源:SqlServer2012SqlProvider.cs


示例2: BuildSkip

        static void BuildSkip(ExpressionBuilder builder, IBuildContext sequence, ISqlExpression prevSkipValue, ISqlExpression expr)
        {
            var sql = sequence.SqlQuery;

            builder.SqlProvider.SqlQuery = sql;

            sql.Select.Skip(expr);

            builder.SqlProvider.SqlQuery = sql;

            if (sql.Select.TakeValue != null)
            {
                if (builder.DataContextInfo.SqlProviderFlags.GetIsSkipSupportedFlag(sql) ||
                    !builder.DataContextInfo.SqlProviderFlags.IsTakeSupported)
                    sql.Select.Take(builder.Convert(
                        sequence,
                        new SqlBinaryExpression(typeof(int), sql.Select.TakeValue, "-", sql.Select.SkipValue, Precedence.Additive)));

                if (prevSkipValue != null)
                    sql.Select.Skip(builder.Convert(
                        sequence,
                        new SqlBinaryExpression(typeof(int), prevSkipValue, "+", sql.Select.SkipValue, Precedence.Additive)));
            }

            if (!builder.DataContextInfo.SqlProviderFlags.GetAcceptsTakeAsParameterFlag(sql))
            {
                var p = sql.Select.SkipValue as SqlParameter;

                if (p != null)
                    p.IsQueryParameter = false;
            }
        }
开发者ID:henleygao,项目名称:linq2db,代码行数:32,代码来源:TakeSkipBuilder.cs


示例3: ParseSkip

		static void ParseSkip(ExpressionParser parser, IParseContext sequence, ISqlExpression prevSkipValue, ISqlExpression expr)
		{
			var sql = sequence.SqlQuery;

			parser.SqlProvider.SqlQuery = sql;

			sql.Select.Skip(expr);

			parser.SqlProvider.SqlQuery = sql;

			if (sql.Select.TakeValue != null)
			{
				if (parser.SqlProvider.IsSkipSupported || !parser.SqlProvider.IsTakeSupported)
					sql.Select.Take(parser.Convert(
						sequence,
						new SqlBinaryExpression(typeof(int), sql.Select.TakeValue, "-", sql.Select.SkipValue, Precedence.Additive)));

				if (prevSkipValue != null)
					sql.Select.Skip(parser.Convert(
						sequence,
						new SqlBinaryExpression(typeof(int), prevSkipValue, "+", sql.Select.SkipValue, Precedence.Additive)));
			}

			if (!parser.SqlProvider.TakeAcceptsParameter)
			{
				var p = sql.Select.SkipValue as SqlParameter;

				if (p != null)
					p.IsQueryParameter = false;
			}
		}
开发者ID:Firebie,项目名称:ItemsUsage,代码行数:31,代码来源:TakeSkipParser.cs


示例4: ConvertArgs

		protected ISqlExpression[] ConvertArgs(MemberInfo member, ISqlExpression[] args)
		{
			if (member is MethodInfo)
			{
				var method = (MethodInfo)member;

				if (method.DeclaringType.IsGenericType)
					args = args.Concat(method.DeclaringType.GetGenericArguments().Select(t => (ISqlExpression)SqlDataType.GetDataType(t))).ToArray();

				if (method.IsGenericMethod)
					args = args.Concat(method.GetGenericArguments().Select(t => (ISqlExpression)SqlDataType.GetDataType(t))).ToArray();
			}

			if (ArgIndices != null)
			{
				var idxs = new ISqlExpression[ArgIndices.Length];

				for (var i = 0; i < ArgIndices.Length; i++)
					idxs[i] = args[ArgIndices[i]];

				return idxs;
			}

			return args;
		}
开发者ID:MajidSafari,项目名称:bltoolkit,代码行数:25,代码来源:SqlFunctionAttribute.cs


示例5: ConvertExpression

		public override ISqlExpression ConvertExpression(ISqlExpression expr)
		{
			expr = base.ConvertExpression(expr);

			switch (expr.ElementType)
			{
				case QueryElementType.SqlBinaryExpression:
					{
						var be = (SqlBinaryExpression)expr;

						switch (be.Operation)
						{
							case "%":
								{
									var type1 = TypeHelper.GetUnderlyingType(be.Expr1.SystemType);

									if (type1 == typeof(double) || type1 == typeof(float))
									{
										return new SqlBinaryExpression(
											be.Expr2.SystemType,
											new SqlFunction(typeof(int), "Convert", SqlDataType.Int32, be.Expr1),
											be.Operation,
											be.Expr2);
									}

									break;
								}
						}

						break;
					}

				case QueryElementType.SqlFunction:
					{
						var func = (SqlFunction)expr;

						switch (func.Name)
						{
							case "Convert" :
								{
									if (TypeHelper.GetUnderlyingType(func.SystemType) == typeof(ulong) &&
										TypeHelper.IsFloatType(func.Parameters[1].SystemType))
										return new SqlFunction(
											func.SystemType,
											func.Name,
											func.Precedence,
											func.Parameters[0],
											new SqlFunction(func.SystemType, "Floor", func.Parameters[1]));

									break;
								}
						}

						break;
					}
			}

			return expr;
		}
开发者ID:luoshulin,项目名称:bltoolkit,代码行数:59,代码来源:MSSqlSqlProvider.cs


示例6: ConvertExpression

		public override ISqlExpression ConvertExpression(ISqlExpression expr)
		{
			expr = base.ConvertExpression(expr);

			if (expr is SqlFunction)
				return ConvertConvertFunction((SqlFunction)expr);

			return expr;
		}
开发者ID:Convey-Compliance,项目名称:linq2db,代码行数:9,代码来源:SqlServer2000SqlOptimizer.cs


示例7: ConvertExpression

		public override ISqlExpression ConvertExpression(ISqlExpression expr)
		{
			expr = base.ConvertExpression(expr);

			if (expr is SqlBinaryExpression)
			{
				var be = (SqlBinaryExpression)expr;

				switch (be.Operation)
				{
					case "^": return new SqlBinaryExpression(be.SystemType, be.Expr1, "#", be.Expr2);
					case "+": return be.SystemType == typeof(string)? new SqlBinaryExpression(be.SystemType, be.Expr1, "||", be.Expr2, be.Precedence): expr;
				}
			}
			else if (expr is SqlFunction)
			{
				var func = (SqlFunction) expr;

				switch (func.Name)
				{
					case "Convert"   :
						if (TypeHelper.GetUnderlyingType(func.SystemType) == typeof(bool))
						{
							var ex = AlternativeConvertToBoolean(func, 1);
							if (ex != null)
								return ex;
						}

						return new SqlExpression(func.SystemType, "Cast({0} as {1})", Precedence.Primary, FloorBeforeConvert(func), func.Parameters[0]);

					case "CharIndex" :
						return func.Parameters.Length == 2?
							new SqlExpression(func.SystemType, "Position({0} in {1})", Precedence.Primary, func.Parameters[0], func.Parameters[1]):
							Add<int>(
								new SqlExpression(func.SystemType, "Position({0} in {1})", Precedence.Primary, func.Parameters[0],
									ConvertExpression(new SqlFunction(typeof(string), "Substring",
										func.Parameters[1],
										func.Parameters[2],
										Sub<int>(ConvertExpression(new SqlFunction(typeof(int), "Length", func.Parameters[1])), func.Parameters[2])))),
								Sub(func.Parameters[2], 1));
				}
			}
			else if (expr is SqlExpression)
			{
				var e = (SqlExpression)expr;

				if (e.Expr.StartsWith("Extract(DOW"))
					return Inc(new SqlExpression(expr.SystemType, e.Expr.Replace("Extract(DOW", "Extract(Dow"), e.Parameters));

				if (e.Expr.StartsWith("Extract(Millisecond"))
					return new SqlExpression(expr.SystemType, "Cast(To_Char({0}, 'MS') as int)", e.Parameters);
			}

			return expr;
		}
开发者ID:pbludov,项目名称:bltoolkit,代码行数:55,代码来源:PostgreSQLSqlProvider.cs


示例8: GenerateRsSizeLimitingParametersForPaging

        protected override IDacParameter[] GenerateRsSizeLimitingParametersForPaging(IQuery query, ISqlExpression sqlExpression)
        {
            var skipRows = (query.Paging.PageIndex * query.Paging.PageSize);
            var takeRows = (skipRows + query.Paging.PageSize);

            return new IDacParameter[] 
            {
                new DacParameter("skipRows", skipRows),
                new DacParameter("takeRows", takeRows)
            };
        }
开发者ID:ovuncgursoy,项目名称:SisoDb-Provider,代码行数:11,代码来源:Sql2005QueryGenerator.cs


示例9: GenerateOrderByMembersString

		protected virtual string GenerateOrderByMembersString(IQuery queryCommand, ISqlExpression sqlExpression)
		{
			var sortings = sqlExpression.SortingMembers.Select(
				sorting => (sorting.MemberPath != IndexStorageSchema.Fields.StructureId.Name)
					? string.Format("min(mem{0}.[{1}]) mem{0}", sorting.Index, sorting.IndexStorageColumnName)
					: string.Empty).Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();

            return sortings.Length == 0
                ? string.Empty
				: string.Join(", ", sortings);
        }
开发者ID:BlackMael,项目名称:SisoDb-Provider,代码行数:11,代码来源:DbQueryGenerator.cs


示例10: ConvertEmptyStringToNullIfNeeded

		private static void ConvertEmptyStringToNullIfNeeded(ISqlExpression expr)
		{
			var sqlParameter = expr as SqlParameter;
			var sqlValue     = expr as SqlValue;

			if (sqlParameter != null && sqlParameter.Value is string && sqlParameter.Value.ToString() == "")
				sqlParameter.Value = null;

			if (sqlValue != null && sqlValue.Value is string && sqlValue.Value.ToString() == "")
				sqlValue.Value = null;
		}
开发者ID:yallie,项目名称:linq2db,代码行数:11,代码来源:OracleSqlBuilder.cs


示例11: GenerateOrderByString

		protected virtual string GenerateOrderByString(IQuery query, ISqlExpression sqlExpression)
		{
			var sortings = sqlExpression.SortingMembers.Select(
				sorting => (sorting.MemberPath != IndexStorageSchema.Fields.StructureId.Name)
				           	? string.Format("mem{0} {1}", sorting.Index, sorting.Direction)
							: string.Format("s.[{0}] {1}", IndexStorageSchema.Fields.StructureId.Name, sorting.Direction)).ToArray();

            return sortings.Length == 0
                ? string.Empty
                : string.Join(", ", sortings);
        }
开发者ID:BlackMael,项目名称:SisoDb-Provider,代码行数:11,代码来源:DbQueryGenerator.cs


示例12: GeneratePagingString

		protected override string GeneratePagingString(IQuery query, ISqlExpression sqlExpression)
        {
			if (!query.HasPaging)
                return string.Empty;

            var s = string.Join(", ", sqlExpression.SortingMembers.Select(
				sorting => sorting.MemberPath != IndexStorageSchema.Fields.StructureId.Name 
					? string.Format("min(mem{0}.[{1}]) {2}", sorting.Index, sorting.IndexStorageColumnName, sorting.Direction)
					: string.Format("s.[{0}] {1}", IndexStorageSchema.Fields.StructureId.Name, sorting.Direction)));
            
            return string.Format("row_number() over (order by {0}) RowNum", s);
        }
开发者ID:MikaelEliasson,项目名称:SisoDb-Provider,代码行数:12,代码来源:Sql2005QueryGenerator.cs


示例13: GeneratePagingParameters

        protected override IDacParameter[] GeneratePagingParameters(IQuery query, ISqlExpression sqlExpression)
        {
            if (!query.HasPaging)
                return new IDacParameter[0];

            var takeFromRowNum = (query.Paging.PageIndex * query.Paging.PageSize) + 1;
            var takeToRowNum = (takeFromRowNum + query.Paging.PageSize) - 1;

            return new IDacParameter[]
            {
                new DacParameter("pagingFrom", takeFromRowNum),
                new DacParameter("pagingTo", takeToRowNum)
            };
        }
开发者ID:MikaelEliasson,项目名称:SisoDb-Provider,代码行数:14,代码来源:Sql2005QueryGenerator.cs


示例14: ConvertExpression

		public override ISqlExpression ConvertExpression(ISqlExpression expr)
		{
			expr = base.ConvertExpression(expr);

			if (expr is SqlFunction)
			{
				var func = expr as SqlFunction;
				if (func.Name == "Convert")
				{
					var ftype = func.SystemType.ToUnderlying();

					if (ftype == typeof(bool))
					{
						var ex = AlternativeConvertToBoolean(func, 1);
						if (ex != null)
							return ex;
					}
					return new SqlExpression(func.SystemType, "Cast({0} as {1})", Precedence.Primary, FloorBeforeConvert(func), func.Parameters[0]);
				}
			}
			else if (expr is SqlBinaryExpression)
			{
				var be = expr as SqlBinaryExpression;

				switch (be.Operation)
				{
					case "%":
						return new SqlFunction(be.SystemType, "MOD", be.Expr1, be.Expr2);
					case "&": 
						return new SqlFunction(be.SystemType, "BITAND", be.Expr1, be.Expr2);
					case "|":
						return Sub(
							Add(be.Expr1, be.Expr2, be.SystemType),
							new SqlFunction(be.SystemType, "BITAND", be.Expr1, be.Expr2),
							be.SystemType);
					case "^": // (a + b) - BITAND(a, b) * 2
						return Sub(
							Add(be.Expr1, be.Expr2, be.SystemType),
							Mul(new SqlFunction(be.SystemType, "BITAND", be.Expr1, be.Expr2), 2),
							be.SystemType);
					case "+": 
						return be.SystemType == typeof(string) ? 
							new SqlBinaryExpression(be.SystemType, be.Expr1, "||", be.Expr2, be.Precedence) : 
							expr;
				}
			}

			return expr;
		}
开发者ID:Convey-Compliance,项目名称:linq2db,代码行数:49,代码来源:SapHanaSqlOptimizer.cs


示例15: CreateSqlQueryFormatter

 protected override SqlQueryFormatter CreateSqlQueryFormatter(IQuery query, ISqlExpression sqlExpression)
 {
     return new SqlQueryFormatter
     {
         Start = GenerateStartString(query, sqlExpression),
         End = GenerateEndString(query, sqlExpression),
         Take = GenerateTakeString(query),
         OrderByMembers = GenerateOrderByMembersString(query, sqlExpression),
         MainStructureTable = query.StructureSchema.GetStructureTableName(),
         WhereAndSortingJoins = GenerateWhereAndSortingJoins(query, sqlExpression),
         WhereCriteria = GenerateWhereCriteriaString(sqlExpression),
         OrderBy = GenerateOrderByString(query, sqlExpression),
         Paging = GeneratePagingString(query, sqlExpression).PrependWith(", "),
     };
 }
开发者ID:ovuncgursoy,项目名称:SisoDb-Provider,代码行数:15,代码来源:Sql2005QueryGenerator.cs


示例16: ConvertExpression

		public override ISqlExpression ConvertExpression(ISqlExpression expr)
		{
			expr = base.ConvertExpression(expr);

			if (expr is SqlFunction)
			{
				var func = (SqlFunction)expr;

				switch (Type.GetTypeCode(TypeHelper.GetUnderlyingType(func.SystemType)))
				{
					case TypeCode.DateTime :

						if (func.Name == "Convert")
						{
							var type1 = TypeHelper.GetUnderlyingType(func.Parameters[1].SystemType);

							if (IsTimeDataType(func.Parameters[0]))
							{
								if (type1 == typeof(DateTime) || type1 == typeof(DateTimeOffset))
									return new SqlExpression(
										func.SystemType, "Cast(Convert(Char, {0}, 114) as DateTime)", Precedence.Primary, func.Parameters[1]);

								if (func.Parameters[1].SystemType == typeof(string))
									return func.Parameters[1];

								return new SqlExpression(
									func.SystemType, "Convert(Char, {0}, 114)", Precedence.Primary, func.Parameters[1]);
							}

							if (type1 == typeof(DateTime) || type1 == typeof(DateTimeOffset))
							{
								if (IsDateDataType(func.Parameters[0], "Datetime"))
									return new SqlExpression(
										func.SystemType, "Cast(Floor(Cast({0} as Float)) as DateTime)", Precedence.Primary, func.Parameters[1]);
							}

							if (func.Parameters.Length == 2 && func.Parameters[0] is SqlDataType && func.Parameters[0] == SqlDataType.DateTime)
								return new SqlFunction(func.SystemType, func.Name, func.Precedence, func.Parameters[0], func.Parameters[1], new SqlValue(120));
						}

						break;
				}
			}

			return expr;
		}
开发者ID:MajidSafari,项目名称:bltoolkit,代码行数:46,代码来源:MsSql2005SqlProvider.cs


示例17: BuildTake

		static void BuildTake(ExpressionBuilder builder, IBuildContext sequence, ISqlExpression expr)
		{
			var sql = sequence.SqlQuery;

			builder.SqlProvider.SqlQuery = sql;

			sql.Select.Take(expr);

			if (sql.Select.SkipValue != null && builder.SqlProvider.IsTakeSupported && !builder.SqlProvider.IsSkipSupported)
			{
				if (sql.Select.SkipValue is SqlParameter && sql.Select.TakeValue is SqlValue)
				{
					var skip = (SqlParameter)sql.Select.SkipValue;
					var parm = (SqlParameter)sql.Select.SkipValue.Clone(new Dictionary<ICloneableElement,ICloneableElement>(), _ => true);

					parm.SetTakeConverter((int)((SqlValue)sql.Select.TakeValue).Value);

					sql.Select.Take(parm);

					var ep = (from pm in builder.CurrentSqlParameters where pm.SqlParameter == skip select pm).First();

					ep = new ParameterAccessor
					{
						Expression   = ep.Expression,
						Accessor     = ep.Accessor,
						SqlParameter = parm
					};

					builder.CurrentSqlParameters.Add(ep);
				}
				else
					sql.Select.Take(builder.Convert(
						sequence,
						new SqlBinaryExpression(typeof(int), sql.Select.SkipValue, "+", sql.Select.TakeValue, Precedence.Additive)));
			}

			if (!builder.SqlProvider.TakeAcceptsParameter)
			{
				var p = sql.Select.TakeValue as SqlParameter;

				if (p != null)
					p.IsQueryParameter = false;
			}
		}
开发者ID:MajidSafari,项目名称:bltoolkit,代码行数:44,代码来源:TakeSkipBuilder.cs


示例18: BuildColumnExpression

		protected override void BuildColumnExpression(ISqlExpression expr, string alias, ref bool addAlias)
		{
			var wrap = false;

			if (expr.SystemType == typeof(bool))
			{
				if (expr is SelectQuery.SearchCondition)
					wrap = true;
				else
				{
					var ex = expr as SqlExpression;
					wrap = ex != null && ex.Expr == "{0}" && ex.Parameters.Length == 1 && ex.Parameters[0] is SelectQuery.SearchCondition;
				}
			}

			if (wrap) StringBuilder.Append("CASE WHEN ");
			base.BuildColumnExpression(expr, alias, ref addAlias);
			if (wrap) StringBuilder.Append(" THEN 1 ELSE 0 END");
		}
开发者ID:Convey-Compliance,项目名称:linq2db,代码行数:19,代码来源:SqlCeSqlBuilder.cs


示例19: GenerateRsSizeLimitingParametersForSkipAndTake

        protected override IDacParameter[] GenerateRsSizeLimitingParametersForSkipAndTake(IQuery query, ISqlExpression sqlExpression)
        {
            var skipRows = 0;
            var ps = new List<IDacParameter>(2);

            if (query.SkipNumOfStructures.HasValue)
            {
                skipRows = query.SkipNumOfStructures.Value;
                ps.Add(new DacParameter("skipRows", skipRows));
            }

            if (query.TakeNumOfStructures.HasValue)
            {
                var takeRows = skipRows + query.TakeNumOfStructures.Value;
                ps.Add(new DacParameter("takeRows", takeRows));
            }

            return ps.ToArray();
        }
开发者ID:ovuncgursoy,项目名称:SisoDb-Provider,代码行数:19,代码来源:Sql2005QueryGenerator.cs


示例20: ConvertExpression

		public override ISqlExpression ConvertExpression(ISqlExpression expr)
		{
			expr = base.ConvertExpression(expr);

			if (expr is SqlFunction)
			{
				var func = (SqlFunction) expr;

				switch (func.Name)
				{
					case "CharIndex" :
						if (func.Parameters.Length == 3)
							return Add<int>(
								ConvertExpression(new SqlFunction(func.SystemType, "CharIndex",
									func.Parameters[0],
									ConvertExpression(new SqlFunction(typeof(string), "Substring",
										func.Parameters[1],
										func.Parameters[2], new SqlFunction(typeof(int), "Len", func.Parameters[1]))))),
								Sub(func.Parameters[2], 1));
						break;

					case "Stuff"     :
						if (func.Parameters[3] is SqlValue)
						{
							var value = (SqlValue)func.Parameters[3];

							if (value.Value is string && string.IsNullOrEmpty((string)value.Value))
								return new SqlFunction(
									func.SystemType,
									func.Name,
									func.Precedence,
									func.Parameters[0],
									func.Parameters[1],
									func.Parameters[1],
									new SqlValue(null));
						}

						break;
				}
			}

			return expr;
		}
开发者ID:jiangguang5201314,项目名称:bltoolkit,代码行数:43,代码来源:SybaseSqlProvider.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ISqlNode类代码示例发布时间:2022-05-24
下一篇:
C# ISqlDialect类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap