Skip to content

fix: escape quotes in string defaults on export and unescape them on import - #1062

Merged
huydo862003 merged 4 commits into
holistics:masterfrom
jayhemnani9910:fix/string-default-quotes
Dec 2, 2026
Merged

huydo862003 merged 4 commits into
holistics:masterfrom
jayhemnani9910:fix/string-default-quotes

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

A string default with a quote in it broke conversion both ways.

  • Import: DEFAULT 'Don''t panic' kept the SQL escaping. Postgres, MySQL and MSSQL gave the default as Don''t panic, MySQL also kept backslash escapes ('C:\\temp', 'Don\'t') and charset introducers (_utf8mb4'xxx' came out as utf8mb4'xxx). The DBML exporter then wrote these unescaped, and the result didn't parse (Expect a comma ',').
  • Export: the Postgres, MySQL, SQL Server and Oracle exporters wrote string defaults and enum values as they are, so [default: 'Don\'t panic'] became DEFAULT 'Don't panic', which the database rejects.

The importers now decode string literals: '' for all three, and for MySQL also backslash escapes and N/charset prefixes. For Postgres this happens once, in visitAnysconst, so comments and INSERT records get it too, and the separate unescape for comments is removed. The exporters escape string defaults and enum values the way they already escape notes and records (MySQL also escapes \).

Two fixtures encoded the old output and are updated: mysql_importer/ddl_create (c3 is now 'xxx') and mssql-parse/insert (test''s value is now test's value). Added tests for the importers and exporters.

Not covered: the live-database connectors (db2dbml) still return defaults with '' doubled.

@huydo862003 huydo862003 added the PR: Bug Fix 🐛 A type of pull request used for changelog categories label Dec 2, 2026
@huydo862003
huydo862003 merged commit b2ae4c1 into holistics:master Dec 2, 2026
4 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Bug Fix 🐛 A type of pull request used for changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants