From bebd77e65342bbd65f3db9386dc1be57d204c30f Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 2 Jun 2021 12:15:10 +0200 Subject: [PATCH] [jOOQ/jOOQ#9650] Add support for the Snowflake database - BITNOT support - CREATE TABLE inline comment support - DATEADD support --- .../java/org/jooq/impl/CreateTableImpl.java | 2 + .../main/java/org/jooq/impl/Expression.java | 1 + jOOQ/src/main/java/org/jooq/impl/Names.java | 68 ++++++++++--------- jOOQ/src/main/java/org/jooq/impl/Neg.java | 19 +++--- 4 files changed, 48 insertions(+), 42 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/CreateTableImpl.java b/jOOQ/src/main/java/org/jooq/impl/CreateTableImpl.java index fb8a077f22..316caacfb8 100644 --- a/jOOQ/src/main/java/org/jooq/impl/CreateTableImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/CreateTableImpl.java @@ -489,6 +489,8 @@ final class CreateTableImpl extends AbstractDDLQuery implements + + ctx.visit(comment); } diff --git a/jOOQ/src/main/java/org/jooq/impl/Expression.java b/jOOQ/src/main/java/org/jooq/impl/Expression.java index 344e7aee61..fc6782599a 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Expression.java +++ b/jOOQ/src/main/java/org/jooq/impl/Expression.java @@ -787,6 +787,7 @@ final class Expression extends AbstractTransformable { + case FIREBIRD: { diff --git a/jOOQ/src/main/java/org/jooq/impl/Names.java b/jOOQ/src/main/java/org/jooq/impl/Names.java index 1251181ce4..a49555fd07 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Names.java +++ b/jOOQ/src/main/java/org/jooq/impl/Names.java @@ -78,21 +78,23 @@ final class Names { static final Name N_ATN2 = unquotedName("atn2"); static final Name N_AVG = unquotedName("avg"); static final Name N_BIN_AND = unquotedName("bin_and"); + static final Name N_BIN_NOT = unquotedName("bin_not"); static final Name N_BIN_OR = unquotedName("bin_or"); static final Name N_BIN_SHL = unquotedName("bin_shl"); static final Name N_BIN_SHR = unquotedName("bin_shr"); static final Name N_BIN_XOR = unquotedName("bin_xor"); - static final Name N_BIT_COUNT = unquotedName("bit_count"); - static final Name N_BIT_LENGTH = unquotedName("bit_length"); static final Name N_BITAND = unquotedName("bitand"); + static final Name N_BITNOT = unquotedName("bitnot"); static final Name N_BITOR = unquotedName("bitor"); static final Name N_BITSHIFTLEFT = unquotedName("bitshiftleft"); static final Name N_BITSHIFTRIGHT = unquotedName("bitshiftright"); static final Name N_BITXOR = unquotedName("bitxor"); - static final Name N_BOOL_AND = unquotedName("bool_and"); - static final Name N_BOOL_OR = unquotedName("bool_or"); + static final Name N_BIT_COUNT = unquotedName("bit_count"); + static final Name N_BIT_LENGTH = unquotedName("bit_length"); static final Name N_BOOLAND_AGG = unquotedName("booland_agg"); static final Name N_BOOLOR_AGG = unquotedName("boolor_agg"); + static final Name N_BOOL_AND = unquotedName("bool_and"); + static final Name N_BOOL_OR = unquotedName("bool_or"); static final Name N_BYTE_LENGTH = unquotedName("byte_length"); static final Name N_CARDINALITY = unquotedName("cardinality"); static final Name N_CASE = unquotedName("case"); @@ -100,8 +102,8 @@ final class Names { static final Name N_CEIL = unquotedName("ceil"); static final Name N_CEILING = unquotedName("ceiling"); static final Name N_CHAR = unquotedName("char"); - static final Name N_CHAR_LENGTH = unquotedName("char_length"); static final Name N_CHARINDEX = unquotedName("charindex"); + static final Name N_CHAR_LENGTH = unquotedName("char_length"); static final Name N_CHOOSE = unquotedName("choose"); static final Name N_CHR = unquotedName("chr"); static final Name N_COALESCE = unquotedName("coalesce"); @@ -117,12 +119,13 @@ final class Names { static final Name N_COT = unquotedName("cot"); static final Name N_COTH = unquotedName("coth"); static final Name N_COUNT = unquotedName("count"); - static final Name N_COUNT_IF = unquotedName("count_if"); static final Name N_COUNTIF = unquotedName("countif"); static final Name N_COUNTSET = unquotedName("countset"); + static final Name N_COUNT_IF = unquotedName("count_if"); static final Name N_COVAR_POP = unquotedName("covar_pop"); static final Name N_COVAR_SAMP = unquotedName("covar_samp"); static final Name N_CUME_DIST = unquotedName("cume_dist"); + static final Name N_CURRENTUSER = unquotedName("currentuser"); static final Name N_CURRENT_BIGDATETIME = unquotedName("current_bigdatetime"); static final Name N_CURRENT_CATALOG = unquotedName("current_catalog"); static final Name N_CURRENT_DATABASE = unquotedName("current_database"); @@ -131,16 +134,15 @@ final class Names { static final Name N_CURRENT_TIME = unquotedName("current_time"); static final Name N_CURRENT_TIMESTAMP = unquotedName("current_timestamp"); static final Name N_CURRENT_USER = unquotedName("current_user"); - static final Name N_CURRENTUSER = unquotedName("currentuser"); static final Name N_CURRVAL = unquotedName("currval"); static final Name N_DATALENGTH = unquotedName("datalength"); - static final Name N_DATE_ADD = unquotedName("date_add"); - static final Name N_DATE_DIFF = unquotedName("date_diff"); - static final Name N_DATE_TRUNC = unquotedName("date_trunc"); static final Name N_DATEADD = unquotedName("dateadd"); static final Name N_DATEDIFF = unquotedName("datediff"); static final Name N_DATEPART = unquotedName("datepart"); static final Name N_DATETIME_TRUNC = unquotedName("datetime_trunc"); + static final Name N_DATE_ADD = unquotedName("date_add"); + static final Name N_DATE_DIFF = unquotedName("date_diff"); + static final Name N_DATE_TRUNC = unquotedName("date_trunc"); static final Name N_DAYOFWEEK = unquotedName("dayofweek"); static final Name N_DAYOFYEAR = unquotedName("dayofyear"); static final Name N_DAYS = unquotedName("days"); @@ -163,20 +165,20 @@ final class Names { static final Name N_FLOOR = unquotedName("floor"); static final Name N_FORMAT = unquotedName("format"); static final Name N_FUNCTION = unquotedName("function"); - static final Name N_GEN_ID = unquotedName("gen_id"); - static final Name N_GEN_RANDOM_UUID = unquotedName("gen_random_uuid"); - static final Name N_GEN_UUID = unquotedName("gen_uuid"); static final Name N_GENERATE_ARRAY = unquotedName("generate_array"); static final Name N_GENERATE_SERIES = unquotedName("generate_series"); static final Name N_GENERATE_UNIQUE = unquotedName("generate_unique"); static final Name N_GENERATE_UUID = unquotedName("generate_uuid"); static final Name N_GENERATOR = unquotedName("generator"); static final Name N_GENGUID = unquotedName("genguid"); + static final Name N_GEN_ID = unquotedName("gen_id"); + static final Name N_GEN_RANDOM_UUID = unquotedName("gen_random_uuid"); + static final Name N_GEN_UUID = unquotedName("gen_uuid"); static final Name N_GETDATE = unquotedName("getdate"); static final Name N_GREATEST = unquotedName("greatest"); static final Name N_GROUP_CONCAT = unquotedName("group_concat"); - static final Name N_HASH_MD5 = unquotedName("hash_md5"); static final Name N_HASHBYTES = unquotedName("hashbytes"); + static final Name N_HASH_MD5 = unquotedName("hash_md5"); static final Name N_HEX = unquotedName("hex"); static final Name N_IF = unquotedName("if"); static final Name N_IFNULL = unquotedName("ifnull"); @@ -186,6 +188,11 @@ final class Names { static final Name N_INSTR = unquotedName("instr"); static final Name N_ISJSON = unquotedName("isjson"); static final Name N_JOIN = unquotedName("join"); + static final Name N_JSONB_AGG = unquotedName("jsonb_agg"); + static final Name N_JSONB_BUILD_ARRAY = unquotedName("jsonb_build_array"); + static final Name N_JSONB_OBJECT_AGG = unquotedName("jsonb_object_agg"); + static final Name N_JSONB_PATH_EXISTS = unquotedName("jsonb_path_exists"); + static final Name N_JSONB_PATH_QUERY_FIRST = unquotedName("jsonb_path_query_first"); static final Name N_JSON_AGG = unquotedName("json_agg"); static final Name N_JSON_ARRAY = unquotedName("json_array"); static final Name N_JSON_ARRAYAGG = unquotedName("json_arrayagg"); @@ -195,17 +202,12 @@ final class Names { static final Name N_JSON_MERGE = unquotedName("json_merge"); static final Name N_JSON_MERGE_PRESERVE = unquotedName("json_merge_preserve"); static final Name N_JSON_OBJECT = unquotedName("json_object"); - static final Name N_JSON_OBJECT_AGG = unquotedName("json_object_agg"); static final Name N_JSON_OBJECTAGG = unquotedName("json_objectagg"); + static final Name N_JSON_OBJECT_AGG = unquotedName("json_object_agg"); static final Name N_JSON_QUOTE = unquotedName("json_quote"); static final Name N_JSON_TABLE = unquotedName("json_table"); static final Name N_JSON_VALID = unquotedName("json_valid"); static final Name N_JSON_VALUE = unquotedName("json_value"); - static final Name N_JSONB_AGG = unquotedName("jsonb_agg"); - static final Name N_JSONB_BUILD_ARRAY = unquotedName("jsonb_build_array"); - static final Name N_JSONB_OBJECT_AGG = unquotedName("jsonb_object_agg"); - static final Name N_JSONB_PATH_EXISTS = unquotedName("jsonb_path_exists"); - static final Name N_JSONB_PATH_QUERY_FIRST = unquotedName("jsonb_path_query_first"); static final Name N_LCASE = unquotedName("lcase"); static final Name N_LEAST = unquotedName("least"); static final Name N_LEFT = unquotedName("left"); @@ -253,9 +255,9 @@ final class Names { static final Name N_OREPLACE = unquotedName("oreplace"); static final Name N_OTRANSLATE = unquotedName("otranslate"); static final Name N_OVERLAY = unquotedName("overlay"); - static final Name N_PERCENT_RANK = unquotedName("percent_rank"); static final Name N_PERCENTILE_CONT = unquotedName("percentile_cont"); static final Name N_PERCENTILE_DISC = unquotedName("percentile_disc"); + static final Name N_PERCENT_RANK = unquotedName("percent_rank"); static final Name N_PI = unquotedName("pi"); static final Name N_PIVOT = unquotedName("pivot"); static final Name N_PLPGSQL = unquotedName("plpgsql"); @@ -267,13 +269,13 @@ final class Names { static final Name N_RADIANS = unquotedName("radians"); static final Name N_RAND = unquotedName("rand"); static final Name N_RANDOM = unquotedName("random"); - static final Name N_RANDOM_UUID = unquotedName("random_uuid"); static final Name N_RANDOMBLOB = unquotedName("randomblob"); + static final Name N_RANDOM_UUID = unquotedName("random_uuid"); static final Name N_RANK = unquotedName("rank"); static final Name N_RATIO_TO_REPORT = unquotedName("ratio_to_report"); static final Name N_RAWTOHEX = unquotedName("rawtohex"); - static final Name N_REGEX_REPLACE = unquotedName("regex_replace"); static final Name N_REGEXP_REPLACE = unquotedName("regexp_replace"); + static final Name N_REGEX_REPLACE = unquotedName("regex_replace"); static final Name N_REGR_AVGX = unquotedName("regr_avgx"); static final Name N_REGR_AVGY = unquotedName("regr_avgy"); static final Name N_REGR_COUNT = unquotedName("regr_count"); @@ -293,9 +295,9 @@ final class Names { static final Name N_ROUND = unquotedName("round"); static final Name N_ROUND_DOWN = unquotedName("round_down"); static final Name N_ROW = unquotedName("row"); - static final Name N_ROW_NUMBER = unquotedName("row_number"); static final Name N_ROWNUM = unquotedName("rownum"); static final Name N_ROWSFROM = unquotedName("rowsfrom"); + static final Name N_ROW_NUMBER = unquotedName("row_number"); static final Name N_RPAD = unquotedName("rpad"); static final Name N_RSHIFT = unquotedName("rshift"); static final Name N_RTRIM = unquotedName("rtrim"); @@ -332,31 +334,31 @@ final class Names { static final Name N_STDDEV_POP = unquotedName("stddev_pop"); static final Name N_STDDEV_SAMP = unquotedName("stddev_samp"); static final Name N_STDEV = unquotedName("stdev"); - static final Name N_STDEV_SAMP = unquotedName("stdev_samp"); static final Name N_STDEVP = unquotedName("stdevp"); - static final Name N_STR_REPLACE = unquotedName("str_replace"); + static final Name N_STDEV_SAMP = unquotedName("stdev_samp"); static final Name N_STRFTIME = unquotedName("strftime"); static final Name N_STRING_AGG = unquotedName("string_agg"); static final Name N_STRREVERSE = unquotedName("strreverse"); + static final Name N_STR_REPLACE = unquotedName("str_replace"); static final Name N_SUBSTR = unquotedName("substr"); static final Name N_SUBSTRING = unquotedName("substring"); static final Name N_SUBSTRING_INDEX = unquotedName("substring_index"); static final Name N_SUM = unquotedName("sum"); - static final Name N_SYS_CONNECT_BY_PATH = unquotedName("sys_connect_by_path"); - static final Name N_SYS_GUID = unquotedName("sys_guid"); static final Name N_SYSTEM_RANGE = unquotedName("system_range"); static final Name N_SYSTEM_TIME = unquotedName("system_time"); static final Name N_SYSUUID = unquotedName("sysuuid"); + static final Name N_SYS_CONNECT_BY_PATH = unquotedName("sys_connect_by_path"); + static final Name N_SYS_GUID = unquotedName("sys_guid"); static final Name N_T = unquotedName("t"); static final Name N_TAN = unquotedName("tan"); static final Name N_TANH = unquotedName("tanh"); static final Name N_TAU = unquotedName("tau"); - static final Name N_TIMESTAMP_ADD = unquotedName("timestamp_add"); - static final Name N_TIMESTAMP_DIFF = unquotedName("timestamp_diff"); - static final Name N_TIMESTAMP_SUB = unquotedName("timestamp_sub"); static final Name N_TIMESTAMPADD = unquotedName("timestampadd"); static final Name N_TIMESTAMPDIFF = unquotedName("timestampdiff"); static final Name N_TIMESTAMPSUB = unquotedName("timestampsub"); + static final Name N_TIMESTAMP_ADD = unquotedName("timestamp_add"); + static final Name N_TIMESTAMP_DIFF = unquotedName("timestamp_diff"); + static final Name N_TIMESTAMP_SUB = unquotedName("timestamp_sub"); static final Name N_TO_CHAR = unquotedName("to_char"); static final Name N_TO_CLOB = unquotedName("to_clob"); static final Name N_TO_DATE = unquotedName("to_date"); @@ -380,11 +382,11 @@ final class Names { static final Name N_VALUE = unquotedName("value"); static final Name N_VALUES = unquotedName("values"); static final Name N_VAR = unquotedName("var"); - static final Name N_VAR_POP = unquotedName("var_pop"); - static final Name N_VAR_SAMP = unquotedName("var_samp"); static final Name N_VARIANCE = unquotedName("variance"); static final Name N_VARIANCE_SAMP = unquotedName("variance_samp"); static final Name N_VARP = unquotedName("varp"); + static final Name N_VAR_POP = unquotedName("var_pop"); + static final Name N_VAR_SAMP = unquotedName("var_samp"); static final Name N_WEEKDAY = unquotedName("weekday"); static final Name N_WIDTH_BUCKET = unquotedName("width_bucket"); static final Name N_XMLAGG = unquotedName("xmlagg"); diff --git a/jOOQ/src/main/java/org/jooq/impl/Neg.java b/jOOQ/src/main/java/org/jooq/impl/Neg.java index 9290beb15e..5080a08731 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Neg.java +++ b/jOOQ/src/main/java/org/jooq/impl/Neg.java @@ -46,7 +46,14 @@ import static org.jooq.SQLDialect.HSQLDB; // ... // ... // ... +// ... +import static org.jooq.impl.DSL.function; +import static org.jooq.impl.DSL.one; +import static org.jooq.impl.DSL.zero; import static org.jooq.impl.ExpressionOperator.BIT_NOT; +import static org.jooq.impl.Internal.isub; +import static org.jooq.impl.Names.N_BIN_NOT; +import static org.jooq.impl.Names.N_BITNOT; import java.util.Set; @@ -111,17 +118,11 @@ final class Neg extends AbstractTransformable { if (operator == BIT_NOT && EMULATE_BIT_NOT.contains(ctx.dialect())) - ctx.sql("(0 - ") - .visit(field) - .sql(" - 1)"); + ctx.visit(isub(isub(zero(), field), one())); else if (operator == BIT_NOT && SUPPORT_BIT_NOT.contains(ctx.dialect())) - ctx.sql("bitnot(") - .visit(field) - .sql(')'); + ctx.visit(function(N_BITNOT, getDataType(), field)); else if (operator == BIT_NOT && family == FIREBIRD) - ctx.sql("bin_not(") - .visit(field) - .sql(')'); + ctx.visit(function(N_BIN_NOT, getDataType(), field)); else ctx.sql(operator.toSQL()) .sql('(')