[#6994] Emulate COMMENT ON TABLE in MySQL
This commit is contained in:
parent
132a1ef71e
commit
8a545cfab9
@ -41,6 +41,8 @@ package org.jooq;
|
||||
import static org.jooq.SQLDialect.FIREBIRD;
|
||||
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;
|
||||
|
||||
@ -55,12 +57,12 @@ public interface CommentOnIsStep {
|
||||
/**
|
||||
* Specify the comment for the given object type.
|
||||
*/
|
||||
@Support({ FIREBIRD, H2, HSQLDB, POSTGRES })
|
||||
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
|
||||
CommentOnFinalStep is(String comment);
|
||||
|
||||
/**
|
||||
* Specify the comment for the given object type.
|
||||
*/
|
||||
@Support({ FIREBIRD, H2, HSQLDB, POSTGRES })
|
||||
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
|
||||
CommentOnFinalStep is(Comment comment);
|
||||
}
|
||||
|
||||
@ -8441,7 +8441,7 @@ public interface DSLContext extends Scope , AutoCloseable {
|
||||
*
|
||||
* @see DSL#commentOnTable(String)
|
||||
*/
|
||||
@Support({ FIREBIRD, H2, HSQLDB, POSTGRES })
|
||||
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
|
||||
CommentOnIsStep commentOnTable(String tableName);
|
||||
|
||||
/**
|
||||
@ -8449,7 +8449,7 @@ public interface DSLContext extends Scope , AutoCloseable {
|
||||
*
|
||||
* @see DSL#commentOnTable(Name)
|
||||
*/
|
||||
@Support({ FIREBIRD, H2, HSQLDB, POSTGRES })
|
||||
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
|
||||
CommentOnIsStep commentOnTable(Name tableName);
|
||||
|
||||
/**
|
||||
@ -8457,7 +8457,7 @@ public interface DSLContext extends Scope , AutoCloseable {
|
||||
*
|
||||
* @see DSL#commentOnTable(Table)
|
||||
*/
|
||||
@Support({ FIREBIRD, H2, HSQLDB, POSTGRES })
|
||||
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
|
||||
CommentOnIsStep commentOnTable(Table<?> table);
|
||||
|
||||
/**
|
||||
|
||||
@ -38,6 +38,7 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.DSL.comment;
|
||||
import static org.jooq.impl.Keywords.K_ALTER_TABLE;
|
||||
import static org.jooq.impl.Keywords.K_COLUMN;
|
||||
import static org.jooq.impl.Keywords.K_COMMENT;
|
||||
import static org.jooq.impl.Keywords.K_IS;
|
||||
@ -86,6 +87,29 @@ implements
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
case MARIADB:
|
||||
case MYSQL: {
|
||||
if (table != null)
|
||||
acceptMySQL(ctx);
|
||||
else
|
||||
acceptDefault(ctx);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
acceptDefault(ctx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final void acceptMySQL(Context<?> ctx) {
|
||||
ctx.visit(K_ALTER_TABLE).sql(' ').visit(table).sql(' ').visit(K_COMMENT).sql(" = ").visit(comment);
|
||||
}
|
||||
|
||||
private final void acceptDefault(Context<?> ctx) {
|
||||
ctx.visit(K_COMMENT).sql(' ').visit(K_ON).sql(' ');
|
||||
|
||||
if (table != null)
|
||||
|
||||
@ -5827,7 +5827,7 @@ public class DSL {
|
||||
*
|
||||
* @see DSLContext#commentOnTable(String)
|
||||
*/
|
||||
@Support({ FIREBIRD, H2, HSQLDB, POSTGRES })
|
||||
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
|
||||
public static CommentOnIsStep commentOnTable(String tableName) {
|
||||
return using(new DefaultConfiguration()).commentOnTable(tableName);
|
||||
}
|
||||
@ -5837,7 +5837,7 @@ public class DSL {
|
||||
*
|
||||
* @see DSLContext#commentOnTable(Name)
|
||||
*/
|
||||
@Support({ FIREBIRD, H2, HSQLDB, POSTGRES })
|
||||
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
|
||||
public static CommentOnIsStep commentOnTable(Name tableName) {
|
||||
return using(new DefaultConfiguration()).commentOnTable(tableName);
|
||||
}
|
||||
@ -5847,7 +5847,7 @@ public class DSL {
|
||||
*
|
||||
* @see DSLContext#commentOnTable(Table)
|
||||
*/
|
||||
@Support({ FIREBIRD, H2, HSQLDB, POSTGRES })
|
||||
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
|
||||
public static CommentOnIsStep commentOnTable(Table<?> table) {
|
||||
return using(new DefaultConfiguration()).commentOnTable(table);
|
||||
}
|
||||
|
||||
@ -2115,6 +2115,17 @@ final class ParserImpl implements Parser {
|
||||
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
case 'C':
|
||||
|
||||
// TODO: support all of the storageLoop from the CREATE TABLE statement
|
||||
if (parseKeywordIf(ctx, "COMMENT")) {
|
||||
parseIf(ctx, '=');
|
||||
return ctx.dsl.commentOnTable(tableName).is(parseStringLiteral(ctx));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
case 'D':
|
||||
if (parseKeywordIf(ctx, "DROP")) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user