本文整理汇总了C#中ISqlExpression类的典型用法代码示例。如果您正苦于以下问题:C# ISqlExpression类的具体用法?C# ISqlExpression怎么用?C# ISqlExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ISqlExpression类属于命名空间,在下文中一共展示了ISqlExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例6: ConvertExpression
public override ISqlExpression ConvertExpression(ISqlExpression expr)
{
expr = base.ConvertExpression(expr);
if (expr is SqlFunction)
return ConvertConvertFunction((SqlFunction)expr);
return expr;
}
示例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;
}
示例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)
};
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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)
};
}
示例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;
}
示例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(", "),
};
}