package com.lxy.dialect;
public class MyDialect implements Dialect {
protected static final String SQL_END_DELIMITER = ";";
public String getLimitString(String sql, boolean hasoffset) {
return new StringBuffer(sql.length() + 20).append(trim(sql)).append(
hasoffset ? "limit ?,?" : "limit ?").append(SQL_END_DELIMITER)
.toString();
}
public String getLimitString(String sql, int offset, int limit) {
sql = trim(sql);
StringBuffer sb = new StringBuffer(sql.length() + 20);
sb.append(sql);
if (offset > 0) {
sb.append("limit").append(offset).append(',').append(limit).append(
";");
} else {
sb.append("limit").append(limit).append(";");
}
return sb.toString();
}
public boolean supportLimit() {
return true;
}
private String trim(String sql) {
sql = sql.trim();
if (sql.endsWith(";")) {
sql = sql.substring(0, sql.length() - 1 - ";".length());
}
return sql;
}
}