cloudflare / cloudflare/developer-platform
D1Database.exec incomplete input error caused by multi-line SQL.
- Dominant language
- No language data
- Stars
- 1
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
### Which Cloudflare product(s) does this pertain to?
D1
### What versions & operating system are you using?
Wrangler v4.14.1, Node v20.18.3, Linux x86_64 6.6.85-2-MANJARO
### Please provide a link to a minimal reproduction
_No response_
### Describe the Bug
Calls to the `D1Database` `exec` method with a multi-line migration script fail with error:
```sh
✘ [ERROR] Error: D1_EXEC_ERROR: Error in line 1:
CREATE TABLE "users" (: incomplete input: SQLITE_ERROR
at D1DatabaseSessionAlwaysPrimary.exec (cloudflare-internal:d1-api:201:19)
```
To avoid this error, I had to replace all new-lines in my otherwise working migration script with a space:
```ts
await env.siteDbTemp.exec(migration_sql.replaceAll(/\n/gm, " "));
```
The same migration script works in SQLite and it works when sending it to the D1 API via fetch, but it doesn't work locally with a bound `D1Database` instance in my Cloudflare Pages/functions project. I haven't tested it live on Cloudflare.
### Please provide any relevant error logs
_No response_
Contributor guide
Research direction
Start by reproducing the multiline migration failure with a locally bound D1Database instance, then compare it with the same script in SQLite and through the D1 API fetch path. Trace D1Database.exec handling of multiline input; done means the bound instance accepts the original migration script without replacing newlines.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql, sqlite, typescript
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100