mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
Fix transform() corrupting TRUE/FALSE/NULL column defaults into strings
* 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. PR #764
This commit is contained in:
parent
77d241959c
commit
a4acc3958c
4 changed files with 48 additions and 0 deletions
|
|
@ -983,6 +983,11 @@ class Database:
|
|||
if str(value).upper() in ("CURRENT_TIME", "CURRENT_DATE", "CURRENT_TIMESTAMP"):
|
||||
return value
|
||||
|
||||
if isinstance(value, str) and 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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue