|
|
|
@ -37,25 +37,29 @@ public class MySQL5Dialect extends MySQLDialect {
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//utf8编码下,mysql5.7以下版本主键长度不能超过255,故特殊处理,去掉它的primary。
|
|
|
|
|
// 它默认会生成一个长度为255的前缀索引
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String getPrimaryKeyString(List<Column> columnList) { |
|
|
|
|
for (Column column : columnList) { |
|
|
|
|
public String sqlConstraintString(List<Column> columnList) { |
|
|
|
|
StringBuilder buf = new StringBuilder("key ("); |
|
|
|
|
boolean overLimit = false; |
|
|
|
|
for (int i = 0; i < columnList.size(); i ++) { |
|
|
|
|
if (i != 0) { |
|
|
|
|
buf.append(", "); |
|
|
|
|
} |
|
|
|
|
Column column = columnList.get(i); |
|
|
|
|
buf.append(column.getQuotedName(this)); |
|
|
|
|
if (column.getLength() > INDEX_LENGTH_LIMIT) { |
|
|
|
|
return "key"; |
|
|
|
|
buf.append("(" + INDEX_LENGTH_LIMIT + ")"); |
|
|
|
|
overLimit = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return "primary key"; |
|
|
|
|
if (!overLimit) { |
|
|
|
|
buf.insert(0, "primary "); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// mysql有些小版本(如5.5.46)不支持创建key的同时自动创建前缀索引,此处手动指定
|
|
|
|
|
@Override |
|
|
|
|
public String getPrimaryKeyPostfix(Column column) { |
|
|
|
|
int columnLength = column.getLength(); |
|
|
|
|
return columnLength > INDEX_LENGTH_LIMIT ? "(" + INDEX_LENGTH_LIMIT + ")" : ""; |
|
|
|
|
return buf.append(')').toString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter() { |
|
|
|
|
return EXTRACTER; |
|
|
|
|
} |
|
|
|
|