babyfish-ct / jimmer

A revolutionary ORM framework for both java and kotlin.
Apache License 2.0
876 stars 88 forks source link

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

Closed SWQXDBA closed 2 weeks ago

SWQXDBA commented 3 weeks ago

版本为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";
    }
}
babyfish-ct commented 2 weeks ago

Try 0.9.11