summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-03-28 13:46:24 -0400
committermike bayer <mike_mp@zzzcomputing.com>2022-03-28 20:50:16 +0000
commit24a031146c8b74550b6705dfb5f2e67ed69f78c9 (patch)
tree9ee3e72993c5a425b980f7ca00196ee0bc2532f9 /lib/sqlalchemy/dialects
parentc90396fbe7424c481f8f4ee18b6cedd1fa09c711 (diff)
downloadsqlalchemy-24a031146c8b74550b6705dfb5f2e67ed69f78c9.tar.gz
fix quotes regexp for SQLite CHECK constraints
Fixed bug where the name of CHECK constraints under SQLite would not be reflected if the name were created using quotes, as is the case when the name uses mixed case or special characters. Fixes: #5463 Change-Id: Ic3b1e0a0385fb9e727b0880e90815ea2814df313
Diffstat (limited to 'lib/sqlalchemy/dialects')
-rw-r--r--lib/sqlalchemy/dialects/sqlite/base.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py
index 03f35d5e2..b1ac20383 100644
--- a/lib/sqlalchemy/dialects/sqlite/base.py
+++ b/lib/sqlalchemy/dialects/sqlite/base.py
@@ -2430,17 +2430,21 @@ class SQLiteDialect(default.DefaultDialect):
if not table_data:
return []
- CHECK_PATTERN = r"(?:CONSTRAINT (\w+) +)?" r"CHECK *\( *(.+) *\),? *"
+ CHECK_PATTERN = r"(?:CONSTRAINT (.+) +)?" r"CHECK *\( *(.+) *\),? *"
check_constraints = []
# NOTE: we aren't using re.S here because we actually are
# taking advantage of each CHECK constraint being all on one
# line in the table definition in order to delineate. This
# necessarily makes assumptions as to how the CREATE TABLE
# was emitted.
+
for match in re.finditer(CHECK_PATTERN, table_data, re.I):
- check_constraints.append(
- {"sqltext": match.group(2), "name": match.group(1)}
- )
+ name = match.group(1)
+
+ if name:
+ name = re.sub(r'^"|"$', "", name)
+
+ check_constraints.append({"sqltext": match.group(2), "name": name})
return check_constraints