cloudflare / cloudflare/developer-platform
D1Database.exec incomplete input error caused by multi-line SQL.
- Lenguaje dominante
- Sin datos de lenguaje
- Estrellas
- 1
- Forks
- 0
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
### 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_
Guía de contribución
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- sql, sqlite, typescript
- Área
- database
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100