execute_sql cannot create a SQLite trigger or a PostgreSQL BEGIN ATOMIC function: the statement is cut at the semicolons inside its body
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 85/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- postgresql, sql, sqlite, typescript
Hướng nghiên cứu
Bắt đầu với splitSQLStatements trong src/utils/sql-parser.ts và tái hiện các trường hợp trigger SQLite và BEGIN ATOMIC của PostgreSQL được mô tả trong issue. Xem cách splitWith phân biệt dấu chấm phẩy trong dấu nháy và trong chú thích, sau đó thêm các bài kiểm thử parser tập trung cho cả hai dialect. Hoàn thành nghĩa là phần thân của mỗi trigger hoặc hàm atomic vẫn là một câu lệnh duy nhất, hành vi của dialect còn lại không thay đổi và bộ kiểm thử liên quan vượt qua.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
execute_sql cuts a batch at every ; that is outside a quote or a comment. A SQLite trigger and a PostgreSQL function with an SQL-standard body have ; inside their BEGIN ... END body. They are cut into pieces that no database accepts. On SQLite no trigger can be created through execute_sql, because every trigger body ends with ; END.
The SQL is not exotic. The SQLite FTS5 manual (section 4.4.3, external content tables) tells you to keep the index current with three CREATE TRIGGER ... BEGIN ...; END; statements. sqlite-utils writes the same triggers for enable_fts(create_triggers=True) and enable_counts(), so the schema of any database it made has them. PostgreSQL 14 added CREATE FUNCTION ... BEGIN ATOMIC ...; END, and PostgreSQL's own regression file src/test/regress/sql/create_function_sql.sql uses it a lot.
Expected Behavior
The trigger or function reaches the database as one statement, as it does when you run the same text in sqlite3 or psql.
Actual Behavior
On main (5128cf8, same code in v2.1.0), take the schema of a database made by sqlite-utils 4.2.1 (enable_fts with triggers and enable_counts) and run it through SQLiteConnector.executeSQL on sqlite:///:memory::
CREATE TABLE "docs" ( "id" INTEGER PRIMARY KEY, "title" TEXT, "body" TEXT );
CREATE VIRTUAL TABLE "docs_fts" USING FTS5 ( "title", "body", content="docs" );
CREATE TRIGGER "docs_ai" AFTER INSERT ON "docs" BEGIN
INSERT INTO "docs_fts" (rowid, "title", "body") VALUES (new.rowid, new."title", new."body");
END;
...
It fails with incomplete input. The splitter returns CREATE TRIGGER "docs_ai" ... BEGIN\n INSERT INTO ... new."body") and then END as two statements. SQLite prepares each piece alone, so the first piece is incomplete input. The same text runs fine in the SQLite engine as one script, so the text is valid.
PostgreSQL gets the same cut. Take this text from the PostgreSQL regression file:
CREATE FUNCTION functest_S_13() RETURNS boolean
BEGIN ATOMIC
SELECT 1;
SELECT false;
END;
splitSQLStatements(sql, "postgres") returns three pieces: ... BEGIN ATOMIC SELECT 1, SELECT false and END. PostgresConnector.executeSQL sends each piece as its own query. I had no PostgreSQL server here, so I did not see the server error. I compared the split with libpg-query, the real PostgreSQL parser that DBHub already uses. The parser reads that text as 1 statement. In all 10 BEGIN ATOMIC blocks of the regression file the split gives more pieces than the parser reads statements.
MySQL and SQL Server are not affected. The MySQL connector sends the whole batch, and the SQL Server connector already handles module bodies.
Steps to Reproduce
import { splitSQLStatements } from "./src/utils/sql-parser.js";
splitSQLStatements(
"CREATE TRIGGER t_ai AFTER INSERT ON t BEGIN INSERT INTO a VALUES (1); END",
"sqlite"
);
// ["CREATE TRIGGER t_ai AFTER INSERT ON t BEGIN INSERT INTO a VALUES (1)", "END"]
Or call execute_sql on any SQLite source with the FTS5 trigger example from the SQLite manual.
Cause
splitWith in src/utils/sql-parser.ts ends a statement at every ; that the dialect scanner does not mark as a comment or quoted block. A BEGIN ... END body is neither. The sqlite and postgres connectors execute the pieces one by one (src/connectors/sqlite/index.ts line 525, src/connectors/postgres/index.ts line 755).
System
- DBHub: main 5128cf8 (v2.1.0 has the same code)
- OS/version: Windows 11, Node 24
I have a small fix with tests ready. It keeps the body of a CREATE TRIGGER (SQLite) or a BEGIN ATOMIC function or procedure (PostgreSQL) in one statement, and leaves the other dialects as they are.
Validated with Claude Opus 5.5.
- Ngôn ngữ chính
- TypeScript
- Star
- 4k
- Fork
- 370
- Merge trung bình
- 6 giờ 28 phút
- Pull request đã merge (30 ngày)
- 41
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bytebase/dbhub
-
SQLite: max_rows breaks LIMIT -1 OFFSET n with a syntax errorCó thể đã có người làm @goranai đã nhận 4 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Oracle: opt-in thick mode for servers that require Native Network Encryption (NJS-533 / ORA-12660)Có thể đã có người làm @gabriell-prado đã nhận 3 ngày trước. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Maintainer thường phản hồi trong vòng 1 ngày
-
MySQL: query_timeout fallback KILL QUERY uses the handshake thread id, which is wrong behind a proxyCó thể đã có người làm @DongJinNam đã nhận 1 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
👉👉👉 Please share your use case to shape DBHub roadmapCó thể làm lại được @tianzhou đã nhận 367 ngày trước và không có pull request nào đang mở. Đang mở
bytebase/dbhub#146 · 27 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của bytebase/dbhub
Issue tương tự
-
Flaky test: selecting a portion just after inserting it can also match its Change and Delete buttonsĐang mởready-for-agent
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
linagora/dcs-onlyoffice#172 ·
-
bug follow-up
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
nightly-tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
BlackBeltTechnology/pi-agent-dashboard#1226 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
danielmiessler/LifeOS#3028 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100