Mercurial > pub > bltoolkit
diff Source/Data/Sql/SqlProvider/MsSql2005SqlProvider.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Source/Data/Sql/SqlProvider/MsSql2005SqlProvider.cs Thu Mar 27 21:46:09 2014 +0400 @@ -0,0 +1,83 @@ +using System; +using System.Data; +using System.Text; + +namespace BLToolkit.Data.Sql.SqlProvider +{ + using Reflection; + + public class MsSql2005SqlProvider : MsSqlSqlProvider + { + 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; + } + + protected override void BuildFunction(StringBuilder sb, SqlFunction func) + { + func = ConvertFunctionParameters(func); + base.BuildFunction(sb, func); + } + + protected override ISqlProvider CreateSqlProvider() + { + return new MsSql2005SqlProvider(); + } + + protected override void BuildDataType(System.Text.StringBuilder sb, SqlDataType type) + { + switch (type.SqlDbType) + { +#if !MONO + case SqlDbType.DateTimeOffset : + case SqlDbType.DateTime2 : +#endif + case SqlDbType.Time : + case SqlDbType.Date : sb.Append("DateTime"); break; + default : base.BuildDataType(sb, type); break; + } + } + } +}