Skip to content

fix: a backup restores text that looks like a number as text - #945

Merged
blaipr merged 1 commit into
mainfrom
fix/a-backup-restores-text-that-looks-like-a-number
Sep 24, 2026
Merged

blaipr merged 1 commit into
mainfrom
fix/a-backup-restores-text-that-looks-like-a-number

Conversation

@blaipr

@blaipr blaipr commented Sep 24, 2026

Copy link
Copy Markdown
Member

The database backup dump (BackupFile) wrote every value is_numeric() accepted as a bare SQL literal. is_numeric() is true of text that only looks numeric, and a bare literal is a number to MySQL. So restoring a backup silently changed text columns:

CREATE TEMPORARY TABLE t (v varchar(20));
INSERT INTO t VALUES(0123),(1e5),( 7),(0800),('0123');
SELECT v FROM t;   -- 123, 100000, 7, 800, 0123

So an account login of 0123, an account or client named 0800, or a note reading 1e5 would come back as 123, 800 and 100000. The backup is the recovery path, so this only shows up on the day it's needed.

Change

The decision is now made by the column's type, not by what the value looks like:

  • PDO returns integer columns as int and every text column as string. This was measured against MariaDB with both native and emulated prepares.
  • Only real ints and floats are written bare. Everything else is quoted.
  • A quoted number still loads correctly into a numeric column.

Tests

FileBackupServiceTest::testTextThatLooksLikeANumberIsDumpedAsText checks that a row of '0123', 5, '1e5', ' 7', 2.5, NULL is dumped as VALUES('0123',5,'1e5',' 7',2.5,NULL). It fails without the fix.

@blaipr
blaipr merged commit 68307dc into main Sep 24, 2026
8 checks passed
@blaipr
blaipr deleted the fix/a-backup-restores-text-that-looks-like-a-number branch September 24, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant