Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mysql方言在Mysql5.7 Upsert问题 #751

Open
SWQXDBA opened this issue Nov 4, 2024 · 0 comments
Open

Mysql方言在Mysql5.7 Upsert问题 #751

SWQXDBA opened this issue Nov 4, 2024 · 0 comments

Comments

@SWQXDBA
Copy link

SWQXDBA commented Nov 4, 2024

版本为Mysql 5.7.35

Mysql5.7似乎不支持 LAST_INSERT_ID() LAST_INSERT_ID(expr)语句 会报错
44cc14279c9fb074c8635202ae466867

建议写一个Mysql57版本的方言 关闭upset同时修改update方法


public class MySql57Dialect extends DefaultDialect {
    public void paginate(PaginationContext ctx) {
        ctx.origin().space().sql("limit ").variable(ctx.getOffset()).sql(", ").variable(ctx.getLimit());
    }

    public UpdateJoin getUpdateJoin() {
        return new UpdateJoin(true, UpdateJoin.From.UNNECESSARY);
    }

    public boolean isDeletedAliasRequired() {
        return true;
    }

    public String sqlType(Class<?> elementType) {
        if (elementType == String.class) {
            return "varchar";
        } else if (elementType == UUID.class) {
            return "char(36)";
        } else if (elementType == Boolean.TYPE) {
            return "boolean";
        } else if (elementType == Byte.TYPE) {
            return "tinyint";
        } else if (elementType == Short.TYPE) {
            return "smallint";
        } else if (elementType == Integer.TYPE) {
            return "int";
        } else if (elementType == Long.TYPE) {
            return "bigint";
        } else if (elementType == Float.TYPE) {
            return "float";
        } else if (elementType == Double.TYPE) {
            return "double";
        } else if (elementType == BigDecimal.class) {
            return "decimal";
        } else if (elementType != Date.class && elementType != LocalDate.class) {
            if (elementType != Time.class && elementType != LocalTime.class) {
                if (elementType == OffsetTime.class) {
                    return "datetime";
                } else if (elementType != java.util.Date.class && elementType != Timestamp.class) {
                    if (elementType == LocalDateTime.class) {
                        return "timestamp";
                    } else {
                        return elementType != OffsetDateTime.class && elementType != ZonedDateTime.class ? null : "timestamp";
                    }
                } else {
                    return "timestamp";
                }
            } else {
                return "datetime";
            }
        } else {
            return "date";
        }
    }

    public boolean isUpsertWithMultipleUniqueConstraintSupported() {
        return false;
    }

    public boolean isIdFetchableByKeyUpdate() {
        return true;
    }

    public boolean isUpsertSupported() {
        return false;
    }

    public void update(Dialect.UpdateContext ctx) {
        super.update(ctx);
    }


    public String transCacheOperatorTableDDL() {
        return "create table JIMMER_TRANS_CACHE_OPERATOR(\n\tID bigint unsigned not null auto_increment primary key,\n\tIMMUTABLE_TYPE varchar(128),\n\tIMMUTABLE_PROP varchar(128),\n\tCACHE_KEY varchar(64) not null,\n\tREASON varchar(32)\n) engine=innodb";
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant