0
|
1 using System;
|
|
2 using System.Data;
|
|
3 using System.Text;
|
|
4
|
|
5 namespace BLToolkit.Data.Sql.SqlProvider
|
|
6 {
|
|
7 using Reflection;
|
|
8
|
|
9 public class MsSql2005SqlProvider : MsSqlSqlProvider
|
|
10 {
|
|
11 public override ISqlExpression ConvertExpression(ISqlExpression expr)
|
|
12 {
|
|
13 expr = base.ConvertExpression(expr);
|
|
14
|
|
15 if (expr is SqlFunction)
|
|
16 {
|
|
17 var func = (SqlFunction)expr;
|
|
18
|
|
19 switch (Type.GetTypeCode(TypeHelper.GetUnderlyingType(func.SystemType)))
|
|
20 {
|
|
21 case TypeCode.DateTime :
|
|
22
|
|
23 if (func.Name == "Convert")
|
|
24 {
|
|
25 var type1 = TypeHelper.GetUnderlyingType(func.Parameters[1].SystemType);
|
|
26
|
|
27 if (IsTimeDataType(func.Parameters[0]))
|
|
28 {
|
|
29 if (type1 == typeof(DateTime) || type1 == typeof(DateTimeOffset))
|
|
30 return new SqlExpression(
|
|
31 func.SystemType, "Cast(Convert(Char, {0}, 114) as DateTime)", Precedence.Primary, func.Parameters[1]);
|
|
32
|
|
33 if (func.Parameters[1].SystemType == typeof(string))
|
|
34 return func.Parameters[1];
|
|
35
|
|
36 return new SqlExpression(
|
|
37 func.SystemType, "Convert(Char, {0}, 114)", Precedence.Primary, func.Parameters[1]);
|
|
38 }
|
|
39
|
|
40 if (type1 == typeof(DateTime) || type1 == typeof(DateTimeOffset))
|
|
41 {
|
|
42 if (IsDateDataType(func.Parameters[0], "Datetime"))
|
|
43 return new SqlExpression(
|
|
44 func.SystemType, "Cast(Floor(Cast({0} as Float)) as DateTime)", Precedence.Primary, func.Parameters[1]);
|
|
45 }
|
|
46
|
|
47 if (func.Parameters.Length == 2 && func.Parameters[0] is SqlDataType && func.Parameters[0] == SqlDataType.DateTime)
|
|
48 return new SqlFunction(func.SystemType, func.Name, func.Precedence, func.Parameters[0], func.Parameters[1], new SqlValue(120));
|
|
49 }
|
|
50
|
|
51 break;
|
|
52 }
|
|
53 }
|
|
54
|
|
55 return expr;
|
|
56 }
|
|
57
|
|
58 protected override void BuildFunction(StringBuilder sb, SqlFunction func)
|
|
59 {
|
|
60 func = ConvertFunctionParameters(func);
|
|
61 base.BuildFunction(sb, func);
|
|
62 }
|
|
63
|
|
64 protected override ISqlProvider CreateSqlProvider()
|
|
65 {
|
|
66 return new MsSql2005SqlProvider();
|
|
67 }
|
|
68
|
|
69 protected override void BuildDataType(System.Text.StringBuilder sb, SqlDataType type)
|
|
70 {
|
|
71 switch (type.SqlDbType)
|
|
72 {
|
|
73 #if !MONO
|
|
74 case SqlDbType.DateTimeOffset :
|
|
75 case SqlDbType.DateTime2 :
|
|
76 #endif
|
|
77 case SqlDbType.Time :
|
|
78 case SqlDbType.Date : sb.Append("DateTime"); break;
|
|
79 default : base.BuildDataType(sb, type); break;
|
|
80 }
|
|
81 }
|
|
82 }
|
|
83 }
|