cloudflare / cloudflare/developer-platform
D1Database.exec incomplete input error caused by multi-line SQL.
- Ngôn ngữ chính
- Không có dữ liệu ngôn ngữ
- Star
- 1
- Fork
- 0
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
### 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_
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện lỗi migration nhiều dòng với một phiên bản D1Database được liên kết cục bộ, sau đó so sánh với cùng script đó trong SQLite và thông qua đường dẫn fetch của D1 API. Truy vết cách D1Database.exec xử lý đầu vào nhiều dòng; công việc được xem là hoàn tất khi phiên bản được liên kết chấp nhận script migration ban đầu mà không thay thế các ký tự xuống dòng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- sql, sqlite, typescript
- Lĩnh vực
- database
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100