Skip to content

Commit

Permalink
[#7306] Added support for SELECT INTO
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaseder committed Jan 4, 2019
1 parent 00d715e commit 541dd6d
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 10 deletions.
5 changes: 5 additions & 0 deletions jOOQ/src/main/java/org/jooq/AssignmentTarget.java
Expand Up @@ -51,6 +51,11 @@

















Expand Down
9 changes: 9 additions & 0 deletions jOOQ/src/main/java/org/jooq/impl/Assignment.java
Expand Up @@ -75,6 +75,15 @@





















Expand Down
30 changes: 25 additions & 5 deletions jOOQ/src/main/java/org/jooq/impl/BlockImpl.java
Expand Up @@ -71,6 +71,7 @@
import org.jooq.Context; import org.jooq.Context;
import org.jooq.DDLQuery; import org.jooq.DDLQuery;
// ... // ...
import org.jooq.Field;
import org.jooq.SQLDialect; import org.jooq.SQLDialect;
import org.jooq.Statement; import org.jooq.Statement;


Expand Down Expand Up @@ -176,6 +177,7 @@ private final void accept0(Context<?> ctx) {
accept1(ctx, new ArrayList<Statement>(statements)); accept1(ctx, new ArrayList<Statement>(statements));
} }


@SuppressWarnings({ "rawtypes", "unchecked" })
private static final void accept1(Context<?> ctx, List<Statement> statements) { private static final void accept1(Context<?> ctx, List<Statement> statements) {




Expand All @@ -197,6 +199,20 @@ private static final void accept1(Context<?> ctx, List<Statement> statements) {


























Expand All @@ -208,6 +224,14 @@ private static final void accept1(Context<?> ctx, List<Statement> statements) {
accept2(ctx, statements); accept2(ctx, statements);
} }


private static final void semicolonAfterStatement(Context<?> ctx, Statement s) {
if (!(s instanceof Block))



ctx.sql(';');
}







Expand Down Expand Up @@ -277,11 +301,7 @@ private static final void accept2(Context<?> ctx, List<Statement> statements) {






if (!(s instanceof Block)) semicolonAfterStatement(ctx, s);



ctx.sql(';');
} }
} }


Expand Down
9 changes: 9 additions & 0 deletions jOOQ/src/main/java/org/jooq/impl/DeclarationImpl.java
Expand Up @@ -37,6 +37,15 @@
*/ */
package org.jooq.impl; package org.jooq.impl;


import static org.jooq.impl.DSL.field;














Expand Down
3 changes: 1 addition & 2 deletions jOOQ/src/main/java/org/jooq/impl/ScalarSubquery.java
Expand Up @@ -50,8 +50,7 @@
final class ScalarSubquery<T> extends AbstractField<T> { final class ScalarSubquery<T> extends AbstractField<T> {


private static final long serialVersionUID = 3463144434073231750L; private static final long serialVersionUID = 3463144434073231750L;

final Select<?> query;
private final Select<?> query;


ScalarSubquery(Select<?> query, DataType<T> type) { ScalarSubquery(Select<?> query, DataType<T> type) {
super(DSL.name("select"), type); super(DSL.name("select"), type);
Expand Down
11 changes: 8 additions & 3 deletions jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java
Expand Up @@ -167,6 +167,7 @@
import org.jooq.OrderField; import org.jooq.OrderField;
import org.jooq.Param; import org.jooq.Param;
import org.jooq.QualifiedAsterisk; import org.jooq.QualifiedAsterisk;
import org.jooq.QueryPart;
import org.jooq.Record; import org.jooq.Record;
import org.jooq.Row; import org.jooq.Row;
import org.jooq.SQLDialect; import org.jooq.SQLDialect;
Expand Down Expand Up @@ -201,7 +202,7 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
private static final EnumSet<SQLDialect> EMULATE_SELECT_INTO_AS_CTAS = EnumSet.of(CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE); private static final EnumSet<SQLDialect> EMULATE_SELECT_INTO_AS_CTAS = EnumSet.of(CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE);
private static final EnumSet<SQLDialect> NO_SUPPORT_FOR_UPDATE = EnumSet.of(CUBRID); private static final EnumSet<SQLDialect> NO_SUPPORT_FOR_UPDATE = EnumSet.of(CUBRID);
private static final EnumSet<SQLDialect> NO_SUPPORT_FOR_UPDATE_QUALIFIED = EnumSet.of(DERBY, FIREBIRD, H2, HSQLDB); private static final EnumSet<SQLDialect> NO_SUPPORT_FOR_UPDATE_QUALIFIED = EnumSet.of(DERBY, FIREBIRD, H2, HSQLDB);
private static final EnumSet<SQLDialect> SUPPORT_SELECT_INTO = EnumSet.of(HSQLDB, POSTGRES); private static final EnumSet<SQLDialect> SUPPORT_SELECT_INTO_TABLE = EnumSet.of(HSQLDB, POSTGRES);
static final EnumSet<SQLDialect> SUPPORT_WINDOW_CLAUSE = EnumSet.of(H2, MYSQL, POSTGRES, SQLITE); static final EnumSet<SQLDialect> SUPPORT_WINDOW_CLAUSE = EnumSet.of(H2, MYSQL, POSTGRES, SQLITE);
private static final EnumSet<SQLDialect> REQUIRES_FROM_CLAUSE = EnumSet.of(CUBRID, DERBY, FIREBIRD, HSQLDB, MARIADB, MYSQL); private static final EnumSet<SQLDialect> REQUIRES_FROM_CLAUSE = EnumSet.of(CUBRID, DERBY, FIREBIRD, HSQLDB, MARIADB, MYSQL);
private static final EnumSet<SQLDialect> EMULATE_EMPTY_GROUP_BY_OTHER = EnumSet.of(FIREBIRD, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE); private static final EnumSet<SQLDialect> EMULATE_EMPTY_GROUP_BY_OTHER = EnumSet.of(FIREBIRD, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE);
Expand Down Expand Up @@ -1254,13 +1255,17 @@ else if (context.subquery() && dialect == H2 && context.data(DATA_ROW_VALUE_EXPR
) { ) {
context.start(SELECT_INTO); context.start(SELECT_INTO);


Table<?> actualInto = (Table<?>) context.data(DATA_SELECT_INTO_TABLE); QueryPart actualInto = (QueryPart) context.data(DATA_SELECT_INTO_TABLE);




if (actualInto == null) if (actualInto == null)
actualInto = into; actualInto = into;


if (actualInto != null if (actualInto != null
&& context.data(DATA_OMIT_INTO_CLAUSE) == null && context.data(DATA_OMIT_INTO_CLAUSE) == null
&& SUPPORT_SELECT_INTO.contains(family)) { && (SUPPORT_SELECT_INTO_TABLE.contains(family) || !(actualInto instanceof Table))) {


context.formatSeparator() context.formatSeparator()
.visit(K_INTO) .visit(K_INTO)
Expand Down
7 changes: 7 additions & 0 deletions jOOQ/src/main/java/org/jooq/impl/Tools.java
Expand Up @@ -415,6 +415,13 @@ enum DataKey {
*/ */
DATA_SELECT_INTO_TABLE, DATA_SELECT_INTO_TABLE,









/** /**
* [#7139] No data must be selected in the <code>SELECT</code> statement. * [#7139] No data must be selected in the <code>SELECT</code> statement.
*/ */
Expand Down
7 changes: 7 additions & 0 deletions jOOQ/src/main/java/org/jooq/impl/VariableImpl.java
Expand Up @@ -67,6 +67,13 @@



















Expand Down

0 comments on commit 541dd6d

Please sign in to comment.