-
Notifications
You must be signed in to change notification settings - Fork 934
/
Copy pathSqlServerCeDriver.cs
129 lines (114 loc) · 3.88 KB
/
SqlServerCeDriver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Data;
using System.Data.Common;
using NHibernate.SqlTypes;
using NHibernate.Util;
namespace NHibernate.Driver
{
/// <summary>
/// A NHibernate driver for Microsoft SQL Server CE data provider
/// </summary>
public class SqlServerCeDriver : ReflectionBasedDriver
{
private static readonly Action<object, SqlDbType> SetSqlDbType =
DelegateHelper.BuildPropertySetter<SqlDbType>(
ReflectHelper.TypeFromAssembly("System.Data.SqlServerCe.SqlCeParameter", "System.Data.SqlServerCe", true),
"SqlDbType");
/// <summary>
/// Initializes a new instance of the <see cref="SqlServerCeDriver"/> class.
/// </summary>
public SqlServerCeDriver()
: base(
"System.Data.SqlServerCe",
"System.Data.SqlServerCe.SqlCeConnection",
"System.Data.SqlServerCe.SqlCeCommand")
{
}
/// <summary>
/// MsSql requires the use of a Named Prefix in the SQL statement.
/// </summary>
/// <remarks>
/// <see langword="true" /> because MsSql uses "<c>@</c>".
/// </remarks>
public override bool UseNamedPrefixInSql => true;
/// <summary>
/// MsSql requires the use of a Named Prefix in the Parameter.
/// </summary>
/// <remarks>
/// <see langword="true" /> because MsSql uses "<c>@</c>".
/// </remarks>
public override bool UseNamedPrefixInParameter => true;
/// <summary>
/// The Named Prefix for parameters.
/// </summary>
/// <value>
/// Sql Server uses <c>"@"</c>.
/// </value>
public override string NamedPrefix => "@";
/// <summary>
/// The SqlClient driver does NOT support more than 1 open DbDataReader
/// with only 1 DbConnection.
/// </summary>
/// <value><see langword="false" /> - it is not supported.</value>
/// <remarks>
/// Ms Sql 2000 (and 7) throws an Exception when multiple DataReaders are
/// attempted to be Opened. When Yukon comes out a new Driver will be
/// created for Yukon because it is supposed to support it.
/// </remarks>
public override bool SupportsMultipleOpenReaders => false;
protected override void SetCommandTimeout(DbCommand cmd)
{
}
public override IResultSetsCommand GetResultSetsCommand(Engine.ISessionImplementor session)
{
return new BasicResultSetsCommand(session);
}
protected override void InitializeParameter(DbParameter dbParam, string name, SqlType sqlType)
{
base.InitializeParameter(dbParam, name, AdjustSqlType(sqlType));
// For types that are using one character (CharType, AnsiCharType, TrueFalseType, YesNoType and EnumCharType),
// we have to specify the length otherwise sql function like charindex won't work as expected.
if (sqlType.LengthDefined && sqlType.Length == 1)
{
dbParam.Size = sqlType.Length;
}
AdjustDbParamTypeForLargeObjects(dbParam, sqlType);
}
private static SqlType AdjustSqlType(SqlType sqlType)
{
switch (sqlType.DbType)
{
case DbType.AnsiString:
return new StringSqlType(sqlType.Length);
case DbType.AnsiStringFixedLength:
return new StringFixedLengthSqlType(sqlType.Length);
case DbType.Date:
return SqlTypeFactory.DateTime;
case DbType.Time:
return SqlTypeFactory.DateTime;
default:
return sqlType;
}
}
private void AdjustDbParamTypeForLargeObjects(DbParameter dbParam, SqlType sqlType)
{
if (sqlType is BinaryBlobSqlType)
{
SetSqlDbType(dbParam, SqlDbType.Image);
}
else if (sqlType is StringClobSqlType)
{
SetSqlDbType(dbParam, SqlDbType.NText);
}
}
public override bool SupportsNullEnlistment => false;
/// <summary>
/// <see langword="false"/>. Enlistment is completely disabled when auto-enlistment is disabled.
/// <see cref="DbConnection.EnlistTransaction(System.Transactions.Transaction)"/> does nothing in
/// this case.
/// </summary>
public override bool SupportsEnlistmentWhenAutoEnlistmentIsDisabled => false;
/// <inheritdoc />
public override DateTime MinDate => new DateTime(1753, 1, 1);
}
}