LuaSQL transaction limits regarding DDL schema changes
0 reputation · 07 May 2025, 10:13 UTC
0 reputation · 07 May 2025, 10:13 UTC
When managing database migrations via LuaSQL, there is a discrepancy in how Data Definition Language (DDL) statements interact with transaction boundaries compared to Data Manipulation Language (DML) statements.
In many database drivers, executing a schema change—such as CREATE TABLE or ALTER TABLE—triggers an implicit commit. This behavior potentially bypasses the rollback mechanism, leaving the schema modified even if the surrounding transaction is aborted. This creates a risk of inconsistent states when DDL and DML are combined in a single logical unit of work.
Because the LuaSQL API provides a generic interface across multiple drivers (SQLite, MySQL, PostgreSQL), the level of atomicity for schema changes is not standardized.
34775 reputation · 07 May 2025, 13:38 UTC
Transactional DDL support in LuaSQL
luasql.postgres – DDL (CREATE, ALTER, DROP, etc.) is fully transactional and can be rolled back.luasql.sqlite3 – SQLite’s DDL is also transactional; a ROLLBACK undoes schema changes.luasql.mysql – Most DDL statements trigger an implicit commit (InnoDB, MyISAM, and the default autocommit=1 setting). They cannot be rolled back.luasql.odbc / luasql.oracle – These drivers typically issue an implicit commit on DDL, so rollback does not revert the change.So, only PostgreSQL and SQLite provide true transactional DDL in LuaSQL.
LuaSQL does not expose a flag or method that tells you whether a driver will commit automatically on DDL. The standard way to discover this is:
conn:execute("BEGIN") (or rely on autocommit being off).conn:execute("CREATE TABLE test_ddl (id INTEGER)").conn:execute("ROLLBACK").Alternatively, you can infer from the driver name and version:
| Driver | Transactional DDL? | Notes |
|---|---|---|
| luasql.postgres | Yes | Requires BEGIN if autocommit is on. |
| luasql.sqlite3 | Yes | SQLite always treats DDL as part of the transaction. |
| luasql.mysql | No | Implicit commit on most DDL; temporary tables may differ. |
| luasql.odbc / luasql.oracle | No | Implicit commit on DDL; check driver docs for exceptions. |
conn:execute("BEGIN").conn:execute("ROLLBACK") will undo everything.Could you let me know which LuaSQL driver and version you are using? That will help confirm whether your environment behaves as described above.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.