Mercurial > pub > bltoolkit
comparison Source/Data/Sql/SqlProvider/MsSql2000SqlProvider.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f990fcb411a9 |
---|---|
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 MsSql2000SqlProvider : MsSqlSqlProvider | |
10 { | |
11 protected override string FirstFormat { get { return "TOP {0}"; } } | |
12 | |
13 public override bool IsSkipSupported { get { return false; } } | |
14 public override bool IsApplyJoinSupported { get { return false; } } | |
15 public override bool TakeAcceptsParameter { get { return false; } } | |
16 public override bool IsCountSubQuerySupported { get { return false; } } | |
17 | |
18 public override ISqlExpression ConvertExpression(ISqlExpression expr) | |
19 { | |
20 expr = base.ConvertExpression(expr); | |
21 | |
22 if (expr is SqlFunction) | |
23 { | |
24 var func = (SqlFunction)expr; | |
25 | |
26 switch (Type.GetTypeCode(TypeHelper.GetUnderlyingType(func.SystemType))) | |
27 { | |
28 case TypeCode.DateTime : | |
29 | |
30 if (func.Name == "Convert") | |
31 { | |
32 var type1 = TypeHelper.GetUnderlyingType(func.Parameters[1].SystemType); | |
33 | |
34 if (IsTimeDataType(func.Parameters[0])) | |
35 { | |
36 if (type1 == typeof(DateTime) || type1 == typeof(DateTimeOffset)) | |
37 return new SqlExpression( | |
38 func.SystemType, "Cast(Convert(Char, {0}, 114) as DateTime)", Precedence.Primary, func.Parameters[1]); | |
39 | |
40 if (func.Parameters[1].SystemType == typeof(string)) | |
41 return func.Parameters[1]; | |
42 | |
43 return new SqlExpression( | |
44 func.SystemType, "Convert(Char, {0}, 114)", Precedence.Primary, func.Parameters[1]); | |
45 } | |
46 | |
47 if (type1 == typeof(DateTime) || type1 == typeof(DateTimeOffset)) | |
48 { | |
49 if (IsDateDataType(func.Parameters[0], "Datetime")) | |
50 return new SqlExpression( | |
51 func.SystemType, "Cast(Floor(Cast({0} as Float)) as DateTime)", Precedence.Primary, func.Parameters[1]); | |
52 } | |
53 | |
54 if (func.Parameters.Length == 2 && func.Parameters[0] is SqlDataType && func.Parameters[0] == SqlDataType.DateTime) | |
55 return new SqlFunction(func.SystemType, func.Name, func.Precedence, func.Parameters[0], func.Parameters[1], new SqlValue(120)); | |
56 } | |
57 | |
58 break; | |
59 } | |
60 } | |
61 | |
62 return expr; | |
63 } | |
64 | |
65 protected override void BuildFunction(StringBuilder sb, SqlFunction func) | |
66 { | |
67 func = ConvertFunctionParameters(func); | |
68 base.BuildFunction(sb, func); | |
69 } | |
70 | |
71 protected override ISqlProvider CreateSqlProvider() | |
72 { | |
73 return new MsSql2000SqlProvider(); | |
74 } | |
75 | |
76 protected override void BuildDataType(System.Text.StringBuilder sb, SqlDataType type) | |
77 { | |
78 switch (type.SqlDbType) | |
79 { | |
80 #if !MONO | |
81 case SqlDbType.DateTimeOffset : | |
82 case SqlDbType.DateTime2 : | |
83 #endif | |
84 case SqlDbType.Time : | |
85 case SqlDbType.Date : sb.Append("DateTime"); break; | |
86 default : base.BuildDataType(sb, type); break; | |
87 } | |
88 } | |
89 } | |
90 } |