{"id":"86250a91a80494fa","repo":"go-sql-driver/mysql","slug":"protocol-error-illegal-decimals-value-d","errorCode":null,"errorMessage":"protocol error, illegal decimals value %d","messagePattern":"protocol error, illegal decimals value (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packets.go","lineNumber":1409,"sourceCode":"\t\t\tfieldTypeTimestamp, fieldTypeDateTime: // Timestamp YYYY-MM-DD HH:MM:SS[.fractal]\n\n\t\t\tnum, isNull, n := readLengthEncodedInteger(data[pos:])\n\t\t\tpos += n\n\n\t\t\tswitch {\n\t\t\tcase isNull:\n\t\t\t\tdest[i] = nil\n\t\t\t\tcontinue\n\t\t\tcase rows.rs.columns[i].fieldType == fieldTypeTime:\n\t\t\t\t// database/sql does not support an equivalent to TIME, return a string\n\t\t\t\tvar dstlen uint8\n\t\t\t\tswitch decimals := rows.rs.columns[i].decimals; decimals {\n\t\t\t\tcase 0x00, 0x1f:\n\t\t\t\t\tdstlen = 8\n\t\t\t\tcase 1, 2, 3, 4, 5, 6:\n\t\t\t\t\tdstlen = 8 + 1 + decimals\n\t\t\t\tdefault:\n\t\t\t\t\treturn fmt.Errorf(\n\t\t\t\t\t\t\"protocol error, illegal decimals value %d\",\n\t\t\t\t\t\trows.rs.columns[i].decimals,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tdest[i], err = formatBinaryTime(data[pos:pos+int(num)], dstlen)\n\t\t\tcase rows.mc.parseTime:\n\t\t\t\tdest[i], err = parseBinaryDateTime(num, data[pos:], rows.mc.cfg.Loc)\n\t\t\tdefault:\n\t\t\t\tvar dstlen uint8\n\t\t\t\tif rows.rs.columns[i].fieldType == fieldTypeDate {\n\t\t\t\t\tdstlen = 10\n\t\t\t\t} else {\n\t\t\t\t\tswitch decimals := rows.rs.columns[i].decimals; decimals {\n\t\t\t\t\tcase 0x00, 0x1f:\n\t\t\t\t\t\tdstlen = 19\n\t\t\t\t\tcase 1, 2, 3, 4, 5, 6:\n\t\t\t\t\t\tdstlen = 19 + 1 + decimals\n\t\t\t\t\tdefault:","sourceCodeStart":1391,"sourceCodeEnd":1427,"githubUrl":"https://github.com/go-sql-driver/mysql/blob/c426bd93799de0f0e094c8f0582872c529d0ed0a/packets.go#L1391-L1427","documentation":"A protocol-level error while decoding a binary-protocol TIME column from a prepared-statement result row (packets.go:1409): the column's decimals metadata byte is not 0x00, 0x1f, or 1-6, the only legal values per the MySQL binary protocol. The driver's adjacent comment urges reporting it, signaling it should not occur with a conformant server. It indicates a malformed or non-conforming server/proxy response.","triggerScenarios":"Reading rows from a prepared statement over a connection to a buggy/non-conforming server or middleware (ProxySQL, Vitess, a custom sharding layer) that emits an invalid decimals byte for a TIME column; packet corruption in transit.","commonSituations":"A proxy generating malformed column definitions; an extremely old or patched server; rare genuine driver/server version skew.","solutions":["Reproduce against a vanilla MySQL/MariaDB server to confirm it is a server/proxy bug.","Upgrade or patch the offending server or proxy that generates the result set.","Work around it by casting the column in SQL, e.g. SELECT CAST(t AS CHAR) AS t.","Report the bug to the driver maintainers with the server/proxy version details."],"exampleFix":"// before\nrows, _ := db.Query(\"SELECT t FROM events\")  // t is TIME with malformed metadata\n\n// after — force a string to bypass binary TIME decoding\nrows, _ := db.Query(\"SELECT CAST(t AS CHAR) AS t FROM events\")","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := rows.Scan(dest...); err != nil {\n    if strings.Contains(err.Error(), \"illegal decimals value\") && strings.Contains(err.Error(), \"protocol error\") {\n        // server/proxy sent malformed TIME metadata; re-issue with CAST(t AS CHAR)\n    }\n}","preventionTips":["Test new server/proxy versions against TIME columns before rollout.","Use CAST(t AS CHAR) for TIME columns if a middleware mangles metadata.","Report protocol errors to the driver and server maintainers."],"tags":["protocol","binary-protocol","time","resultset","bug"],"analyzedSha":"c426bd93799de0f0e094c8f0582872c529d0ed0a","analyzedAt":"2026-08-04T21:52:59.219Z","schemaVersion":2}