{"record":{"id":"572cd01243d03440","repo":"OtterMind/Chat2DB","slug":"invalid-mysql-default-value-value","errorCode":null,"errorMessage":"Invalid MySQL default value: {value}","messagePattern":"Invalid MySQL default value: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-plugins/chat2db-community-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlSqlGuards.java","lineNumber":53,"sourceCode":"\n    /**\n     * Validate a strict MySQL name token (ENGINE / CHARACTER SET / COLLATE style positions where\n     * escaping is impossible by design).\n     */\n    public static String requireMysqlName(String value, String what) {\n        if (value == null || !MYSQL_NAME_PATTERN.matcher(value).matches()) {\n            throw new IllegalArgumentException(\"Invalid MySQL \" + what + \": \" + value);\n        }\n        return value;\n    }\n\n    /**\n     * Validate a raw DEFAULT literal for numeric-ish columns (positions where quoting would change\n     * semantics). Accepts decimal/scientific numbers, hex and bit literals, TRUE/FALSE.\n     */\n    public static String requireNumericDefault(String value) {\n        if (value == null || !NUMERIC_DEFAULT_PATTERN.matcher(value.trim()).matches()) {\n            throw new IllegalArgumentException(\"Invalid MySQL default value: \" + value);\n        }\n        return value;\n    }\n\n    /**\n     * Validate content of a b'...' bit literal.\n     */\n    public static String requireBitLiteral(String value) {\n        if (value == null || !BIT_LITERAL_PATTERN.matcher(value).matches()) {\n            throw new IllegalArgumentException(\"Invalid MySQL bit literal: \" + value);\n        }\n        return value;\n    }\n\n    /**\n     * Validate the digits of a 0x... hex literal (the template adds the 0x prefix).\n     */\n    public static String requireHexDigits(String value) {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-plugins/chat2db-community-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlSqlGuards.java#L35-L71","documentation":"Thrown by MysqlSqlGuards.requireNumericDefault when a raw DEFAULT literal (for a numeric-ish column, where quoting would change semantics) fails the NUMERIC_DEFAULT_PATTERN. The pattern accepts decimals/scientific, 0x hex, x'/b' literals, and TRUE/FALSE; anything else is rejected because it cannot be safely interpolated unquoted into the DEFAULT clause.","triggerScenarios":"Calling requireNumericDefault(value) with a non-numeric expression such as a SQL function (NOW(), CURRENT_TIMESTAMP), a quoted string, an arithmetic expression, or a value with illegal characters. The value is trimmed first, so leading/trailing spaces are tolerated.","commonSituations":"A column DEFAULT specified as a string for a numeric column; a frontend default-value field that accepts arbitrary expressions and forwards them raw; mixing up string defaults (which should be quoted elsewhere) with numeric defaults.","solutions":["Route function/expression defaults (NOW(), etc.) through the quoted-string or expression path, not requireNumericDefault.","Validate the default against the column's data type before selecting the numeric-guard path.","For numeric columns, ensure the default is a plain number, hex, bit literal, or TRUE/FALSE.","Trim the value and strip any surrounding quotes before validation."],"exampleFix":"// before\nMysqlSqlGuards.requireNumericDefault(defaultValue);\n\n// after\nString d = StringUtils.trimToNull(defaultValue);\nif (d == null || !d.matches(\"^([+-]?(\\\\d+(\\\\.\\\\d+)?|\\\\.\\\\d+)([eE][+-]?\\\\d+)?|0[xX][0-9a-fA-F]+|[xX]'[0-9a-fA-F]*'|[bB]'[01]*'|(?i:TRUE|FALSE))$\")) {\n    throw new IllegalArgumentException(\"Invalid MySQL default value: \" + defaultValue);\n}\nMysqlSqlGuards.requireNumericDefault(d);","handlingStrategy":"validation","validationCode":"String d = StringUtils.trimToNull(value);\nif (d == null || !d.matches(\"^([+-]?(\\\\d+(\\\\.\\\\d+)?|\\\\.\\\\d+)([eE][+-]?\\\\d+)?|0[xX][0-9a-fA-F]+|[xX]'[0-9a-fA-F]*'|[bB]'[01]*'|(?i:TRUE|FALSE))$\")) {\n    throw new IllegalArgumentException(\"Invalid MySQL default value: \" + value);\n}\nMysqlSqlGuards.requireNumericDefault(d);","typeGuard":"static boolean isNumericDefault(String value) {\n    return value != null && value.trim().matches(\"^([+-]?(\\\\d+(\\\\.\\\\d+)?|\\\\.\\\\d+)([eE][+-]?\\\\d+)?|0[xX][0-9a-fA-F]+|[xX]'[0-9a-fA-F]*'|[bB]'[01]*'|(?i:TRUE|FALSE))$\");\n}","tryCatchPattern":null,"preventionTips":["Route expression defaults (NOW(), etc.) through the quoted/expression path.","Match the default validation to the column's data type.","Strip surrounding quotes before passing to the numeric guard.","Do not forward arbitrary UI expressions into raw DEFAULT positions."],"tags":["mysql","validation","ddl","default-value"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}