Search in sources :

Example 1 with ParamType

use of org.jooq.conf.ParamType in project jOOQ by jOOQ.

the class Limit method accept.

@Override
public final void accept(Context<?> context) {
    ParamType paramType = context.paramType();
    CastMode castMode = context.castMode();
    switch(context.dialect()) {
        // [#4785] OFFSET cannot be without LIMIT
        case H2:
        case MARIADB:
        case MYSQL:
        case SQLITE:
            {
                context.castMode(NEVER).formatSeparator().keyword("limit").sql(' ').visit(numberOfRowsOrMax);
                if (!offsetZero())
                    context.formatSeparator().keyword("offset").sql(' ').visit(offsetOrZero);
                context.castMode(castMode);
                break;
            }
        // [#4785] OFFSET can be without LIMIT
        case HSQLDB:
        case POSTGRES:
        case POSTGRES_9_3:
        case POSTGRES_9_4:
        case POSTGRES_9_5:
            {
                context.castMode(NEVER);
                if (!limitZero())
                    context.formatSeparator().keyword("limit").sql(' ').visit(numberOfRows);
                if (!offsetZero())
                    context.formatSeparator().keyword("offset").sql(' ').visit(offsetOrZero);
                context.castMode(castMode);
                break;
            }
        // -------------------------------------------
        case CUBRID:
            {
                context.castMode(NEVER).formatSeparator().keyword("limit").sql(' ').visit(offsetOrZero).sql(", ").visit(numberOfRowsOrMax).castMode(castMode);
                break;
            }
        // -------------
        case FIREBIRD:
        case FIREBIRD_2_5:
        case FIREBIRD_3_0:
            {
                context.castMode(NEVER).formatSeparator().keyword("rows").sql(' ').visit(getLowerRownum().add(inline(1, SQLDataType.INTEGER))).sql(' ').keyword("to").sql(' ').visit(getUpperRownum()).castMode(castMode);
                break;
            }
        case DERBY:
            {
                // Casts are not supported here...
                context.castMode(NEVER).formatSeparator().keyword("offset").sql(' ').visit(offsetOrZero).sql(' ').keyword("rows");
                if (!limitZero())
                    context.sql(' ').keyword("fetch next").sql(' ').visit(numberOfRows).sql(' ').keyword("rows only");
                context.castMode(castMode);
                break;
            }
        // A default implementation is necessary for hashCode() and toString()
        default:
            {
                context.castMode(NEVER).formatSeparator().keyword("limit").sql(' ').visit(numberOfRows);
                if (!offsetZero())
                    context.sql(' ').keyword("offset").sql(' ').visit(offsetOrZero);
                context.castMode(castMode);
                break;
            }
    }
}
Also used : CastMode(org.jooq.RenderContext.CastMode) ParamType(org.jooq.conf.ParamType)

Example 2 with ParamType

use of org.jooq.conf.ParamType in project jOOQ by jOOQ.

the class CreateViewImpl method accept0.

private final void accept0(Context<?> ctx) {
    // [#3835] SQLite doesn't like renaming columns at the view level
    boolean rename = fields != null && fields.length > 0;
    boolean renameSupported = ctx.family() != SQLITE;
    // [#4806] CREATE VIEW doesn't accept parameters in most databases
    ParamType paramType = ctx.paramType();
    ctx.start(CREATE_VIEW_NAME).keyword("create view").sql(' ');
    if (ifNotExists && supportsIfNotExists(ctx))
        ctx.keyword("if not exists").sql(' ');
    ctx.visit(view);
    if (rename && renameSupported) {
        boolean qualify = ctx.qualify();
        ctx.sql('(').qualify(false).visit(new QueryPartList<Field<?>>(fields)).qualify(qualify).sql(')');
    }
    ctx.end(CREATE_VIEW_NAME).formatSeparator().keyword("as").formatSeparator().start(CREATE_VIEW_AS).paramType(INLINED).visit(rename && !renameSupported ? selectFrom(table(select).as("t", Tools.fieldNames(fields))) : select).paramType(paramType).end(CREATE_VIEW_AS);
}
Also used : Field(org.jooq.Field) ParamType(org.jooq.conf.ParamType)

Example 3 with ParamType

use of org.jooq.conf.ParamType in project jOOQ by jOOQ.

the class Val method accept.

// ------------------------------------------------------------------------
// XXX: Field API
// ------------------------------------------------------------------------
@Override
public void accept(Context<?> ctx) {
    if (ctx instanceof RenderContext) {
        ParamType paramType = ctx.paramType();
        if (isInline(ctx))
            ctx.paramType(ParamType.INLINED);
        try {
            getBinding().sql(new DefaultBindingSQLContext<T>(ctx.configuration(), ctx.data(), (RenderContext) ctx, value, getBindVariable(ctx)));
        } catch (SQLException e) {
            throw new DataAccessException("Error while generating SQL for Binding", e);
        }
        ctx.paramType(paramType);
    } else {
        // [#1302] Bind value only if it was not explicitly forced to be inlined
        if (!isInline(ctx)) {
            ctx.bindValue(value, this);
        }
    }
}
Also used : RenderContext(org.jooq.RenderContext) SQLException(java.sql.SQLException) ParamType(org.jooq.conf.ParamType) DataAccessException(org.jooq.exception.DataAccessException)

Example 4 with ParamType

use of org.jooq.conf.ParamType in project jOOQ by jOOQ.

the class CompareCondition method accept.

@Override
public final void accept(Context<?> ctx) {
    SQLDialect family = ctx.family();
    Field<?> lhs = field1;
    Field<?> rhs = field2;
    Comparator op = comparator;
    // [#293] TODO: This could apply to other operators, too
    if ((op == LIKE || op == NOT_LIKE) && field1.getType() != String.class && asList(DERBY, POSTGRES).contains(family)) {
        lhs = lhs.cast(String.class);
    } else // need to emulate this as LOWER(lhs) LIKE LOWER(rhs)
    if ((op == LIKE_IGNORE_CASE || op == NOT_LIKE_IGNORE_CASE) && POSTGRES != family) {
        lhs = lhs.lower();
        rhs = rhs.lower();
        op = (op == LIKE_IGNORE_CASE ? LIKE : NOT_LIKE);
    }
    ctx.visit(lhs).sql(' ');
    boolean castRhs = false;
    ParamType previousParamType = ctx.paramType();
    ParamType forcedParamType = previousParamType;
    ctx.keyword(op.toSQL()).sql(' ');
    if (castRhs)
        ctx.keyword("cast").sql('(');
    ctx.paramType(forcedParamType).visit(rhs).paramType(previousParamType);
    if (castRhs)
        ctx.sql(' ').keyword("as").sql(' ').keyword("varchar").sql("(4000))");
    if (escape != null) {
        ctx.sql(' ').keyword("escape").sql(' ').visit(inline(escape));
    }
}
Also used : SQLDialect(org.jooq.SQLDialect) ParamType(org.jooq.conf.ParamType) Comparator(org.jooq.Comparator)

Example 5 with ParamType

use of org.jooq.conf.ParamType in project jOOQ by jOOQ.

the class SQLInline method accept.

@Override
public final void accept(Context<?> ctx) {
    ParamType paramType = ctx.paramType();
    ctx.paramType(INLINED).visit(sql).paramType(paramType);
}
Also used : ParamType(org.jooq.conf.ParamType)

Aggregations

ParamType (org.jooq.conf.ParamType)5 SQLException (java.sql.SQLException)1 Comparator (org.jooq.Comparator)1 Field (org.jooq.Field)1 RenderContext (org.jooq.RenderContext)1 CastMode (org.jooq.RenderContext.CastMode)1 SQLDialect (org.jooq.SQLDialect)1 DataAccessException (org.jooq.exception.DataAccessException)1