[#883] Fixed DDL for DB2, Firebird, Oracle
This commit is contained in:
parent
068cd10c98
commit
6b49b9472d
@ -897,7 +897,11 @@ public abstract class BaseTest<
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Sequence<? extends Number> SAuthorID() throws IllegalAccessException, NoSuchFieldException {
|
||||
return (Sequence<? extends Number>) cSequences().getField("S_AUTHOR_ID").get(cSequences());
|
||||
Class<?> sequences = cSequences();
|
||||
|
||||
return sequences == null
|
||||
? null
|
||||
: (Sequence<? extends Number>) sequences.getField("S_AUTHOR_ID").get(sequences);
|
||||
}
|
||||
|
||||
protected final Schema schema() {
|
||||
|
||||
@ -135,27 +135,27 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
public void testAlterTableAdd() throws Exception {
|
||||
try {
|
||||
// TODO: Re-use jOOQ API for this
|
||||
create().execute("create table t (a int)");
|
||||
create().execute("create table t (a " + varchar() + ")");
|
||||
create().insertInto(table("t"), field("a")).values(1).execute();
|
||||
assertEquals(asList(1), asList(create().fetchOne(table("t")).intoArray()));
|
||||
assertEquals(asList("1"), asList(create().fetchOne(table("t")).intoArray()));
|
||||
|
||||
create().alterTable("t").add("b", SQLDataType.INTEGER).execute();
|
||||
assertEquals(asList(1, null), asList(create().fetchOne(table("t")).intoArray()));
|
||||
assertEquals(asList("1", null), asList(create().fetchOne(table("t")).intoArray()));
|
||||
|
||||
create().alterTable("t").add("c", SQLDataType.NUMERIC).execute();
|
||||
assertEquals(asList(1, null, null), asList(create().fetchOne(table("t")).intoArray()));
|
||||
assertEquals(asList("1", null, null), asList(create().fetchOne(table("t")).intoArray()));
|
||||
|
||||
create().alterTable("t").add("d", SQLDataType.NUMERIC.precision(5)).execute();
|
||||
assertEquals(asList(1, null, null, null), asList(create().fetchOne(table("t")).intoArray()));
|
||||
assertEquals(asList("1", null, null, null), asList(create().fetchOne(table("t")).intoArray()));
|
||||
|
||||
create().alterTable("t").add("e", SQLDataType.NUMERIC.precision(5, 2)).execute();
|
||||
assertEquals(asList(1, null, null, null, null), asList(create().fetchOne(table("t")).intoArray()));
|
||||
assertEquals(asList("1", null, null, null, null), asList(create().fetchOne(table("t")).intoArray()));
|
||||
|
||||
create().alterTable("t").add("f", SQLDataType.VARCHAR).execute();
|
||||
assertEquals(asList(1, null, null, null, null, null), asList(create().fetchOne(table("t")).intoArray()));
|
||||
assertEquals(asList("1", null, null, null, null, null), asList(create().fetchOne(table("t")).intoArray()));
|
||||
|
||||
create().alterTable("t").add("g", SQLDataType.VARCHAR.length(5)).execute();
|
||||
assertEquals(asList(1, null, null, null, null, null, null), asList(create().fetchOne(table("t")).intoArray()));
|
||||
assertEquals(asList("1", null, null, null, null, null, null), asList(create().fetchOne(table("t")).intoArray()));
|
||||
}
|
||||
finally {
|
||||
create().dropTable("t").execute();
|
||||
@ -163,12 +163,13 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
}
|
||||
|
||||
public void testAlterTableAlterType() throws Exception {
|
||||
assumeFamilyNotIn(FIREBIRD);
|
||||
|
||||
try {
|
||||
// TODO: Re-use jOOQ API for this
|
||||
create().execute("create table t (a int)");
|
||||
create().insertInto(table("t"), field("a")).values(1).execute();
|
||||
|
||||
create().alterTable("t").alter("a").set(SQLDataType.VARCHAR).execute();
|
||||
create().insertInto(table("t"), field("a")).values("1").execute();
|
||||
assertEquals("1", create().fetchOne("select * from t").getValue(0));
|
||||
}
|
||||
finally {
|
||||
@ -179,7 +180,7 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
public void testAlterTableAlterDefault() throws Exception {
|
||||
try {
|
||||
// TODO: Re-use jOOQ API for this
|
||||
create().execute("create table t (a int, b " + SQLDataType.VARCHAR.length(10).getCastTypeName(create().configuration()) + ")");
|
||||
create().execute("create table t (a int, b " + varchar() + ")");
|
||||
|
||||
create().alterTable("t").alter("b").defaultValue("empty").execute();
|
||||
create().insertInto(table("t"), field("a")).values(1).execute();
|
||||
@ -193,15 +194,15 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
public void testAlterTableDrop() throws Exception {
|
||||
try {
|
||||
// TODO: Re-use jOOQ API for this
|
||||
create().execute("create table t (a int, b int, c int)");
|
||||
create().insertInto(table("t"), field("a"), field("b"), field("c")).values(1, 2, 3).execute();
|
||||
assertEquals(asList(1, 2, 3), asList(create().fetchOne(table("t")).intoArray()));
|
||||
create().execute("create table t (a " + varchar() + ", b " + varchar() + ", c " + varchar() + ")");
|
||||
create().insertInto(table("t"), field("a"), field("b"), field("c")).values("1", "2", "3").execute();
|
||||
assertEquals(asList("1", "2", "3"), asList(create().fetchOne(table("t")).intoArray()));
|
||||
|
||||
create().alterTable("t").drop("c").execute();
|
||||
assertEquals(asList(1, 2), asList(create().fetchOne(table("t")).intoArray()));
|
||||
assertEquals(asList("1", "2"), asList(create().fetchOne(table("t")).intoArray()));
|
||||
|
||||
create().alterTable("t").drop("b").execute();
|
||||
assertEquals(asList(1), asList(create().fetchOne(table("t")).intoArray()));
|
||||
assertEquals(asList("1"), asList(create().fetchOne(table("t")).intoArray()));
|
||||
}
|
||||
finally {
|
||||
create().dropTable("t").execute();
|
||||
@ -211,9 +212,9 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
public void testDropTable() throws Exception {
|
||||
|
||||
// TODO: Re-use jOOQ API for this
|
||||
create().execute("create table t (a int, b int, c int)");
|
||||
create().insertInto(table("t"), field("a"), field("b"), field("c")).values(1, 2, 3).execute();
|
||||
assertEquals(asList(1, 2, 3), asList(create().fetchOne(table("t")).intoArray()));
|
||||
create().execute("create table t (a " + varchar() + ", b " + varchar() + ", c " + varchar() + ")");
|
||||
create().insertInto(table("t"), field("a"), field("b"), field("c")).values("1", "2", "3").execute();
|
||||
assertEquals(asList("1", "2", "3"), asList(create().fetchOne(table("t")).intoArray()));
|
||||
|
||||
create().dropTable("t").execute();
|
||||
try {
|
||||
@ -222,4 +223,8 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
}
|
||||
catch (DataAccessException expected) {}
|
||||
}
|
||||
|
||||
private String varchar() {
|
||||
return SQLDataType.VARCHAR.length(10).getCastTypeName(create().configuration());
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,6 +57,7 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assume.assumeNotNull;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -128,15 +129,15 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
}
|
||||
|
||||
public void testSequences() throws Exception {
|
||||
assumeNotNull(SAuthorID());
|
||||
|
||||
testSequences0(SAuthorID());
|
||||
}
|
||||
|
||||
public void testSequenceByName() throws Exception {
|
||||
Sequence<? extends Number> sequence = SAuthorID();
|
||||
assumeNotNull(SAuthorID());
|
||||
|
||||
if (sequence != null) {
|
||||
testSequences0(DSL.sequenceByName(sequence.getSchema().getName(), sequence.getName()));
|
||||
}
|
||||
testSequences0(DSL.sequenceByName(SAuthorID().getSchema().getName(), SAuthorID().getName()));
|
||||
}
|
||||
|
||||
private void testSequences0(Sequence<? extends Number> sequence) {
|
||||
|
||||
@ -46,6 +46,8 @@ import static java.util.Arrays.asList;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.DERBY;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.MARIADB;
|
||||
import static org.jooq.SQLDialect.MYSQL;
|
||||
import static org.jooq.conf.StatementType.STATIC_STATEMENT;
|
||||
import static org.jooq.impl.DSL.all;
|
||||
import static org.jooq.impl.DSL.any;
|
||||
@ -527,6 +529,10 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
}
|
||||
|
||||
public void testInPredicateWithSubselectAndLimitOffset() throws Exception {
|
||||
|
||||
// This query is not yet supported in these databases
|
||||
assumeFamilyNotIn(MARIADB, MYSQL);
|
||||
|
||||
Result<Record1<Integer>> result =
|
||||
create().select(TBook_ID())
|
||||
.from(TBook())
|
||||
|
||||
@ -40,6 +40,22 @@
|
||||
*/
|
||||
package org.jooq;
|
||||
|
||||
// ...
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.CUBRID;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.DERBY;
|
||||
import static org.jooq.SQLDialect.H2;
|
||||
import static org.jooq.SQLDialect.HSQLDB;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.MARIADB;
|
||||
import static org.jooq.SQLDialect.MYSQL;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.POSTGRES;
|
||||
import static org.jooq.SQLDialect.SQLITE;
|
||||
// ...
|
||||
// ...
|
||||
|
||||
import org.jooq.api.annotation.State;
|
||||
|
||||
/**
|
||||
@ -54,15 +70,18 @@ public interface AlterTableAlterStep<T> {
|
||||
/**
|
||||
* Specify a new column <code>DEFAULT</code>.
|
||||
*/
|
||||
@Support
|
||||
AlterTableFinalStep defaultValue(T literal);
|
||||
|
||||
/**
|
||||
* Specify a new column <code>DEFAULT</code>.
|
||||
*/
|
||||
@Support
|
||||
AlterTableFinalStep defaultValue(Field<T> expression);
|
||||
|
||||
/**
|
||||
* Specify a new column data type.
|
||||
*/
|
||||
@Support({ CUBRID, DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
AlterTableFinalStep set(DataType<?> type);
|
||||
}
|
||||
|
||||
@ -55,11 +55,13 @@ public interface AlterTableDropStep extends AlterTableFinalStep {
|
||||
* Add a <code>CASCADE</code> clause to the
|
||||
* <code>ALTER TABLE .. DROP COLUMN</code> statement.
|
||||
*/
|
||||
@Support
|
||||
AlterTableFinalStep cascade();
|
||||
|
||||
/**
|
||||
* Add a <code>RESTRICT</code> clause to the
|
||||
* <code>ALTER TABLE .. DROP COLUMN</code> statement.
|
||||
*/
|
||||
@Support
|
||||
AlterTableFinalStep restrict();
|
||||
}
|
||||
|
||||
@ -54,35 +54,41 @@ public interface AlterTableStep {
|
||||
* Add an <code>ALTER COLUMN</code> clause to the <code>ALTER TABLE</code>
|
||||
* statement.
|
||||
*/
|
||||
@Support
|
||||
<T> AlterTableAlterStep<T> alter(Field<T> field);
|
||||
|
||||
/**
|
||||
* Add an <code>ALTER COLUMN</code> clause to the <code>ALTER TABLE</code>
|
||||
* statement.
|
||||
*/
|
||||
@Support
|
||||
AlterTableAlterStep<Object> alter(String field);
|
||||
|
||||
/**
|
||||
* Add an <code>ADD COLUMN</code> clause to the <code>ALTER TABLE</code>
|
||||
* statement.
|
||||
*/
|
||||
@Support
|
||||
<T> AlterTableFinalStep add(Field<T> field, DataType<T> type);
|
||||
|
||||
/**
|
||||
* Add an <code>ADD COLUMN</code> clause to the <code>ALTER TABLE</code>
|
||||
* statement.
|
||||
*/
|
||||
@Support
|
||||
AlterTableFinalStep add(String field, DataType<?> type);
|
||||
|
||||
/**
|
||||
* Add an <code>DROP COLUMN</code> clause to the <code>ALTER TABLE</code>
|
||||
* statement.
|
||||
*/
|
||||
@Support
|
||||
AlterTableDropStep drop(Field<?> field);
|
||||
|
||||
/**
|
||||
* Add an <code>DROP COLUMN</code> clause to the <code>ALTER TABLE</code>
|
||||
* statement.
|
||||
*/
|
||||
@Support
|
||||
AlterTableDropStep drop(String field);
|
||||
}
|
||||
|
||||
@ -55,11 +55,13 @@ public interface DropTableStep extends DropTableFinalStep {
|
||||
* Add a <code>CASCADE</code> clause to the <code>DROP TABLE</code>
|
||||
* statement.
|
||||
*/
|
||||
@Support
|
||||
DropTableFinalStep cascade();
|
||||
|
||||
/**
|
||||
* Add a <code>RESTRICT</code> clause to the <code>DROP TABLE</code>
|
||||
* statement.
|
||||
*/
|
||||
@Support
|
||||
DropTableFinalStep restrict();
|
||||
}
|
||||
|
||||
@ -40,15 +40,12 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.jooq.Clause.ALTER_TABLE;
|
||||
import static org.jooq.Clause.ALTER_TABLE_ADD;
|
||||
import static org.jooq.Clause.ALTER_TABLE_ALTER;
|
||||
import static org.jooq.Clause.ALTER_TABLE_ALTER_DEFAULT;
|
||||
import static org.jooq.Clause.ALTER_TABLE_DROP;
|
||||
import static org.jooq.Clause.ALTER_TABLE_TABLE;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.POSTGRES;
|
||||
import static org.jooq.impl.DSL.field;
|
||||
import static org.jooq.impl.DSL.inline;
|
||||
|
||||
@ -190,21 +187,37 @@ class AlterTableImpl extends AbstractQuery implements
|
||||
ctx.end(ALTER_TABLE_ADD);
|
||||
}
|
||||
else if (alter != null) {
|
||||
ctx.start(ALTER_TABLE_ALTER)
|
||||
.sql(" ").keyword("alter").sql(" ")
|
||||
ctx.start(ALTER_TABLE_ALTER);
|
||||
|
||||
switch (family) {
|
||||
/* [pro] xx
|
||||
xxxx xxxxxxx
|
||||
xxxxxxxxx xxxxxxxxxxxxxxxxxxxxx
|
||||
xxxxxx
|
||||
xx [/pro] */
|
||||
|
||||
default:
|
||||
ctx.sql(" ").keyword("alter");
|
||||
break;
|
||||
}
|
||||
|
||||
ctx.sql(" ")
|
||||
.qualify(false)
|
||||
.visit(alter)
|
||||
.qualify(true);
|
||||
|
||||
if (alterType != null) {
|
||||
if (asList(POSTGRES).contains(family)) {
|
||||
ctx.sql(" ").keyword("type");
|
||||
switch (family) {
|
||||
/* [pro] xx
|
||||
xxxx xxxx
|
||||
xxxxxxxxx xxxxxxxxxxxxxxx xxxx xxxxxxx
|
||||
xxxxxx
|
||||
xx [/pro] */
|
||||
|
||||
case POSTGRES:
|
||||
ctx.sql(" ").keyword("type");
|
||||
break;
|
||||
}
|
||||
/* [pro] xx
|
||||
xxxx xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x
|
||||
xxxxxxxxx xxxxxxxxxxxxxxx xxxx xxxxxxx
|
||||
x
|
||||
xx [/pro] */
|
||||
|
||||
ctx.sql(" ").keyword(alterType.getCastTypeName(ctx.configuration()));
|
||||
|
||||
@ -213,16 +226,42 @@ class AlterTableImpl extends AbstractQuery implements
|
||||
}
|
||||
}
|
||||
else if (alterDefault != null) {
|
||||
ctx.start(ALTER_TABLE_ALTER_DEFAULT)
|
||||
.sql(" ").keyword("set default").sql(" ").visit(alterDefault)
|
||||
ctx.start(ALTER_TABLE_ALTER_DEFAULT);
|
||||
|
||||
switch (family) {
|
||||
/* [pro] xx
|
||||
xxxx xxxxxxx
|
||||
xxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx
|
||||
xxxxxx
|
||||
xx [/pro] */
|
||||
|
||||
default:
|
||||
ctx.sql(" ").keyword("set default");
|
||||
break;
|
||||
}
|
||||
|
||||
ctx.sql(" ").visit(alterDefault)
|
||||
.end(ALTER_TABLE_ALTER_DEFAULT);
|
||||
}
|
||||
|
||||
ctx.end(ALTER_TABLE_ALTER);
|
||||
}
|
||||
else if (drop != null) {
|
||||
ctx.start(ALTER_TABLE_DROP)
|
||||
.sql(" ").keyword("drop").sql(" ")
|
||||
ctx.start(ALTER_TABLE_DROP);
|
||||
|
||||
switch (family) {
|
||||
/* [pro] xx
|
||||
xxxx xxxxxxx
|
||||
xxxxxxxxx xxxxxxxxxxxxxxxx xxxxxxxxx
|
||||
xxxxxx
|
||||
xx [/pro] */
|
||||
|
||||
default:
|
||||
ctx.sql(" ").keyword("drop");
|
||||
break;
|
||||
}
|
||||
|
||||
ctx.sql(" ")
|
||||
.qualify(false)
|
||||
.visit(drop)
|
||||
.qualify(true);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user