diff --git a/jOOQ/src/main/java/org/jooq/ForInStep.java b/jOOQ/src/main/java/org/jooq/ForInStep.java index b5ccf31078..dd8c2acdc2 100644 --- a/jOOQ/src/main/java/org/jooq/ForInStep.java +++ b/jOOQ/src/main/java/org/jooq/ForInStep.java @@ -79,6 +79,18 @@ package org.jooq; + + + + + + + + + + + + diff --git a/jOOQ/src/main/java/org/jooq/impl/BlockImpl.java b/jOOQ/src/main/java/org/jooq/impl/BlockImpl.java index af97ac210c..a16ad4d01e 100644 --- a/jOOQ/src/main/java/org/jooq/impl/BlockImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/BlockImpl.java @@ -43,6 +43,7 @@ package org.jooq.impl; import static org.jooq.SQLDialect.FIREBIRD; import static org.jooq.SQLDialect.H2; import static org.jooq.SQLDialect.MARIADB; +import static org.jooq.SQLDialect.MYSQL; // ... import static org.jooq.SQLDialect.POSTGRES; import static org.jooq.conf.ParamType.INLINED; @@ -130,20 +131,6 @@ final class BlockImpl extends AbstractQuery implements Block { decrement(ctx.data(), DATA_BLOCK_NESTING); break; } -// case MARIADB: { -// if (increment(ctx.data(), DATA_BLOCK_NESTING)) { -// ctx/*.paramType(INLINED) -// */.visit(K_BEGIN).sql(' ').visit(K_NOT).sql(' ').visit(K_ATOMIC) -// .formatIndentStart(); -// -// // ctx.data(DATA_FORCE_STATIC_STATEMENT, true); -// } -// -// accept0(ctx); -// -// decrement(ctx.data(), DATA_BLOCK_NESTING); -// break; -// } @@ -195,6 +182,7 @@ final class BlockImpl extends AbstractQuery implements Block { break; } + case MARIADB: @@ -315,17 +303,8 @@ final class BlockImpl extends AbstractQuery implements Block { private static final void acceptNonDeclarations(Context ctx, List statements, boolean wrapInBeginEnd) { - if (wrapInBeginEnd) { - if (ctx.family() == H2) - ctx.sql('{'); - else - ctx.visit(K_BEGIN); - - if (ctx.family() == MARIADB) - ctx.sql(' ').visit(K_NOT).sql(' ').visit(K_ATOMIC); - - ctx.formatIndentStart(); - } + if (wrapInBeginEnd) + begin(ctx); if (statements.isEmpty()) { switch (ctx.family()) { @@ -419,6 +398,18 @@ final class BlockImpl extends AbstractQuery implements Block { end(ctx); } + private static final void begin(Context ctx) { + if (ctx.family() == H2) + ctx.sql('{'); + else + ctx.visit(K_BEGIN); + + if (ctx.family() == MARIADB && toplevel(ctx.data(), DATA_BLOCK_NESTING)) + ctx.sql(' ').visit(K_NOT).sql(' ').visit(K_ATOMIC); + + ctx.formatIndentStart(); + } + private static final void end(Context ctx) { ctx.formatIndentEnd() .formatSeparator(); diff --git a/jOOQ/src/main/java/org/jooq/impl/Continue.java b/jOOQ/src/main/java/org/jooq/impl/Continue.java index f72cc0f1ee..e3950bfabe 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Continue.java +++ b/jOOQ/src/main/java/org/jooq/impl/Continue.java @@ -124,6 +124,8 @@ package org.jooq.impl; + + diff --git a/jOOQ/src/main/java/org/jooq/impl/DeclarationImpl.java b/jOOQ/src/main/java/org/jooq/impl/DeclarationImpl.java index 20c30ad3f6..3a2bc66f1c 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DeclarationImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/DeclarationImpl.java @@ -37,105 +37,104 @@ */ package org.jooq.impl; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file +// ... +import static org.jooq.conf.ParamType.INLINED; +import static org.jooq.impl.DSL.field; +import static org.jooq.impl.Keywords.K_DECLARE; +import static org.jooq.impl.Keywords.K_DEFAULT; + +import org.jooq.Context; +// ... +import org.jooq.Field; +// ... +import org.jooq.Record1; +import org.jooq.Select; +import org.jooq.Statement; +// ... +import org.jooq.conf.ParamType; + +/** + * @author Lukas Eder + */ +@Pro +final class DeclarationImpl extends AbstractStatement implements Declaration { + + /** + * Generated UID + */ + private static final long serialVersionUID = -4976947749196983386L; + final Variable variable; + final Field value; + + DeclarationImpl(Variable variable, Field value) { + this.variable = variable; + this.value = value; + } + + @Override + public final Statement set(T v) { + return set(Tools.field(v, variable.getDataType())); + } + + @Override + public final Statement set(Field v) { + return new DeclarationImpl(variable, v); + } + + @Override + public final Statement set(Select> v) { + return set(field(v)); + } + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + case H2: + ctx.sql(BlockImpl.variableType(variable)) + .sql(' ') + .sql(variable.getName()); + + if (value instanceof ScalarSubquery) { + ctx.sql(" = null;") + .formatSeparator(); + + ctx.visit(variable.set(value)); + } + else if (value != null) + ctx.sql(" = ").visit(value); + else + ctx.sql(" = null"); + + break; + + case POSTGRES: + case ORACLE: + ctx.visit(variable).sql(' '); + Tools.toSQLDDLTypeDeclaration(ctx, variable.getDataType()); + + if (value != null) + ctx.sql(" := ").visit(value); + + break; + + case DB2: + case MARIADB: + case MYSQL: + case SQLSERVER: + default: + ctx.visit(K_DECLARE).sql(' ').visit(variable).sql(' '); + Tools.toSQLDDLTypeDeclaration(ctx, variable.getDataType()); + + ParamType previous = ctx.paramType(); + if (value != null) + if (ctx.family() == SQLSERVER) + ctx.sql(" = ").visit(value); + else + ctx.sql(' ').visit(K_DEFAULT).sql(' ').paramType(INLINED).visit(value).paramType(previous); + + break; + } + } +} + +/* [/pro] */ \ No newline at end of file diff --git a/jOOQ/src/main/java/org/jooq/impl/Exit.java b/jOOQ/src/main/java/org/jooq/impl/Exit.java index 5ad08c0e27..59d0ae935d 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Exit.java +++ b/jOOQ/src/main/java/org/jooq/impl/Exit.java @@ -125,6 +125,8 @@ package org.jooq.impl; + + diff --git a/jOOQ/src/main/java/org/jooq/impl/IfImpl.java b/jOOQ/src/main/java/org/jooq/impl/IfImpl.java index 694c3b6680..fd2e7cab83 100644 --- a/jOOQ/src/main/java/org/jooq/impl/IfImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/IfImpl.java @@ -37,7 +37,19 @@ */ package org.jooq.impl; -// ... + + + + + + + + + + + + + diff --git a/jOOQ/src/main/java/org/jooq/impl/LabelledStatement.java b/jOOQ/src/main/java/org/jooq/impl/LabelledStatement.java index 06e647668c..b22ab33d79 100644 --- a/jOOQ/src/main/java/org/jooq/impl/LabelledStatement.java +++ b/jOOQ/src/main/java/org/jooq/impl/LabelledStatement.java @@ -82,6 +82,8 @@ package org.jooq.impl; + + diff --git a/jOOQ/src/main/java/org/jooq/impl/LoopImpl.java b/jOOQ/src/main/java/org/jooq/impl/LoopImpl.java index 4b5c9ef684..e55e08b0b8 100644 --- a/jOOQ/src/main/java/org/jooq/impl/LoopImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/LoopImpl.java @@ -277,6 +277,19 @@ package org.jooq.impl; + + + + + + + + + + + + +