Skip to content

Commit 250a3cb

Browse files
Adds Sybase SQL Anywhere 12 dialect and driver (for .NET 4.0) [NH-2835]
1 parent 0b184d0 commit 250a3cb

File tree

3 files changed

+195
-0
lines changed

3 files changed

+195
-0
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
/// <summary>
9+
/// SQL Dialect for SQL Anywhere 12 - for the NHibernate 3.2.0 distribution
10+
/// Copyright (C) 2011 Glenn Paulley
11+
/// Contact: http://iablog.sybase.com/paulley
12+
///
13+
/// This NHibernate dialect for SQL Anywhere 12 is a contribution to the NHibernate
14+
/// open-source project. It is intended to be included in the NHibernate
15+
/// distribution and is licensed under LGPL.
16+
///
17+
/// This library is free software; you can redistribute it and/or
18+
/// modify it under the terms of the GNU Lesser General Public
19+
/// License as published by the Free Software Foundation; either
20+
/// version 2.1 of the License, or (at your option) any later version.
21+
///
22+
/// This library is distributed in the hope that it will be useful,
23+
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
24+
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25+
/// Lesser General Public License for more details.
26+
///
27+
/// You should have received a copy of the GNU Lesser General Public
28+
/// License along with this library; if not, write to the Free Software
29+
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30+
/// </summary>
31+
/// <remarks>
32+
/// The SybaseSQLAnywhere12Dialect uses the SybaseSQLAnywhere11Dialect as its
33+
/// base class. SybaseSQLAnywhere12Dialect includes support for ISO SQL standard
34+
/// sequences, which are defined in the catalog table <tt>SYSSEQUENCE</tt>.
35+
/// The dialect uses the SybaseSQLAnywhe11MetaData class for metadata API
36+
/// calls, which correctly supports reserved words defined by SQL Anywhere.
37+
///
38+
/// The dialect defaults the following configuration properties:
39+
/// <list type="table">
40+
/// <listheader>
41+
/// <term>Property</term>
42+
/// <description>Default Value</description>
43+
/// </listheader>
44+
/// <item>
45+
/// <term>connection.driver_class</term>
46+
/// <description><see cref="NHibernate.Driver.SybaseSQLAnywhereDotNet4Driver" /></description>
47+
/// </item>
48+
/// <item>
49+
/// <term>prepare_sql</term>
50+
/// <description><see langword="false" /></description>
51+
/// </item>
52+
/// </list>
53+
/// </remarks>
54+
public class SybaseSQLAnywhere12Dialect : SybaseSQLAnywhere11Dialect
55+
{
56+
public SybaseSQLAnywhere12Dialect()
57+
: base()
58+
{
59+
DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.SybaseSQLAnywhereDotNet4Driver";
60+
RegisterDateTimeTypeMappings();
61+
RegisterKeywords();
62+
}
63+
64+
new protected void RegisterKeywords()
65+
{
66+
RegisterKeyword("NEAR");
67+
RegisterKeyword("LIMIT");
68+
RegisterKeyword("OFFSET");
69+
RegisterKeyword("DATETIMEOFFSET");
70+
}
71+
72+
new void RegisterDateTimeTypeMappings()
73+
{
74+
RegisterColumnType(DbType.DateTimeOffset, "DATETIMEOFFSET");
75+
}
76+
77+
/// <summary>
78+
/// SQL Anywhere supports <tt>SEQUENCES</tt> using a primarily SQL Standard
79+
/// syntax. Sequence values can be queried using the <tt>.CURRVAL</tt> identifier, and the next
80+
/// value in a sequence can be retrieved using the <tt>.NEXTVAL</tt> identifier. Sequences
81+
/// are retained in the SYS.SYSSEQUENCE catalog table.
82+
/// </summary>
83+
public override bool SupportsSequences
84+
{
85+
get { return true; }
86+
}
87+
88+
/// <summary>
89+
/// Pooled sequences does not refer to the CACHE parameter of the <tt>CREATE SEQUENCE</tt>
90+
/// statement, but merely if the DBMS supports sequences that can be incremented or decremented
91+
/// by values greater than 1.
92+
/// </summary>
93+
public override bool SupportsPooledSequences
94+
{
95+
get { return true; }
96+
}
97+
98+
/// <summary>Get the <tt>SELECT</tt> command used to retrieve the names of all sequences.</summary>
99+
/// <returns>The <tt>SELECT</tt> command; or NULL if sequences are not supported.</returns>
100+
public override string QuerySequencesString
101+
{
102+
get { return "SELECT SEQUENCE_NAME FROM SYS.SYSSEQUENCE"; }
103+
}
104+
105+
public override string GetSequenceNextValString(string sequenceName)
106+
{
107+
return "SELECT " + GetSelectSequenceNextValString(sequenceName) + " FROM SYS.DUMMY";
108+
}
109+
110+
public override string GetSelectSequenceNextValString(string sequenceName)
111+
{
112+
return sequenceName + ".NEXTVAL";
113+
}
114+
115+
public override string GetCreateSequenceString(string sequenceName)
116+
{
117+
return "CREATE SEQUENCE " + sequenceName; // by default, is START WITH 1 MAXVALUE 2**63-1
118+
}
119+
120+
public override string GetDropSequenceString(string sequenceName)
121+
{
122+
return "DROP SEQUENCE " + sequenceName;
123+
}
124+
125+
public override IDataBaseSchema GetDataBaseSchema(DbConnection connection)
126+
{
127+
return new SybaseAnywhereDataBaseMetaData(connection);
128+
}
129+
}
130+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
3+
namespace NHibernate.Driver
4+
{
5+
/// <summary>
6+
/// SQL Dialect for SQL Anywhere 12 - for the NHibernate 3.2.0 distribution
7+
/// Copyright (C) 2011 Glenn Paulley
8+
/// Contact: http://iablog.sybase.com/paulley
9+
///
10+
/// This NHibernate dialect for SQL Anywhere 12 is a contribution to the NHibernate
11+
/// open-source project. It is intended to be included in the NHibernate
12+
/// distribution and is licensed under LGPL.
13+
///
14+
/// This library is free software; you can redistribute it and/or
15+
/// modify it under the terms of the GNU Lesser General Public
16+
/// License as published by the Free Software Foundation; either
17+
/// version 2.1 of the License, or (at your option) any later version.
18+
///
19+
/// This library is distributed in the hope that it will be useful,
20+
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22+
/// Lesser General Public License for more details.
23+
///
24+
/// You should have received a copy of the GNU Lesser General Public
25+
/// License along with this library; if not, write to the Free Software
26+
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27+
/// </summary>
28+
/// <remarks>
29+
/// The SybaseSQLAnywhereDotNet4Driver provides a .NET 4 database driver for
30+
/// Sybase SQL Anywhere 12 using the versioned ADO.NET driver
31+
/// iAnywhere.Data.SQLAnywhere.v4.0.
32+
/// </remarks>
33+
public class SybaseSQLAnywhereDotNet4Driver : ReflectionBasedDriver
34+
{
35+
/// <summary>
36+
/// Initializes a new instance of the <see cref="SybaseSQLAnywhereDotNet4Driver"/> class.
37+
/// </summary>
38+
/// <exception cref="HibernateException">
39+
/// Thrown when the iAnywhere.Data.SQLAnywhere.v4.0 assembly is not and can not be loaded.
40+
/// </exception>
41+
public SybaseSQLAnywhereDotNet4Driver()
42+
: base(
43+
"iAnywhere.Data.SQLAnywhere", "iAnywhere.Data.SQLAnywhere.v4.0", "iAnywhere.Data.SQLAnywhere.SAConnection",
44+
"iAnywhere.Data.SQLAnywhere.SACommand")
45+
{
46+
}
47+
48+
public override bool UseNamedPrefixInSql
49+
{
50+
get { return false; }
51+
}
52+
53+
public override bool UseNamedPrefixInParameter
54+
{
55+
get { return false; }
56+
}
57+
58+
public override string NamedPrefix
59+
{
60+
get { return String.Empty; }
61+
}
62+
}
63+
}

src/NHibernate/NHibernate.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
<Compile Include="Dialect\SybaseASE15Dialect.cs" />
147147
<Compile Include="Dialect\SybaseSQLAnywhere10Dialect.cs" />
148148
<Compile Include="Dialect\SybaseSQLAnywhere11Dialect.cs" />
149+
<Compile Include="Dialect\SybaseSQLAnywhere12Dialect.cs" />
149150
<Compile Include="Dialect\TypeNames.cs" />
150151
<Compile Include="Driver\DB2Driver.cs" />
151152
<Compile Include="Driver\DriverBase.cs" />
@@ -166,6 +167,7 @@
166167
<Compile Include="Driver\SQLiteDriver.cs" />
167168
<Compile Include="Driver\SybaseAsaClientDriver.cs" />
168169
<Compile Include="Driver\SybaseAseClientDriver.cs" />
170+
<Compile Include="Driver\SybaseSQLAnywhereDotNet4Driver.cs" />
169171
<Compile Include="Driver\SybaseSQLAnywhereDriver.cs" />
170172
<Compile Include="Engine\Cascade.cs" />
171173
<Compile Include="Engine\IBatcher.cs" />

0 commit comments

Comments
 (0)