Repository navigation
fix(query): carry BIGINT as text and quote from column metadata - #510
Merged
Merged
Conversation
BIGINT exceeds what a JSON number can represent, so a value above 2^53 arrived at the grid with a silently wrong final digit — and got pasted into another query from copy-as-INSERT. 9007199254740993 became ...992, with no error anywhere. Carry 64-bit integers as text, as DECIMAL already is after #508. Types up to 32 bits still travel as JSON numbers, since every value of those fits exactly; only BIGINT needs it. mysql2 draws the line in the same place, and its bigNumberStrings option is what Beekeeper Studio enables for this exact reason. That breaks the assumption `typeof value === "number"` means numeric, which both toSqlLiteral and formatSqlValue relied on to decide quoting. Left alone they would emit '9007199254740993' — quoted — turning a precision fix into a correctness regression. Quoting now comes from ColumnMeta.data_type instead, which is what SQLyog does: IS_NUM on the field drives both alignment and whether a generated INSERT quotes. Unquoting requires the column to claim numeric *and* the text to parse as a number. Trusting the declared type alone would splice arbitrary text into a statement unquoted if the two ever disagreed. closes #502 Co-Authored-By: Claude Opus 5 <[email protected]>
EVWorth
added a commit
that referenced
this pull request
Aug 28, 2026
…511) There were two definitions of "is this column numeric" that disagreed. EditableCell had a substring regex, /int|decimal|.../, matched against the lowercased type — so POINT and MULTIPOINT counted as numeric (po·int) while YEAR did not. #510 then added a second, stricter one in sql-types without noticing the first. Consolidated into sql-types, matching the base type rather than a substring, which fixes both misclassifications on the way past. isBooleanType and isLongTextType move there too; the latter was duplicated verbatim in EditableCell and TruncatedCell. Consolidating surfaced a third instance of the precision bug: on commit, parseEditValue pushed any numeric column through Number(), so editing a BIGINT wrote back a value with the last digit dropped. isExactNumericType now keeps BIGINT and DECIMAL as text, matching how they arrive from Rust, and those cells use a text input since a number input normalises them too. Alignment, which the grid had none of: numeric columns are right-aligned with tabular figures, headers follow their column. Driven by the declared type, since BIGINT and DECIMAL arrive as strings and the value's JavaScript type no longer identifies a number — the same reason SQLyog aligns from IS_NUM(field->type). For DECIMAL this is decimal-point alignment for free, as MySQL returns a fixed scale. NULL is styled muted and italic instead of being left-aligned. It read identically to a VARCHAR containing the text "NULL", and styling separates them without breaking a column's run of digits. Co-authored-by: Claude Opus 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #502. Step 2 of the restructure, after #509.
The bug
BIGINTexceeds what a JSON number can represent, so any value above 2^53 reached the grid with a silently wrong final digit:No error, nothing logged. Worst in copy-cell and copy-as-INSERT, where a truncated id gets pasted straight into another query.
The fix, and the trap in it
Carry 64-bit integers as text, as
DECIMALalready is after #509. Types up to 32 bits still travel as JSON numbers — every value of those fits exactly, so onlyBIGINTneeds this. mysql2 draws the line in exactly the same place (SHORT/LONG/INT24useparseLengthCodedIntNoBigCheck, onlyLONGLONGgets the treatment), and itsbigNumberStringsis what Beekeeper Studio turns on for this.The trap: that breaks the assumption
typeof value === "number"identifies a number, which two places relied on to decide quoting —SqlValueGuard.toSqlLiteralandformatSqlValue. Left alone they would emit'9007199254740993'quoted, turning a precision fix into a correctness regression in generated SQL.So quoting now comes from
ColumnMeta.data_type. That is what SQLyog does —IS_NUM(field->type)drives both right-alignment and whether a generated INSERT quotes — and it's the reason a client can hand back big numbers as strings without breaking its SQL generation. Newsrc/lib/sql-types.tsholds that predicate so the grid and the generator share one definition.Safety
Unquoting requires both that the column claims to be numeric and that the text parses as a number:
Trusting the declared type alone would splice arbitrary text into a statement unquoted if the two ever disagreed. Covered by tests, including
"1; DROP TABLE users"against abigintcolumn, which stays quoted.Tests
sql-types.test.ts— type parsing (DECIMAL(20,4),BIGINT UNSIGNED), and the numeric-literal guard against injection-shaped inputsql-generator.test.ts— INSERT/UPDATE/DELETE keep a stringified BIGINT unquoted in both SET and WHERE; avarcharcolumn holding digits stays quoted; and a test pinning that without column types the id would be quoted, so the regression this prevents is visibletype_coverage.rs—bigint_keeps_every_digitasserts 2^53+1 survives, including across the JSON round-trip where the truncation actually happenedVerification
1589 frontend unit tests (+23), 290 browser tests, 5 type-coverage and 39 integration tests against real MySQL,
cargo clippy --all-features -D warningsandcargo fmt --checkclean, type-check clean, lint unchanged at 180 warnings / 0 errors.