@@ -124,6 +124,7 @@ public abstract class AbstractSQLConfig implements SQLConfig {
124124 DATABASE_LIST .add (DATABASE_SQLSERVER );
125125 DATABASE_LIST .add (DATABASE_ORACLE );
126126 DATABASE_LIST .add (DATABASE_DB2 );
127+ DATABASE_LIST .add (DATABASE_CLICKHOUSE );
127128
128129
129130 RAW_MAP = new LinkedHashMap <>(); // 保证顺序,避免配置冲突等意外情况
@@ -508,10 +509,17 @@ public boolean isDb2() {
508509 public static boolean isDb2 (String db ) {
509510 return DATABASE_DB2 .equals (db );
510511 }
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+ }
511519
512520 @ Override
513521 public String getQuote () {
514- return isMySQL () ? "`" : " \" " ;
522+ return isMySQL () ? "`" : ( isClickHouse ()? "" : " \" ") ;
515523 }
516524
517525 @ Override
@@ -2158,6 +2166,9 @@ public String getRegExpString(String key, String value, boolean ignoreCase) {
21582166 if (isOracle ()) {
21592167 return "regexp_like(" + getKey (key ) + ", " + getValue (value ) + (ignoreCase ? ", 'i'" : ", 'c'" ) + ")" ;
21602168 }
2169+ if (isClickHouse ()) {
2170+ return "match(" + (ignoreCase ? "lower(" : "" ) + getKey (key ) + (ignoreCase ? ")" : "" ) + ", " + (ignoreCase ? "lower(" : "" ) + getValue (value ) + (ignoreCase ? ")" : "" ) + ")" ;
2171+ }
21612172 return getKey (key ) + " REGEXP " + (ignoreCase ? "" : "BINARY " ) + getValue (value );
21622173 }
21632174 //~ regexp >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -2448,7 +2459,12 @@ else if (isOracle()) {
24482459 else {
24492460 boolean isNum = c instanceof Number ;
24502461 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+ }
24522468 }
24532469 }
24542470 }
@@ -2649,9 +2665,9 @@ public static String getSQL(AbstractSQLConfig config) throws Exception {
26492665 case POST :
26502666 return "INSERT INTO " + tablePath + config .getColumnString () + " VALUES" + config .getValuesString ();
26512667 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 () : "" );
26532669 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
26552671 default :
26562672 String explain = (config .isExplain () ? (config .isSQLServer () || config .isOracle () ? "SET STATISTICS PROFILE ON " : "EXPLAIN " ) : "" );
26572673 if (config .isTest () && RequestMethod .isGetMethod (config .getMethod (), true )) {
0 commit comments