Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add Ingres v9+ Dialect

Supporting paging on Ingres DB v9+
  • Loading branch information...
commit 80358ba7ee86150bdaa9e8d961b0ffbda773f1a9 1 parent 9d339f6
Nicholas Gamble authored hazzik committed
View
28 src/NHibernate.Test/DialectTest/Ingres9DialectFixture.cs
@@ -0,0 +1,28 @@
+using NHibernate.Dialect;
+using NHibernate.SqlCommand;
+using NUnit.Framework;
+
+namespace NHibernate.Test.DialectTest
+{
+ [TestFixture]
+ public class Ingres9DialectFixture
+ {
+ [Test]
+ public void GetLimitString()
+ {
+ var d = new Ingres9Dialect();
+
+ var str = d.GetLimitString(new SqlString("SELECT * FROM fish"), null, null);
+ Assert.That(str.ToString(), Is.EqualTo("SELECT * FROM fish"));
+
+ str = d.GetLimitString(new SqlString("SELECT * FROM fish"), null, new SqlString("10"));
+ Assert.That(str.ToString(), Is.EqualTo("SELECT * FROM fish fetch first 10 rows only"));
+
+ str = d.GetLimitString(new SqlString("SELECT * FROM fish"), new SqlString("23"), null);
+ Assert.That(str.ToString(), Is.EqualTo("SELECT * FROM fish offset 23"));
+
+ str = d.GetLimitString(new SqlString("SELECT * FROM fish"), new SqlString("5"), new SqlString("15"));
+ Assert.That(str.ToString(), Is.EqualTo("SELECT * FROM fish offset 5 fetch next 15 rows only"));
+ }
+ }
+}
View
1  src/NHibernate.Test/NHibernate.Test.csproj
@@ -218,6 +218,7 @@
<Compile Include="Criteria\Reptile.cs" />
<Compile Include="DialectTest\FunctionTests\SubstringSupportFixture.cs" />
<Compile Include="DialectTest\FunctionTests\SequenceSupportFixture.cs" />
+ <Compile Include="DialectTest\Ingres9DialectFixture.cs" />
<Compile Include="DialectTest\MsSql2012DialectFixture.cs" />
<Compile Include="DialectTest\MsSqlCe40DialectFixture.cs" />
<Compile Include="DialectTest\SchemaTests\ColumnMetaDataFixture.cs" />
View
68 src/NHibernate/Dialect/Ingres9Dialect.cs
@@ -0,0 +1,68 @@
+using NHibernate.SqlCommand;
+
+namespace NHibernate.Dialect
+{
+ public class Ingres9Dialect : IngresDialect
+ {
+ /// <summary>
+ /// Does this Dialect have some kind of <c>LIMIT</c> syntax?
+ /// </summary>
+ /// <value>
+ /// False, unless overridden.
+ /// </value>
+ public override bool SupportsLimit
+ {
+ get { return true; }
+ }
+
+ /// <summary>
+ /// Can parameters be used for a statement containing a LIMIT?
+ /// </summary>
+ public override bool SupportsVariableLimit
+ {
+ get { return false; }
+ }
+
+ /// <summary>
+ /// Does this Dialect support an offset?
+ /// </summary>
+ public override bool SupportsLimitOffset
+ {
+ get { return true; }
+ }
+
+ /// <summary>
+ /// Attempts to add a <c>LIMIT</c> clause to the given SQL <c>SELECT</c>.
+ /// Expects any database-specific offset and limit adjustments to have already been performed (ex. UseMaxForLimit, OffsetStartsAtOne).
+ /// </summary>
+ /// <param name="queryString">The <see cref="SqlString"/> to base the limit query off.</param>
+ /// <param name="offset">Offset of the first row to be returned by the query. This may be represented as a parameter, a string literal, or a null value if no limit is requested. This should have already been adjusted to account for OffsetStartsAtOne.</param>
+ /// <param name="limit">Maximum number of rows to be returned by the query. This may be represented as a parameter, a string literal, or a null value if no offset is requested. This should have already been adjusted to account for UseMaxForLimit.</param>
+ /// <returns>
+ /// A new <see cref="SqlString"/> that contains the <c>LIMIT</c> clause. Returns <c>null</c>
+ /// if <paramref name="queryString"/> represents a SQL statement to which a limit clause cannot be added,
+ /// for example when the query string is custom SQL invoking a stored procedure.
+ /// </returns>
+ public override SqlString GetLimitString(SqlString queryString, SqlString offset, SqlString limit)
+ {
+ SqlStringBuilder pagingBuilder = new SqlStringBuilder();
+ pagingBuilder.Add(queryString);
+
+ if (offset != null)
+ {
+ pagingBuilder.Add(" offset ");
+ pagingBuilder.Add(offset);
+ }
+
+ if (limit != null)
+ {
+ pagingBuilder.Add(" fetch ");
+ pagingBuilder.Add(offset != null ? "next " : "first ");
+ pagingBuilder.Add(limit);
+ pagingBuilder.Add(" rows only");
+ }
+
+ return pagingBuilder.ToSqlString();
+ }
+ }
+}
View
1  src/NHibernate/NHibernate.csproj
@@ -147,6 +147,7 @@
<Compile Include="Dialect\Function\CountQueryFunctionInfo.cs" />
<Compile Include="Dialect\Function\SumQueryFunctionInfo.cs" />
<Compile Include="Dialect\GenericDialect.cs" />
+ <Compile Include="Dialect\Ingres9Dialect.cs" />
<Compile Include="Dialect\InsertGeneratedIdentifierRetrievalMethod.cs" />
<Compile Include="Dialect\MsSql2000Dialect.cs" />
<Compile Include="Dialect\MsSql2005DialectQueryPager.cs" />
Please sign in to comment.
Something went wrong with that request. Please try again.