Fix transform() corrupting TRUE/FALSE/NULL column defaults

quote_default_value() passed keyword-literal defaults (TRUE, FALSE, NULL)
through self.quote(), wrapping them in quotes. So transform() rebuilt a
column declared "INTEGER DEFAULT TRUE" as "INTEGER DEFAULT 'TRUE'", and a
later default insert stored the text 'TRUE' instead of the integer 1
(likewise 'FALSE' for 0 and 'NULL' for null) - silent value corruption.

Return these keyword literals unquoted, as already done for the
CURRENT_TIME/DATE/TIMESTAMP literals.
This commit is contained in:
Vincent Gao 2026-07-01 01:03:46 +02:00
commit 5aa61c2f7f
No known key found for this signature in database
GPG key ID: 4EB74F921300AF3B
3 changed files with 44 additions and 0 deletions

View file

@ -710,6 +710,11 @@ class Database:
if str(value).upper() in ("CURRENT_TIME", "CURRENT_DATE", "CURRENT_TIMESTAMP"):
return value
if str(value).upper() in ("TRUE", "FALSE", "NULL"):
# Keyword literals must stay unquoted; quoting them would turn the
# default into a string ('TRUE' instead of 1, 'NULL' instead of null).
return value
if str(value).endswith(")"):
# Expr
return "({})".format(value)