Skip to content

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

invisal
Copy link

@invisal invisal commented Jul 7, 2025

Fixes #8377, #6357, #5920
Might also related to #8226

This PR improves the D1 SQL dump logic

  • Properly escape column and table names to prevent syntax errors.
  • Handle SQLite's loose typing by escaping values based on value type instead of enforcing strict column types.
  • Add tests to verify SQL dump output and edge cases.

  • Tests
    • Tests included
    • Tests not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: It is a bugfix
  • Wrangler V3 Backport
    • Wrangler PR:
    • Not necessary because:

@invisal invisal requested a review from a team as a code owner July 7, 2025 05:48
Copy link

changeset-bot bot commented Jul 7, 2025

⚠️ No Changeset found

Latest commit: c16782d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@invisal invisal marked this pull request as draft July 7, 2025 05:48
* @param id - The identifier to escape.
* @returns
*/
function escapeId(id: string) {
Copy link
Author

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

@emily-shen emily-shen marked this pull request as ready for review July 7, 2025 16:48
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Jul 8, 2025
@emily-shen emily-shen marked this pull request as draft July 8, 2025 10:36
Copy link

pkg-pr-new bot commented Jul 8, 2025

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@9866

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@9866

miniflare

npm i https://pkg.pr.new/miniflare@9866

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@9866

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@9866

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@9866

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@9866

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@9866

wrangler

npm i https://pkg.pr.new/wrangler@9866

commit: c16782d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Untriaged
Development

Successfully merging this pull request may close these issues.

🐛 BUG: d1 reserved key words fail on export but not migrations
1 participant