|
| 1 | +using NHibernate.SqlCommand; |
| 2 | + |
| 3 | +namespace NHibernate.Dialect |
| 4 | +{ |
| 5 | + /// <summary> |
| 6 | + /// An SQL dialect targeting Sybase Adaptive Server Enterprise (ASE) 16 and higher. |
| 7 | + /// </summary> |
| 8 | + /// <remarks> |
| 9 | + /// The dialect defaults the following configuration properties: |
| 10 | + /// <list type="table"> |
| 11 | + /// <listheader> |
| 12 | + /// <term>Property</term> |
| 13 | + /// <description>Default Value</description> |
| 14 | + /// </listheader> |
| 15 | + /// <item> |
| 16 | + /// <term>connection.driver_class</term> |
| 17 | + /// <description><see cref="NHibernate.Driver.SybaseAseClientDriver" /></description> |
| 18 | + /// </item> |
| 19 | + /// </list> |
| 20 | + /// </remarks> |
| 21 | + public class SybaseASE16Dialect : SybaseASE15Dialect |
| 22 | + { |
| 23 | + #region Limit/offset support |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Does this Dialect have some kind of <c>LIMIT</c> syntax? |
| 27 | + /// </summary> |
| 28 | + /// <value>False, unless overridden.</value> |
| 29 | + public override bool SupportsLimit |
| 30 | + { |
| 31 | + get { return true; } |
| 32 | + } |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// Does this Dialect support an offset? |
| 36 | + /// </summary> |
| 37 | + public override bool SupportsLimitOffset |
| 38 | + { |
| 39 | + get { return true; } |
| 40 | + } |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Can parameters be used for a statement containing a LIMIT? |
| 44 | + /// </summary> |
| 45 | + public override bool SupportsVariableLimit |
| 46 | + { |
| 47 | + get { return false; } |
| 48 | + } |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Attempts to add a <c>LIMIT</c> clause to the given SQL <c>SELECT</c>. |
| 52 | + /// Expects any database-specific offset and limit adjustments to have already been performed (ex. UseMaxForLimit, OffsetStartsAtOne). |
| 53 | + /// </summary> |
| 54 | + /// <param name="queryString">The <see cref="SqlString"/> to base the limit query off.</param> |
| 55 | + /// <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> |
| 56 | + /// <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> |
| 57 | + /// <returns>A new <see cref="SqlString"/> that contains the <c>LIMIT</c> clause. Returns <c>null</c> |
| 58 | + /// if <paramref name="queryString"/> represents a SQL statement to which a limit clause cannot be added, |
| 59 | + /// for example when the query string is custom SQL invoking a stored procedure.</returns> |
| 60 | + public override SqlString GetLimitString(SqlString queryString, SqlString offset, SqlString limit) |
| 61 | + { |
| 62 | + if (offset == null && limit == null) |
| 63 | + return queryString; |
| 64 | + |
| 65 | + SqlStringBuilder pagingBuilder = new SqlStringBuilder(); |
| 66 | + pagingBuilder.Add(queryString); |
| 67 | + pagingBuilder.Add(" rows "); |
| 68 | + |
| 69 | + if(limit !=null) |
| 70 | + { |
| 71 | + pagingBuilder.Add(" limit "); |
| 72 | + pagingBuilder.Add(limit); |
| 73 | + } |
| 74 | + |
| 75 | + if (offset != null) |
| 76 | + { |
| 77 | + pagingBuilder.Add(" offset "); |
| 78 | + pagingBuilder.Add(offset); |
| 79 | + } |
| 80 | + |
| 81 | + return pagingBuilder.ToSqlString(); |
| 82 | + } |
| 83 | + |
| 84 | + #endregion |
| 85 | + } |
| 86 | +} |
0 commit comments