cloudflare / cloudflare/developer-platform
D1Database.exec incomplete input error caused by multi-line SQL.
- 主要言語
- 言語のデータがありません
- スター
- 1
- フォーク
- 0
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
### 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_
コントリビューションガイド
調査の方向性
まず、ローカルにバインドされた D1Database インスタンスで複数行のマイグレーション失敗を再現し、次に同じスクリプトを SQLite で実行した場合および D1 API の fetch パスを通した場合と比較します。D1Database.exec による複数行入力の処理を追跡します。バインドされたインスタンスが改行を置換せずに元のマイグレーションスクリプトを受け付ければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- sql, sqlite, typescript
- 領域
- database
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100