forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSybaseSQLAnywhere12Dialect.cs
155 lines (139 loc) · 5.6 KB
/
SybaseSQLAnywhere12Dialect.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using System.Data;
using NHibernate.Dialect.Function;
using Environment = NHibernate.Cfg.Environment;
namespace NHibernate.Dialect
{
/// <summary>
/// SQL Dialect for SQL Anywhere 12 - for the NHibernate 3.2.0 distribution
/// Copyright (C) 2011 Glenn Paulley
/// Contact: http://iablog.sybase.com/paulley
///
/// This NHibernate dialect for SQL Anywhere 12 is a contribution to the NHibernate
/// open-source project. It is intended to be included in the NHibernate
/// distribution and is licensed under LGPL.
///
/// This library is free software; you can redistribute it and/or
/// modify it under the terms of the GNU Lesser General Public
/// License as published by the Free Software Foundation; either
/// version 2.1 of the License, or (at your option) any later version.
///
/// This library is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
/// Lesser General Public License for more details.
///
/// You should have received a copy of the GNU Lesser General Public
/// License along with this library; if not, write to the Free Software
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/// </summary>
/// <remarks>
/// The SybaseSQLAnywhere12Dialect uses the SybaseSQLAnywhere11Dialect as its
/// base class. SybaseSQLAnywhere12Dialect includes support for ISO SQL standard
/// sequences, which are defined in the catalog table <c>SYSSEQUENCE</c>.
/// The dialect uses the SybaseSQLAnywhe11MetaData class for metadata API
/// calls, which correctly supports reserved words defined by SQL Anywhere.
///
/// The dialect defaults the following configuration properties:
/// <list type="table">
/// <listheader>
/// <term>Property</term>
/// <description>Default Value</description>
/// </listheader>
/// <item>
/// <term>connection.driver_class</term>
/// <description><see cref="NHibernate.Driver.SybaseSQLAnywhereDotNet4Driver" /></description>
/// </item>
/// <item>
/// <term>prepare_sql</term>
/// <description><see langword="false" /></description>
/// </item>
/// </list>
/// </remarks>
public class SybaseSQLAnywhere12Dialect : SybaseSQLAnywhere11Dialect
{
public SybaseSQLAnywhere12Dialect()
{
DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.SybaseSQLAnywhereDotNet4Driver";
}
protected override void RegisterKeywords()
{
base.RegisterKeywords();
RegisterKeyword("near");
RegisterKeyword("limit");
RegisterKeyword("offset");
RegisterKeyword("datetimeoffset");
}
protected override void RegisterDateTimeTypeMappings()
{
base.RegisterDateTimeTypeMappings();
// Do not use the alias DATETIMEOFFSET here, as the database will translate it to its actual type name,
// causing schema validator failures.
RegisterColumnType(DbType.DateTimeOffset, "TIMESTAMP WITH TIME ZONE");
}
protected override void RegisterDateFunctions()
{
base.RegisterDateFunctions();
RegisterFunction(
"current_utctimestamp",
new SQLFunctionTemplate(NHibernateUtil.UtcDateTime, "cast(current UTC timestamp as timestamp)"));
RegisterFunction(
"current_timestamp_offset",
new NoArgSQLFunction("sysdatetimeoffset", NHibernateUtil.DateTimeOffset, true));
RegisterFunction(
"current_utctimestamp_offset",
new SQLFunctionTemplate(NHibernateUtil.DateTimeOffset, "(current UTC timestamp)"));
}
/// <summary>
/// SQL Anywhere the ANSI standard "DEFAULT VALUES" since 11.0.1 release (not 11.0.0).
/// </summary>
public override string NoColumnsInsertString => " default values ";
/// <inheritdoc />
public override string CurrentUtcTimestampSQLFunctionName => "cast(current UTC timestamp as timestamp)";
/// <inheritdoc />
public override string CurrentUtcTimestampSelectString =>
"SELECT " + CurrentUtcTimestampSQLFunctionName;
/// <inheritdoc />
public override bool SupportsCurrentUtcTimestampSelection => true;
/// <summary>
/// SQL Anywhere supports <tt>SEQUENCES</tt> using a primarily SQL Standard
/// syntax. Sequence values can be queried using the <tt>.CURRVAL</tt> identifier, and the next
/// value in a sequence can be retrieved using the <tt>.NEXTVAL</tt> identifier. Sequences
/// are retained in the SYS.SYSSEQUENCE catalog table.
/// </summary>
public override bool SupportsSequences
{
get { return true; }
}
/// <summary>
/// Pooled sequences does not refer to the CACHE parameter of the <tt>CREATE SEQUENCE</tt>
/// statement, but merely if the DBMS supports sequences that can be incremented or decremented
/// by values greater than 1.
/// </summary>
public override bool SupportsPooledSequences
{
get { return true; }
}
/// <summary>Get the <tt>SELECT</tt> command used to retrieve the names of all sequences.</summary>
/// <returns>The <tt>SELECT</tt> command; or NULL if sequences are not supported.</returns>
public override string QuerySequencesString
{
get { return "SELECT SEQUENCE_NAME FROM SYS.SYSSEQUENCE"; }
}
public override string GetSequenceNextValString(string sequenceName)
{
return "SELECT " + GetSelectSequenceNextValString(sequenceName) + " FROM SYS.DUMMY";
}
public override string GetSelectSequenceNextValString(string sequenceName)
{
return sequenceName + ".NEXTVAL";
}
public override string GetCreateSequenceString(string sequenceName)
{
return "CREATE SEQUENCE " + sequenceName; // by default, is START WITH 1 MAXVALUE 2**63-1
}
public override string GetDropSequenceString(string sequenceName)
{
return "DROP SEQUENCE " + sequenceName;
}
}
}