execute_sql cannot create a SQLite trigger or a PostgreSQL BEGIN ATOMIC function: the statement is cut at the semicolons inside its body
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 85/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- postgresql, sql, sqlite, typescript
Línea de trabajo
Comienza con splitSQLStatements en src/utils/sql-parser.ts y reproduce los casos de triggers de SQLite y BEGIN ATOMIC de PostgreSQL descritos en el issue. Revisa cómo splitWith distingue los semicolones entrecomillados y comentados, y después añade pruebas enfocadas del parser para ambos dialectos. Hecho significa que el cuerpo de cada trigger o función atómica permanece como una sola instrucción, el comportamiento del otro dialecto no cambia y la suite de pruebas correspondiente pasa.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 4k
- Forks
- 370
- Merge medio
- 6 h 28 min
- PR fusionados (30 d)
- 41
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de bytebase/dbhub
-
SQLite: max_rows breaks LIMIT -1 OFFSET n with a syntax errorPosiblemente ocupada @goranai la tomó hace 4 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Oracle: opt-in thick mode for servers that require Native Network Encryption (NJS-533 / ORA-12660)Posiblemente ocupada @gabriell-prado la tomó hace 3 días. Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
Los mantenedores suelen responder en 1 día
-
MySQL: query_timeout fallback KILL QUERY uses the handshake thread id, which is wrong behind a proxyPosiblemente ocupada @DongJinNam la tomó hace 1 día. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
👉👉👉 Please share your use case to shape DBHub roadmapQuizá libre de nuevo @tianzhou la tomó hace 367 días y no hay ningún pull request abierto. Abierto
bytebase/dbhub#146 · 27 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de bytebase/dbhub
Issues similares
-
Flaky test: selecting a portion just after inserting it can also match its Change and Delete buttonsAbiertoready-for-agent
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
linagora/dcs-onlyoffice#172 ·
-
bug follow-up
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
nightly-tests
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
BlackBeltTechnology/pi-agent-dashboard#1226 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
danielmiessler/LifeOS#3028 ·
Los mantenedores suelen responder en 5 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100