@@ -124,6 +124,7 @@ public abstract class AbstractSQLConfig implements SQLConfig {
124
124
DATABASE_LIST .add (DATABASE_SQLSERVER );
125
125
DATABASE_LIST .add (DATABASE_ORACLE );
126
126
DATABASE_LIST .add (DATABASE_DB2 );
127
+ DATABASE_LIST .add (DATABASE_CLICKHOUSE );
127
128
128
129
129
130
RAW_MAP = new LinkedHashMap <>(); // 保证顺序,避免配置冲突等意外情况
@@ -508,10 +509,17 @@ public boolean isDb2() {
508
509
public static boolean isDb2 (String db ) {
509
510
return DATABASE_DB2 .equals (db );
510
511
}
512
+ @ Override
513
+ public boolean isClickHouse () {
514
+ return isClickHouse (getSQLDatabase ());
515
+ }
516
+ public static boolean isClickHouse (String db ) {
517
+ return DATABASE_CLICKHOUSE .equals (db );
518
+ }
511
519
512
520
@ Override
513
521
public String getQuote () {
514
- return isMySQL () ? "`" : " \" " ;
522
+ return isMySQL () ? "`" : ( isClickHouse ()? "" : " \" ") ;
515
523
}
516
524
517
525
@ Override
@@ -2158,6 +2166,9 @@ public String getRegExpString(String key, String value, boolean ignoreCase) {
2158
2166
if (isOracle ()) {
2159
2167
return "regexp_like(" + getKey (key ) + ", " + getValue (value ) + (ignoreCase ? ", 'i'" : ", 'c'" ) + ")" ;
2160
2168
}
2169
+ if (isClickHouse ()) {
2170
+ return "match(" + (ignoreCase ? "lower(" : "" ) + getKey (key ) + (ignoreCase ? ")" : "" ) + ", " + (ignoreCase ? "lower(" : "" ) + getValue (value ) + (ignoreCase ? ")" : "" ) + ")" ;
2171
+ }
2161
2172
return getKey (key ) + " REGEXP " + (ignoreCase ? "" : "BINARY " ) + getValue (value );
2162
2173
}
2163
2174
//~ regexp >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -2448,7 +2459,12 @@ else if (isOracle()) {
2448
2459
else {
2449
2460
boolean isNum = c instanceof Number ;
2450
2461
String v = (isNum ? "" : "\" " ) + childs [i ] + (isNum ? "" : "\" " );
2451
- condition += ("json_contains(" + getKey (key ) + ", " + getValue (v ) + ")" );
2462
+ if (isClickHouse ()) {
2463
+ condition += condition + "has(JSONExtractArrayRaw(assumeNotNull(" + getKey (key ) + "))" + ", " + getValue (v ) + ")" ;
2464
+ }
2465
+ else {
2466
+ condition += ("json_contains(" + getKey (key ) + ", " + getValue (v ) + ")" );
2467
+ }
2452
2468
}
2453
2469
}
2454
2470
}
@@ -2649,9 +2665,9 @@ public static String getSQL(AbstractSQLConfig config) throws Exception {
2649
2665
case POST :
2650
2666
return "INSERT INTO " + tablePath + config .getColumnString () + " VALUES" + config .getValuesString ();
2651
2667
case PUT :
2652
- return "UPDATE " + tablePath + config .getSetString () + config .getWhereString (true ) + (config .isMySQL () ? config .getLimitString () : "" );
2668
+ return "UPDATE " + tablePath + config .getSetString () + config .getWhereString (true ) + (config .isMySQL ()|| config . isClickHouse () ? config .getLimitString () : "" );
2653
2669
case DELETE :
2654
- return "DELETE FROM " + tablePath + config .getWhereString (true ) + (config .isMySQL () ? config .getLimitString () : "" ); // PostgreSQL 不允许 LIMIT
2670
+ return "DELETE FROM " + tablePath + config .getWhereString (true ) + (config .isMySQL ()|| config . isClickHouse () ? config .getLimitString () : "" ); // PostgreSQL 不允许 LIMIT
2655
2671
default :
2656
2672
String explain = (config .isExplain () ? (config .isSQLServer () || config .isOracle () ? "SET STATISTICS PROFILE ON " : "EXPLAIN " ) : "" );
2657
2673
if (config .isTest () && RequestMethod .isGetMethod (config .getMethod (), true )) {
0 commit comments