Skip to content

MDL-88218: Add experimental SQLite support for Moodle WASM environments (4.5)#4

Open
erseco wants to merge 3 commits into
MOODLE_405_STABLEfrom
MDL-88218-sqlite-405
Open

MDL-88218: Add experimental SQLite support for Moodle WASM environments (4.5)#4
erseco wants to merge 3 commits into
MOODLE_405_STABLEfrom
MDL-88218-sqlite-405

Conversation

@erseco

@erseco erseco commented Jul 8, 2026

Copy link
Copy Markdown
Member

Summary

Companion to #1 (main), #2 (5.1) and #3 (5.0). Moodle 4.5 still ships the
legacy SQLite PDO driver (lib/dml/sqlite3_pdo_moodle_database.php +
lib/ddl/sqlite_sql_generator.php) that was removed on 5.0+ — which is why the
newer branches add a modernised driver, while 4.5 only needs the existing one
repaired.

That legacy driver was left behind as the DML/DDL base classes evolved, so on
current 4.5 it can no longer install a site (admin/cli/install_database.php
fails). This PR makes it work again (experimental; WASM / demo / testing only).

Fixes

# File Problem Fix
1 lib/ddl/sqlite_sql_generator.php 4.5's sql_generator declares getCreateTempTableSQL() abstract; the generator omits it, so the class is abstract and cannot be instantiated (silent exit 255). Implement getCreateTempTableSQL() (CREATE TEMPORARY TABLE, mirroring mysql_sql_generator).
2 lib/ddl/sqlite_sql_generator.php Constructor __construct($mdb) drops the $temptables argument that get_manager() passes → $this->temptables is null → Call to a member function is_temptable() on null. Forward $temptables to the parent constructor.
3 lib/dml/sqlite3_pdo_moodle_database.php 4.5 expects each driver to create its temptables controller in connect(); this driver never does → $this->temptables null. Override connect() to initialise moodle_temptables.
4 lib/dml/sqlite3_pdo_moodle_database.php fetch_columns(): array returns false when a table's CREATE TABLE isn't found → TypeError on PHP 8. Return an empty array.
5 lib/dml/pdo_moodle_database.php get_records_sql() / get_records_select() return false on an empty result, but the documented contract (and callers such as license install, which does array_map()) expect an empty array. Return array() when there are no rows.
6 admin/environment.xml The <MOODLE version="4.5"> block does not list the sqlite database vendor, so install_database.php's environment check rejects it. Declare <VENDOR name="sqlite" version="3.0" /> in the 4.5 block.

Verification

Built Moodle 4.5.12 with these changes on top of an erseco/alpine-moodle
image and ran a full CLI install on SQLite:

  • admin/cli/install_database.php completes (496 tables, admin + guest users created).
  • The site serves over HTTP and a Moodle-context moosh role-list works.
  • php -l clean on all changed files; environment.xml is well-formed.

Notes

  • No new files: 4.5 already carries the driver, so this is a focused repair
    (4 files, +40/−5).
  • pdo_moodle_database.php is the shared PDO base, but SQLite is its only
    consumer here; the empty-array change also matches the method's own docblock.

Moodle 4.5 still ships the legacy SQLite PDO driver (removed in 5.0+, which
is why the 5.0/5.1/main branches re-add a modernised one). That legacy driver
was left behind as the DML/DDL base classes evolved, so it can no longer
install a site on 4.5. This makes it usable again (experimental; intended for
WASM / demo / testing environments, like MDL-88218 on the newer branches).

Fixes:

- sqlite_sql_generator::getCreateTempTableSQL(): 4.5's sql_generator declares
  this method abstract, so the generator was left abstract and could not be
  instantiated. Implement it (CREATE TEMPORARY TABLE, mirroring the mysql
  generator).
- sqlite_sql_generator::__construct(): forward the $temptables argument that
  get_manager() passes to the parent constructor; otherwise $this->temptables
  is null and every table create fails with "is_temptable() on null".
- sqlite3_pdo_moodle_database::connect(): 4.5 expects each driver to create its
  temptables controller in connect(); initialise moodle_temptables so the DDL
  generator can query temp tables during install.
- sqlite3_pdo_moodle_database::fetch_columns(): declared ": array" but returned
  false when a table's CREATE TABLE could not be found -> TypeError on PHP 8.
  Return an empty array instead.
- pdo_moodle_database::get_records_sql()/get_records_select(): return an empty
  array (not false) when there are no rows, matching the documented contract;
  4.5 core (e.g. license install) calls array_map() on the result.
- admin/environment.xml: declare the sqlite database VENDOR in the 4.5 block so
  install_database.php's environment check recognises it.

With these, a full CLI install (admin/cli/install_database.php) completes on
SQLite and the site serves.
@erseco erseco changed the title MDL-88218: Fix experimental SQLite support for Moodle 4.5 (WASM environments) MDL-88218: Fix experimental SQLite support for Moodle WASM environments (4.5) Jul 8, 2026
@erseco erseco changed the title MDL-88218: Fix experimental SQLite support for Moodle WASM environments (4.5) MDL-88218: Add experimental SQLite support for Moodle WASM environments (4.5) Jul 8, 2026
erseco added 2 commits July 11, 2026 09:32
database_column_info::__construct() reads its fields via object property access,
so the SQLite driver's fetch_columns() must pass an object like the pgsql and
mysqli drivers do. Passing the raw array left every property (including ->name)
null, which broke callers reading $column->name (e.g. theme_snap's events query
produced 'SELECT e., e., ...' and a syntax error).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant