[#430] Add support for the Firebird database - Implement LIMIT using

ROWS .. TO, instead of FIRST .. SKIP
This commit is contained in:
Lukas Eder 2012-08-19 14:47:03 +02:00
parent 97be121d08
commit 04ab71c821
8 changed files with 38 additions and 36 deletions

View File

@ -1852,7 +1852,7 @@ SELECT * FROM BOOK OFFSET 2 ROWS FETCH NEXT 1 ROWS ONLY
SELECT * FROM BOOK OFFSET 2 FETCH FIRST 1 ROWS ONLY
-- Firebird
SELECT FIRST 1 SKIP 3 * FROM BOOK
SELECT * FROM BOOK ROWS 2 TO 3
-- Sybase SQL Anywhere
SELECT TOP 1 ROWS START AT 3 * FROM BOOK

View File

@ -136,7 +136,7 @@ public interface OrderProvider {
*
* @param numberOfRows The number of rows to return
*/
@Support({ CUBRID, DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
@Support({ CUBRID, DB2, DERBY, FIREBIRD, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
void addLimit(Param<Integer> numberOfRows);
/**
@ -171,7 +171,7 @@ public interface OrderProvider {
* @param offset The lowest offset starting at 0
* @param numberOfRows The number of rows to return
*/
@Support({ CUBRID, DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
@Support({ CUBRID, DB2, DERBY, FIREBIRD, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
void addLimit(Param<Integer> offset, int numberOfRows);
/**
@ -189,7 +189,7 @@ public interface OrderProvider {
* @param offset The lowest offset starting at 0
* @param numberOfRows The number of rows to return
*/
@Support({ CUBRID, DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
@Support({ CUBRID, DB2, DERBY, FIREBIRD, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
void addLimit(int offset, Param<Integer> numberOfRows);
/**
@ -207,7 +207,7 @@ public interface OrderProvider {
* @param offset The lowest offset starting at 0
* @param numberOfRows The number of rows to return
*/
@Support({ CUBRID, DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
@Support({ CUBRID, DB2, DERBY, FIREBIRD, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
void addLimit(Param<Integer> offset, Param<Integer> numberOfRows);
}

View File

@ -121,7 +121,7 @@ public interface SelectLimitStep extends SelectForUpdateStep {
* This is the same as calling {@link #limit(int, int)} with offset = 0, or
* calling <code>.limit(numberOfRows).offset(0)</code>
*/
@Support({ CUBRID, DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
@Support({ CUBRID, DB2, DERBY, FIREBIRD, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SelectOffsetStep limit(Param<Integer> numberOfRows);
/**
@ -150,7 +150,7 @@ public interface SelectLimitStep extends SelectForUpdateStep {
* this may be simulated with a <code>ROW_NUMBER()</code> window function
* and nested <code>SELECT</code> statements.
*/
@Support({ CUBRID, DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
@Support({ CUBRID, DB2, DERBY, FIREBIRD, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SelectForUpdateStep limit(int offset, Param<Integer> numberOfRows);
/**
@ -165,7 +165,7 @@ public interface SelectLimitStep extends SelectForUpdateStep {
* this may be simulated with a <code>ROW_NUMBER()</code> window function
* and nested <code>SELECT</code> statements.
*/
@Support({ CUBRID, DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
@Support({ CUBRID, DB2, DERBY, FIREBIRD, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SelectForUpdateStep limit(Param<Integer> offset, int numberOfRows);
/**
@ -180,6 +180,6 @@ public interface SelectLimitStep extends SelectForUpdateStep {
* this may be simulated with a <code>ROW_NUMBER()</code> window function
* and nested <code>SELECT</code> statements.
*/
@Support({ CUBRID, DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
@Support({ CUBRID, DB2, DERBY, FIREBIRD, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SelectForUpdateStep limit(Param<Integer> offset, Param<Integer> numberOfRows);
}

View File

@ -112,6 +112,6 @@ public interface SelectOffsetStep extends SelectForUpdateStep {
* simulated with a <code>ROW_NUMBER()</code> window function and nested
* <code>SELECT</code> statements.
*/
@Support({ CUBRID, DB2, DERBY, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
@Support({ CUBRID, DB2, DERBY, FIREBIRD, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SelectForUpdateStep offset(Param<Integer> offset);
}

View File

@ -97,7 +97,7 @@ public interface SimpleSelectLimitStep<R extends Record> extends SimpleSelectFor
* This is the same as calling {@link #limit(int, int)} with offset = 0, or
* calling <code>.limit(numberOfRows).offset(0)</code>
*/
@Support({ CUBRID, DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
@Support({ CUBRID, DB2, DERBY, FIREBIRD, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SimpleSelectOffsetStep<R> limit(Param<Integer> numberOfRows);
/**
@ -126,7 +126,7 @@ public interface SimpleSelectLimitStep<R extends Record> extends SimpleSelectFor
* this may be simulated with a <code>ROW_NUMBER()</code> window function and
* nested <code>SELECT</code> statements.
*/
@Support({ CUBRID, DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
@Support({ CUBRID, DB2, DERBY, FIREBIRD, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SimpleSelectForUpdateStep<R> limit(int offset, Param<Integer> numberOfRows);
/**
@ -141,7 +141,7 @@ public interface SimpleSelectLimitStep<R extends Record> extends SimpleSelectFor
* this may be simulated with a <code>ROW_NUMBER()</code> window function and
* nested <code>SELECT</code> statements.
*/
@Support({ CUBRID, DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
@Support({ CUBRID, DB2, DERBY, FIREBIRD, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SimpleSelectForUpdateStep<R> limit(Param<Integer> offset, int numberOfRows);
/**
@ -156,6 +156,6 @@ public interface SimpleSelectLimitStep<R extends Record> extends SimpleSelectFor
* this may be simulated with a <code>ROW_NUMBER()</code> window function
* and nested <code>SELECT</code> statements.
*/
@Support({ CUBRID, DB2, DERBY, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
@Support({ CUBRID, DB2, DERBY, FIREBIRD, H2, HSQLDB, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SimpleSelectForUpdateStep<R> limit(Param<Integer> offset, Param<Integer> numberOfRows);
}

View File

@ -89,6 +89,6 @@ public interface SimpleSelectOffsetStep<R extends Record> extends SimpleSelectFo
* simulated with a <code>ROW_NUMBER()</code> window function and nested
* <code>SELECT</code> statements.
*/
@Support({ CUBRID, DB2, DERBY, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
@Support({ CUBRID, DB2, DERBY, FIREBIRD, H2, HSQLDB, INGRES, MYSQL, ORACLE, POSTGRES, SQLITE, SQLSERVER, SYBASE })
SimpleSelectForUpdateStep<R> offset(Param<Integer> offset);
}

View File

@ -219,7 +219,6 @@ implements
// Sybase has TOP .. START AT support (no bind values)
// Firebird has FIRST .. SKIP support (no bind values)
case FIREBIRD:
case SYBASE: {
// Native TOP support, without OFFSET and without bind values
@ -464,7 +463,6 @@ implements
break;
}
case FIREBIRD:
case SYBASE: {
if (getLimit().isApplicable() && !getLimit().rendersParams()) {
context.sql(getLimit()).sql(" ");

View File

@ -36,6 +36,7 @@
package org.jooq.impl;
import static org.jooq.RenderContext.CastMode.NEVER;
import static org.jooq.impl.Factory.inline;
import static org.jooq.impl.Factory.val;
import org.jooq.BindContext;
@ -100,6 +101,20 @@ class Limit extends AbstractQueryPart {
break;
}
// ROWS .. TO ..
// -------------
case FIREBIRD: {
context.castMode(NEVER)
.formatSeparator()
.keyword("rows ")
.sql(getLowerRownum().add(inline(1)))
.keyword(" to ")
.sql(getUpperRownum())
.castMode(castMode);
break;
}
case DERBY: {
// Casts are not supported here...
@ -144,19 +159,6 @@ class Limit extends AbstractQueryPart {
break;
}
// Nice FIRST .. SKIP support
// --------------------------
case FIREBIRD: {
context.inline(true)
.keyword("first ")
.sql(numberOfRows)
.keyword(" skip ")
.sql(offsetOrZero)
.inline(inline);
break;
}
// Only "TOP" support provided by the following dialects.
// "OFFSET" support is simulated with nested selects
// -----------------------------------------------------------------
@ -238,6 +240,14 @@ class Limit extends AbstractQueryPart {
break;
}
// No bind variables in the FIRST .. SKIP clause
// ---------------------------------------------
case FIREBIRD: {
context.bind(getLowerRownum());
context.bind(getUpperRownum());
break;
}
// These dialects don't support bind variables at all
case ASE:
case INGRES: {
@ -261,12 +271,6 @@ class Limit extends AbstractQueryPart {
break;
}
// No bind variables in the FIRST .. SKIP clause
// ---------------------------------------------
case FIREBIRD: {
break;
}
// These dialects don't allow bind variables in their TOP clauses
// --------------------------------------------------------------
case DB2: