Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

SET autocommit and SET foreign_key_checks are accepted but have no effect

Abierto
#529 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
mysql, php, sqlite
Área
database

Línea de trabajo

Read the driver's session-variable handling and wrapper transaction code, then trace how foreign_key_checks maps to PRAGMA foreign_keys and how autocommit interacts with COMMIT and ROLLBACK. Reproduce both SQL examples from the issue. Done means these settings either affect behavior as described or are rejected clearly instead of being stored silently.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Reproduction

CREATE TABLE p (id INT PRIMARY KEY);
CREATE TABLE c (pid INT, FOREIGN KEY (pid) REFERENCES p (id));

SET foreign_key_checks = 0;
SELECT @@foreign_key_checks;
-- 0
INSERT INTO c VALUES (99);
-- SQLSTATE[23000]: Integrity constraint violation: 19 FOREIGN KEY constraint failed
-- (MySQL: the row is inserted)
CREATE TABLE t (id INT PRIMARY KEY);

SET autocommit = 0;
SELECT @@autocommit;
-- 0
INSERT INTO t VALUES (1);
ROLLBACK;
SELECT id FROM t;
-- 1   (MySQL: no rows; with autocommit off, the INSERT opened a transaction)

Reproduced on trunk (3.1.0) with PHP 8.3 and SQLite 3.45.1.

Both statements are accepted and stored as session variables, so SELECT @@... reports the new value, but neither changes behavior. Before they are set, both variables read as NULL (MySQL: 1).

Impact

  • foreign_key_checks: SQL dumps disable foreign key checks so that tables can be loaded in any order. mysqldump output sets FOREIGN_KEY_CHECKS=0 in its header. Here, importing such a dump fails at the first row of a child table that is loaded before its parent.
  • autocommit: Code that turns autocommit off and relies on ROLLBACK to discard its changes has them committed instead. This one silently keeps data the application meant to discard.

Implementation notes

foreign_key_checks maps to PRAGMA foreign_keys, with one limit: SQLite ignores that pragma inside a transaction, so a change made inside a transaction can only take effect when it ends. The driver's wrapper transaction has the same limit, and #528 discusses running DDL outside it, which would also be the place to apply this setting.

autocommit = 0 could be emulated by opening a transaction before the next statement and keeping it open until COMMIT or ROLLBACK, as MySQL does.

Until then, would it be preferable to reject these values with an error rather than accept them silently? I'm happy to contribute a PR in whichever direction you prefer.

Use of AI

This report was prepared with Claude Code.

Lenguaje dominante
PHP
Estrellas
362
Forks
69
Merge medio
4 d 7 h
PR fusionados (30 d)
9

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

  • Sin Dockerfile ni archivo de Docker Compose
  • Sin plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de WordPress/sqlite-database-integration

Todos los issues de WordPress/sqlite-database-integration

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.