cloudflare / cloudflare/developer-platform

D1Database.exec incomplete input error caused by multi-line SQL.

Aperta
#8 4 commenti 1 reazione 0 assegnatari Vedi su GitHub
awaiting-response:cloudflare product:d1
Lingua principale
Nessun dato sulla lingua
Stelle
1
Fork
0
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### 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_

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.