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
+ }
0 commit comments