-
Notifications
You must be signed in to change notification settings - Fork 936
/
Copy pathNpgsqlDriver.cs
97 lines (82 loc) · 2.91 KB
/
NpgsqlDriver.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
using System.Data;
using System.Data.Common;
using NHibernate.AdoNet;
namespace NHibernate.Driver
{
/// <summary>
/// The PostgreSQL data provider provides a database driver for PostgreSQL.
/// <p>
/// Author: <a href="mailto:[email protected]">Oliver Weichhold</a>
/// </p>
/// </summary>
/// <remarks>
/// <p>
/// In order to use this Driver you must have the Npgsql.dll Assembly available for
/// NHibernate to load it.
/// </p>
/// <p>
/// Please check the products website
/// <a href="http://www.postgresql.org/">http://www.postgresql.org/</a>
/// for any updates and or documentation.
/// </p>
/// <p>
/// The homepage for the .NET DataProvider is:
/// <a href="http://pgfoundry.org/projects/npgsql">http://pgfoundry.org/projects/npgsql</a>.
/// </p>
/// </remarks>
public class NpgsqlDriver : ReflectionBasedDriver, IEmbeddedBatcherFactoryProvider
{
/// <summary>
/// Initializes a new instance of the <see cref="NpgsqlDriver"/> class.
/// </summary>
/// <exception cref="HibernateException">
/// Thrown when the <c>Npgsql</c> assembly can not be loaded.
/// </exception>
public NpgsqlDriver() : base(
"Npgsql",
"Npgsql",
"Npgsql.NpgsqlConnection",
"Npgsql.NpgsqlCommand")
{
}
public override bool UseNamedPrefixInSql => true;
public override bool UseNamedPrefixInParameter => true;
public override string NamedPrefix => ":";
public override bool SupportsMultipleOpenReaders => false;
/// <remarks>
/// NH-2267 Patrick Earl
/// </remarks>
protected override bool SupportsPreparingCommands => true;
public override bool SupportsNullEnlistment => false;
public override IResultSetsCommand GetResultSetsCommand(Engine.ISessionImplementor session)
{
return new BasicResultSetsCommand(session);
}
public override bool SupportsMultipleQueries => true;
protected override void InitializeParameter(DbParameter dbParam, string name, SqlTypes.SqlType sqlType)
{
if (sqlType == null)
throw new QueryException($"No type assigned to parameter '{name}'");
dbParam.ParameterName = FormatNameForParameter(name);
if (sqlType.DbType == DbType.Currency)
{
// Since the .NET currency type has 4 decimal places, we use a decimal type in PostgreSQL instead of its native 2 decimal currency type.
dbParam.DbType = DbType.Decimal;
}
else if (DriverVersionMajor < 6 || sqlType.DbType != DbType.DateTime)
{
dbParam.DbType = sqlType.DbType;
}
else
{
// Let Npgsql 6 driver to decide parameter type
}
}
// Prior to v3, Npgsql was expecting DateTime for time.
// https://github.com/npgsql/npgsql/issues/347
public override bool RequiresTimeSpanForTime => DriverVersionMajor >= 3;
public override bool HasDelayedDistributedTransactionCompletion => true;
System.Type IEmbeddedBatcherFactoryProvider.BatcherFactoryClass => typeof(GenericBatchingBatcherFactory);
private int DriverVersionMajor => DriverVersion?.Major ?? 3;
}
}