-
Notifications
You must be signed in to change notification settings - Fork 940
fix: escape column names and handle mismatched data types in D1 SQL dump #9866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: escape column names and handle mismatched data types in D1 SQL dump #9866
Conversation
🦋 Changeset detectedLatest commit: e5c988a The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
* @param id - The identifier to escape. | ||
* @returns | ||
*/ | ||
function escapeId(id: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SQLite escapes double quotes in identifiers by doubling them using sqlite3_mprintf("\"%w\"", azCol[i])
https://github.com/sqlite/sqlite/blob/master/src/shell.c.in#L2914
The %w
format doubles " as "":
https://github.com/sqlite/sqlite/blob/master/src/printf.c#L34
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
a1797b1
to
423b04a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks for fixing this.
Part of me is tempted to assert that we can round-trip our export through the sqlite cli, reimport it and still get the same results. I doubt that our CI boxes have the sqlite cli installed though, so the way you've done it is probably the right balance.
Congratulations @invisal, the maintainer of this repository has issued you a holobyte! Here it is: https://holopin.io/holobyte/cmd8uaetj1763207jvmdf7wiq6 This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account. |
…ump (#9866) * fix: escape column names and handle mismatched data types in D1 SQL dump * fix(d1): allow exporting blob in tests and importing without errors * fix(d1): correct test case by quoting table names with double quotes in SQL INSERT * fix(d1): Add patch note for escape identifiers and handle dynamic typing --------- Co-authored-by: visal <[email protected]>
…ump (#9866) (#10035) * fix: escape column names and handle mismatched data types in D1 SQL dump * fix(d1): allow exporting blob in tests and importing without errors * fix(d1): correct test case by quoting table names with double quotes in SQL INSERT * fix(d1): Add patch note for escape identifiers and handle dynamic typing --------- Co-authored-by: Visal .In <[email protected]> Co-authored-by: visal <[email protected]>
Fixes #8377, fixes #6357, fixes #5920
Might also related to #8226
This PR improves the D1 SQL dump logic