[#8421] Support various DDL statements in Informix
This commit is contained in:
parent
de302f0cc5
commit
6965dd4d1f
@ -49,6 +49,7 @@ import static org.jooq.SQLDialect.FIREBIRD;
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
import static org.jooq.impl.DSL.index;
|
||||
import static org.jooq.impl.DSL.inline;
|
||||
import static org.jooq.impl.DSL.name;
|
||||
|
||||
@ -54,6 +54,7 @@ import static org.jooq.SQLDialect.FIREBIRD;
|
||||
import static org.jooq.impl.Keywords.K_ALTER;
|
||||
import static org.jooq.impl.Keywords.K_IF_EXISTS;
|
||||
import static org.jooq.impl.Keywords.K_RENAME;
|
||||
import static org.jooq.impl.Keywords.K_RENAME_SEQUENCE;
|
||||
import static org.jooq.impl.Keywords.K_RENAME_TO;
|
||||
import static org.jooq.impl.Keywords.K_RESTART;
|
||||
import static org.jooq.impl.Keywords.K_RESTART_WITH;
|
||||
@ -175,6 +176,7 @@ final class AlterSequenceImpl<T extends Number> extends AbstractQuery implements
|
||||
|
||||
|
||||
|
||||
|
||||
default:
|
||||
accept1(ctx);
|
||||
break;
|
||||
|
||||
@ -62,6 +62,7 @@ import static org.jooq.SQLDialect.DERBY;
|
||||
import static org.jooq.SQLDialect.FIREBIRD;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.HSQLDB;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.MARIADB;
|
||||
import static org.jooq.SQLDialect.MYSQL;
|
||||
// ...
|
||||
@ -84,6 +85,7 @@ import static org.jooq.impl.Keywords.K_ALTER_TABLE;
|
||||
import static org.jooq.impl.Keywords.K_CASCADE;
|
||||
import static org.jooq.impl.Keywords.K_CHANGE_COLUMN;
|
||||
import static org.jooq.impl.Keywords.K_COMMENT;
|
||||
import static org.jooq.impl.Keywords.K_CONSTRAINT;
|
||||
import static org.jooq.impl.Keywords.K_DEFAULT;
|
||||
import static org.jooq.impl.Keywords.K_DROP;
|
||||
import static org.jooq.impl.Keywords.K_DROP_COLUMN;
|
||||
@ -182,6 +184,7 @@ final class AlterTableImpl extends AbstractQuery implements
|
||||
private static final Clause[] CLAUSES = { ALTER_TABLE };
|
||||
private static final EnumSet<SQLDialect> NO_SUPPORT_IF_EXISTS = EnumSet.of(CUBRID, DERBY, FIREBIRD, MARIADB);
|
||||
private static final EnumSet<SQLDialect> NO_SUPPORT_IF_EXISTS_COLUMN = EnumSet.of(CUBRID, DERBY, FIREBIRD);
|
||||
private static final EnumSet<SQLDialect> SUPPORT_RENAME_COLUMN = EnumSet.of(DERBY);
|
||||
private static final EnumSet<SQLDialect> SUPPORT_RENAME_TABLE = EnumSet.of(DERBY);
|
||||
private static final EnumSet<SQLDialect> NO_SUPPORT_RENAME_QUALIFIED_TABLE = EnumSet.of(POSTGRES);
|
||||
private static final EnumSet<SQLDialect> NO_SUPPORT_ALTER_TYPE_AND_NULL = EnumSet.of(POSTGRES);
|
||||
@ -196,6 +199,8 @@ final class AlterTableImpl extends AbstractQuery implements
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private final Table<?> table;
|
||||
private final boolean ifExists;
|
||||
private boolean ifExistsColumn;
|
||||
@ -779,7 +784,7 @@ final class AlterTableImpl extends AbstractQuery implements
|
||||
|
||||
boolean omitAlterTable =
|
||||
(renameConstraint != null && family == HSQLDB)
|
||||
|| (renameColumn != null && family == DERBY);
|
||||
|| (renameColumn != null && SUPPORT_RENAME_COLUMN.contains(family));
|
||||
boolean renameTable = renameTo != null && SUPPORT_RENAME_TABLE.contains(family);
|
||||
boolean renameObject = renameTo != null && (false );
|
||||
|
||||
@ -824,6 +829,9 @@ final class AlterTableImpl extends AbstractQuery implements
|
||||
ctx.start(ALTER_TABLE_RENAME_COLUMN);
|
||||
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
|
||||
case DERBY:
|
||||
ctx.visit(K_RENAME_COLUMN).sql(' ')
|
||||
.visit(renameColumn)
|
||||
@ -1011,8 +1019,15 @@ final class AlterTableImpl extends AbstractQuery implements
|
||||
ctx.start(ALTER_TABLE_ADD);
|
||||
|
||||
ctx.visit(K_ADD)
|
||||
.sql(' ')
|
||||
.visit(addConstraint);
|
||||
.sql(' ');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ctx.visit(addConstraint);
|
||||
|
||||
|
||||
|
||||
@ -1173,6 +1188,7 @@ final class AlterTableImpl extends AbstractQuery implements
|
||||
|
||||
|
||||
|
||||
|
||||
ctx.sql(' ');
|
||||
|
||||
ctx.qualify(false)
|
||||
|
||||
@ -71,6 +71,7 @@ final class ConstantSortField<T> extends CustomField<T> {
|
||||
|
||||
|
||||
|
||||
|
||||
case DERBY:
|
||||
case HSQLDB:
|
||||
case POSTGRES:
|
||||
|
||||
@ -40,6 +40,8 @@ package org.jooq.impl;
|
||||
import static java.lang.Boolean.TRUE;
|
||||
import static org.jooq.Clause.CONSTRAINT;
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
import static org.jooq.impl.ConstraintImpl.Action.CASCADE;
|
||||
import static org.jooq.impl.ConstraintImpl.Action.NO_ACTION;
|
||||
import static org.jooq.impl.ConstraintImpl.Action.RESTRICT;
|
||||
@ -61,6 +63,8 @@ import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
import static org.jooq.impl.Tools.fieldsByName;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_CONSTRAINT_REFERENCE;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.jooq.Clause;
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.ConstraintForeignKeyOnStep;
|
||||
@ -92,6 +96,8 @@ import org.jooq.Context;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.Keyword;
|
||||
import org.jooq.Name;
|
||||
// ...
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
|
||||
@ -136,8 +142,14 @@ implements
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = 1018023703769802616L;
|
||||
private static final Clause[] CLAUSES = { CONSTRAINT };
|
||||
private static final long serialVersionUID = 1018023703769802616L;
|
||||
private static final Clause[] CLAUSES = { CONSTRAINT };
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private Field<?>[] unique;
|
||||
private Field<?>[] primaryKey;
|
||||
@ -176,12 +188,13 @@ implements
|
||||
else {
|
||||
boolean qualify = ctx.qualify();
|
||||
|
||||
if (getQualifiedName() != AbstractName.NO_NAME)
|
||||
if (getQualifiedName() != AbstractName.NO_NAME ) {
|
||||
ctx.visit(K_CONSTRAINT)
|
||||
.sql(' ')
|
||||
.visit(getUnqualifiedName())
|
||||
.formatIndentStart()
|
||||
.formatSeparator();
|
||||
}
|
||||
|
||||
if (unique != null) {
|
||||
ctx.visit(K_UNIQUE)
|
||||
@ -235,12 +248,18 @@ implements
|
||||
.sql(')');
|
||||
|
||||
if (onDelete != null)
|
||||
ctx.sql(' ').visit(K_ON_DELETE)
|
||||
.sql(' ').visit(onDelete.keyword);
|
||||
|
||||
|
||||
|
||||
ctx.sql(' ').visit(K_ON_DELETE)
|
||||
.sql(' ').visit(onDelete.keyword);
|
||||
|
||||
if (onUpdate != null)
|
||||
ctx.sql(' ').visit(K_ON_UPDATE)
|
||||
.sql(' ').visit(onUpdate.keyword);
|
||||
|
||||
|
||||
|
||||
ctx.sql(' ').visit(K_ON_UPDATE)
|
||||
.sql(' ').visit(onUpdate.keyword);
|
||||
}
|
||||
else if (check != null) {
|
||||
ctx.visit(K_CHECK)
|
||||
@ -251,8 +270,19 @@ implements
|
||||
.sql(')');
|
||||
}
|
||||
|
||||
if (getQualifiedName() != AbstractName.NO_NAME)
|
||||
if (getQualifiedName() != AbstractName.NO_NAME) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ctx.formatIndentEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -229,6 +229,12 @@ final class CreateSequenceImpl extends AbstractQuery implements
|
||||
.sql(' ');
|
||||
|
||||
ctx.visit(sequence);
|
||||
String noSeparator = " ";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Some databases default to sequences starting with MIN_VALUE
|
||||
if (startWith == null && REQUIRES_START_WITH.contains(ctx.family()))
|
||||
@ -242,23 +248,23 @@ final class CreateSequenceImpl extends AbstractQuery implements
|
||||
if (minvalue != null)
|
||||
ctx.sql(' ').visit(K_MINVALUE).sql(' ').visit(minvalue);
|
||||
else if (noMinvalue)
|
||||
ctx.sql(' ').visit(K_NO).sql(' ').visit(K_MINVALUE);
|
||||
ctx.sql(' ').visit(K_NO).sql(noSeparator).visit(K_MINVALUE);
|
||||
|
||||
if (maxvalue != null)
|
||||
ctx.sql(' ').visit(K_MAXVALUE).sql(' ').visit(maxvalue);
|
||||
else if (noMaxvalue)
|
||||
ctx.sql(' ').visit(K_NO).sql(' ').visit(K_MAXVALUE);
|
||||
ctx.sql(' ').visit(K_NO).sql(noSeparator).visit(K_MAXVALUE);
|
||||
|
||||
if (cycle)
|
||||
ctx.sql(' ').visit(K_CYCLE);
|
||||
else if (noCycle)
|
||||
ctx.sql(' ').visit(K_NO).sql(' ').visit(K_CYCLE);
|
||||
ctx.sql(' ').visit(K_NO).sql(noSeparator).visit(K_CYCLE);
|
||||
|
||||
if (!NO_SUPPORT_CACHE.contains(ctx.family()))
|
||||
if (cache != null)
|
||||
ctx.sql(' ').visit(K_CACHE).sql(' ').visit(cache);
|
||||
else if (noCache)
|
||||
ctx.sql(' ').visit(K_NO).sql(' ').visit(K_CACHE);
|
||||
ctx.sql(' ').visit(K_NO).sql(noSeparator).visit(K_CACHE);
|
||||
|
||||
ctx.end(CREATE_SEQUENCE_SEQUENCE);
|
||||
}
|
||||
|
||||
@ -48,6 +48,7 @@ import static org.jooq.SQLDialect.DERBY;
|
||||
import static org.jooq.SQLDialect.FIREBIRD;
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.POSTGRES;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.SQLITE;
|
||||
@ -64,6 +65,7 @@ import static org.jooq.impl.Keywords.K_IF_NOT_EXISTS;
|
||||
import static org.jooq.impl.Keywords.K_OR;
|
||||
import static org.jooq.impl.Keywords.K_REPLACE;
|
||||
import static org.jooq.impl.Keywords.K_VIEW;
|
||||
import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
@ -172,12 +174,21 @@ final class CreateViewImpl<R extends Record> extends AbstractQuery implements
|
||||
}
|
||||
|
||||
private final void accept0(Context<?> ctx) {
|
||||
Field<?>[] f = fields;
|
||||
|
||||
// [#3835] SQLite doesn't like renaming columns at the view level
|
||||
boolean rename = fields != null && fields.length > 0;
|
||||
boolean rename = f != null && f.length > 0;
|
||||
boolean renameSupported = ctx.family() != SQLITE;
|
||||
boolean replaceSupported = false ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// [#4806] CREATE VIEW doesn't accept parameters in most databases
|
||||
ParamType paramType = ctx.paramType();
|
||||
|
||||
@ -215,7 +226,7 @@ final class CreateViewImpl<R extends Record> extends AbstractQuery implements
|
||||
|
||||
ctx.sql('(')
|
||||
.qualify(false)
|
||||
.visit(new QueryPartList<Field<?>>(fields))
|
||||
.visit(new QueryPartList<Field<?>>(f))
|
||||
.qualify(qualify)
|
||||
.sql(')');
|
||||
}
|
||||
@ -228,7 +239,7 @@ final class CreateViewImpl<R extends Record> extends AbstractQuery implements
|
||||
.paramType(INLINED)
|
||||
.visit(
|
||||
rename && !renameSupported
|
||||
? selectFrom(table(select).as(name("t"), Tools.fieldNames(fields)))
|
||||
? selectFrom(table(select).as(name("t"), Tools.fieldNames(f)))
|
||||
: select)
|
||||
.paramType(paramType)
|
||||
.end(CREATE_VIEW_AS);
|
||||
|
||||
@ -195,6 +195,7 @@ final class Keywords {
|
||||
static final Keyword K_MINUS = keyword("minus");
|
||||
static final Keyword K_MINVALUE = keyword("minvalue");
|
||||
static final Keyword K_MODIFY = keyword("modify");
|
||||
static final Keyword K_MULTISET = keyword("multiset");
|
||||
static final Keyword K_NEW_TABLE = keyword("new table");
|
||||
static final Keyword K_NO = keyword("no");
|
||||
static final Keyword K_NOCYCLE = keyword("nocycle");
|
||||
@ -247,6 +248,7 @@ final class Keywords {
|
||||
static final Keyword K_RENAME_CONSTRAINT = keyword("rename constraint");
|
||||
static final Keyword K_RENAME_INDEX = keyword("rename index");
|
||||
static final Keyword K_RENAME_OBJECT = keyword("rename object");
|
||||
static final Keyword K_RENAME_SEQUENCE = keyword("rename sequence");
|
||||
static final Keyword K_RENAME_TABLE = keyword("rename table");
|
||||
static final Keyword K_RENAME_TO = keyword("rename to");
|
||||
static final Keyword K_REPEAT = keyword("repeat");
|
||||
|
||||
@ -79,6 +79,7 @@ final class RowIdField extends AbstractField<RowId> {
|
||||
|
||||
|
||||
|
||||
|
||||
case SQLITE:
|
||||
default:
|
||||
ctx.visit(getQualifiedName());
|
||||
|
||||
@ -664,6 +664,10 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1571,11 +1575,13 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
|
||||
}
|
||||
|
||||
private final void toSQLOrderBy(
|
||||
Context<?> ctx,
|
||||
Field<?>[] originalFields, Field<?>[] alternativeFields,
|
||||
boolean wrapQueryExpressionInDerivedTable, boolean wrapQueryExpressionBodyInDerivedTable,
|
||||
SortFieldList actualOrderBy,
|
||||
Limit actualLimit
|
||||
Context<?> ctx,
|
||||
Field<?>[] originalFields,
|
||||
Field<?>[] alternativeFields,
|
||||
boolean wrapQueryExpressionInDerivedTable,
|
||||
boolean wrapQueryExpressionBodyInDerivedTable,
|
||||
SortFieldList actualOrderBy,
|
||||
Limit actualLimit
|
||||
) {
|
||||
|
||||
ctx.start(SELECT_ORDER_BY);
|
||||
|
||||
@ -49,6 +49,7 @@ import static org.jooq.SQLDialect.CUBRID;
|
||||
import static org.jooq.SQLDialect.DERBY;
|
||||
import static org.jooq.SQLDialect.FIREBIRD;
|
||||
import static org.jooq.SQLDialect.HSQLDB;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.MARIADB;
|
||||
import static org.jooq.SQLDialect.MYSQL;
|
||||
// ...
|
||||
|
||||
Loading…
Reference in New Issue
Block a user