Skip to content

Commit 49f1359

Browse files
PetterfredericDelaporte
Petter
authored andcommitted
Added SQL Anywhere 17 support
1 parent 32537ba commit 49f1359

File tree

3 files changed

+125
-4
lines changed

3 files changed

+125
-4
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using System.Data;
2+
using System.Data.Common;
3+
using NHibernate.Dialect.Schema;
4+
using Environment = NHibernate.Cfg.Environment;
5+
6+
namespace NHibernate.Dialect
7+
{
8+
/// <remarks>
9+
/// The SapSQLAnywhere17Dialect uses the SybaseSQLAnywhere12Dialect as its
10+
/// base class. SybaseSQLAnywhere17Dialect includes support for ISO SQL standard
11+
/// sequences, which are defined in the catalog table <tt>SYSSEQUENCE</tt>.
12+
/// The dialect uses the SybaseSQLAnywhe12MetaData class for metadata API
13+
/// calls, which correctly supports reserved words defined by SQL Anywhere.
14+
///
15+
/// The dialect defaults the following configuration properties:
16+
/// <list type="table">
17+
/// <listheader>
18+
/// <term>Property</term>
19+
/// <description>Default Value</description>
20+
/// </listheader>
21+
/// <item>
22+
/// <term>connection.driver_class</term>
23+
/// <description><see cref="NHibernate.Driver.SapSQLAnywhere17Driver" /></description>
24+
/// </item>
25+
/// <item>
26+
/// <term>prepare_sql</term>
27+
/// <description><see langword="false" /></description>
28+
/// </item>
29+
/// </list>
30+
/// </remarks>
31+
public class SapSQLAnywhere17Dialect : SybaseSQLAnywhere12Dialect
32+
{
33+
public SapSQLAnywhere17Dialect()
34+
: base()
35+
{
36+
DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.SybaseSQLAnywhere17Driver";
37+
}
38+
39+
protected override void RegisterKeywords()
40+
{
41+
base.RegisterKeywords();
42+
}
43+
44+
protected override void RegisterDateTimeTypeMappings()
45+
{
46+
base.RegisterDateTimeTypeMappings();
47+
}
48+
49+
/// <summary>
50+
/// SQL Anywhere supports <tt>SEQUENCES</tt> using a primarily SQL Standard
51+
/// syntax. Sequence values can be queried using the <tt>.CURRVAL</tt> identifier, and the next
52+
/// value in a sequence can be retrieved using the <tt>.NEXTVAL</tt> identifier. Sequences
53+
/// are retained in the SYS.SYSSEQUENCE catalog table.
54+
/// </summary>
55+
public override bool SupportsSequences
56+
{
57+
get { return true; }
58+
}
59+
60+
/// <summary>
61+
/// Pooled sequences does not refer to the CACHE parameter of the <tt>CREATE SEQUENCE</tt>
62+
/// statement, but merely if the DBMS supports sequences that can be incremented or decremented
63+
/// by values greater than 1.
64+
/// </summary>
65+
public override bool SupportsPooledSequences
66+
{
67+
get { return true; }
68+
}
69+
70+
/// <summary>Get the <tt>SELECT</tt> command used to retrieve the names of all sequences.</summary>
71+
/// <returns>The <tt>SELECT</tt> command; or NULL if sequences are not supported.</returns>
72+
public override string QuerySequencesString
73+
{
74+
get { return "SELECT SEQUENCE_NAME FROM SYS.SYSSEQUENCE"; }
75+
}
76+
77+
public override string GetSequenceNextValString(string sequenceName)
78+
{
79+
return "SELECT " + GetSelectSequenceNextValString(sequenceName) + " FROM SYS.DUMMY";
80+
}
81+
82+
public override string GetSelectSequenceNextValString(string sequenceName)
83+
{
84+
return sequenceName + ".NEXTVAL";
85+
}
86+
87+
public override string GetCreateSequenceString(string sequenceName)
88+
{
89+
return "CREATE SEQUENCE " + sequenceName; // by default, is START WITH 1 MAXVALUE 2**63-1
90+
}
91+
92+
public override string GetDropSequenceString(string sequenceName)
93+
{
94+
return "DROP SEQUENCE " + sequenceName;
95+
}
96+
97+
public override IDataBaseSchema GetDataBaseSchema(DbConnection connection)
98+
{
99+
return new SybaseAnywhereDataBaseMetaData(connection);
100+
}
101+
}
102+
}

src/NHibernate/Dialect/SybaseSQLAnywhere12Dialect.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,20 @@ public SybaseSQLAnywhere12Dialect()
5757
: base()
5858
{
5959
DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.SybaseSQLAnywhereDotNet4Driver";
60-
RegisterDateTimeTypeMappings();
61-
RegisterKeywords();
6260
}
6361

64-
new protected void RegisterKeywords()
62+
protected override void RegisterKeywords()
6563
{
64+
base.RegisterKeywords();
6665
RegisterKeyword("near");
6766
RegisterKeyword("limit");
6867
RegisterKeyword("offset");
6968
RegisterKeyword("datetimeoffset");
7069
}
7170

72-
new void RegisterDateTimeTypeMappings()
71+
protected override void RegisterDateTimeTypeMappings()
7372
{
73+
base.RegisterDateTimeTypeMappings();
7474
RegisterColumnType(DbType.DateTimeOffset, "DATETIMEOFFSET");
7575
}
7676

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace NHibernate.Driver
2+
{
3+
public class SapSQLAnywhere17Driver : ReflectionBasedDriver
4+
{
5+
public SapSQLAnywhere17Driver()
6+
: base("Sap.Data.SQLAnywhere", "Sap.Data.SQLAnywhere.v4.5", "Sap.Data.SQLAnywhere.SAConnection", "Sap.Data.SQLAnywhere.SACommand")
7+
{
8+
9+
}
10+
11+
public override bool UseNamedPrefixInSql => true;
12+
13+
public override bool UseNamedPrefixInParameter => true;
14+
15+
public override string NamedPrefix => ":";
16+
17+
public override bool RequiresTimeSpanForTime => true;
18+
}
19+
}

0 commit comments

Comments
 (0)