Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public abstract class AbstractSQLConfig implements SQLConfig {
DATABASE_LIST.add(DATABASE_SQLSERVER);
DATABASE_LIST.add(DATABASE_ORACLE);
DATABASE_LIST.add(DATABASE_DB2);
DATABASE_LIST.add(DATABASE_CLICKHOUSE);


RAW_MAP = new LinkedHashMap<>(); // 保证顺序,避免配置冲突等意外情况
Expand Down Expand Up @@ -508,10 +509,17 @@ public boolean isDb2() {
public static boolean isDb2(String db) {
return DATABASE_DB2.equals(db);
}
@Override
public boolean isClickHouse() {
return isClickHouse(getSQLDatabase());
}
public static boolean isClickHouse(String db) {
return DATABASE_CLICKHOUSE.equals(db);
}

@Override
public String getQuote() {
return isMySQL() ? "`" : "\"";
return isMySQL() ? "`" : ( isClickHouse()? "" : "\"");
}

@Override
Expand Down Expand Up @@ -2158,6 +2166,9 @@ public String getRegExpString(String key, String value, boolean ignoreCase) {
if (isOracle()) {
return "regexp_like(" + getKey(key) + ", " + getValue(value) + (ignoreCase ? ", 'i'" : ", 'c'") + ")";
}
if (isClickHouse()) {
return "match(" + (ignoreCase ? "lower(" : "") + getKey(key) + (ignoreCase ? ")" : "") + ", " + (ignoreCase ? "lower(" : "") + getValue(value) + (ignoreCase ? ")" : "") + ")";
}
return getKey(key) + " REGEXP " + (ignoreCase ? "" : "BINARY ") + getValue(value);
}
//~ regexp >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Expand Down Expand Up @@ -2448,7 +2459,12 @@ else if (isOracle()) {
else {
boolean isNum = c instanceof Number;
String v = (isNum ? "" : "\"") + childs[i] + (isNum ? "" : "\"");
condition += ("json_contains(" + getKey(key) + ", " + getValue(v) + ")");
if (isClickHouse()) {
condition += condition + "has(JSONExtractArrayRaw(assumeNotNull(" + getKey(key) + "))" + ", " + getValue(v) + ")";
}
else {
condition += ("json_contains(" + getKey(key) + ", " + getValue(v) + ")");
}
}
}
}
Expand Down Expand Up @@ -2649,9 +2665,9 @@ public static String getSQL(AbstractSQLConfig config) throws Exception {
case POST:
return "INSERT INTO " + tablePath + config.getColumnString() + " VALUES" + config.getValuesString();
case PUT:
return "UPDATE " + tablePath + config.getSetString() + config.getWhereString(true) + (config.isMySQL() ? config.getLimitString() : "");
return "UPDATE " + tablePath + config.getSetString() + config.getWhereString(true) + (config.isMySQL()||config.isClickHouse() ? config.getLimitString() : "");
case DELETE:
return "DELETE FROM " + tablePath + config.getWhereString(true) + (config.isMySQL() ? config.getLimitString() : ""); // PostgreSQL 不允许 LIMIT
return "DELETE FROM " + tablePath + config.getWhereString(true) + (config.isMySQL()||config.isClickHouse() ? config.getLimitString() : ""); // PostgreSQL 不允许 LIMIT
default:
String explain = (config.isExplain() ? (config.isSQLServer() || config.isOracle() ? "SET STATISTICS PROFILE ON " : "EXPLAIN ") : "");
if (config.isTest() && RequestMethod.isGetMethod(config.getMethod(), true)) {
Expand Down
2 changes: 2 additions & 0 deletions APIJSONORM/src/main/java/apijson/orm/SQLConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface SQLConfig {
String DATABASE_SQLSERVER = "SQLSERVER";
String DATABASE_ORACLE = "ORACLE";
String DATABASE_DB2 = "DB2";
String DATABASE_CLICKHOUSE = "CLICKHOUSE";

String SCHEMA_INFORMATION = "information_schema"; //MySQL, PostgreSQL, SQL Server 都有的系统模式
String SCHEMA_SYS = "sys"; //SQL Server 系统模式
Expand All @@ -37,6 +38,7 @@ public interface SQLConfig {
boolean isSQLServer();
boolean isOracle();
boolean isDb2();
boolean isClickHouse();
//暂时只兼容以上 5 种
// boolean isSQL();
// boolean isTSQL();
Expand Down