diff --git a/admin/environment.xml b/admin/environment.xml index 41a84be35f8ce..198363bea09d7 100644 --- a/admin/environment.xml +++ b/admin/environment.xml @@ -4523,6 +4523,7 @@ + diff --git a/lib/ddl/sqlite_sql_generator.php b/lib/ddl/sqlite_sql_generator.php index cf60b33964405..a3a1e29e1f3d8 100644 --- a/lib/ddl/sqlite_sql_generator.php +++ b/lib/ddl/sqlite_sql_generator.php @@ -73,8 +73,8 @@ class sqlite_sql_generator extends sql_generator { /** * Creates one new XMLDBmysql */ - public function __construct($mdb) { - parent::__construct($mdb); + public function __construct($mdb, $temptables = null) { + parent::__construct($mdb, $temptables); } /** @@ -460,4 +460,22 @@ public function addslashes($s) { $s = str_replace("'", "''", $s); return $s; } + + /** + * Given one correct xmldb_table, returns the SQL statements to create a + * temporary table (CREATE TEMPORARY TABLE ...), mirroring getCreateTableSQL. + * + * @param xmldb_table $xmldb_table The xmldb_table object instance. + * @return array of sql statements + */ + public function getCreateTempTableSQL($xmldb_table) { + $this->temptables->add_temptable($xmldb_table->getName()); + $sqlarr = parent::getCreateTableSQL($xmldb_table); + foreach ($sqlarr as $i => $sql) { + if (strpos($sql, 'CREATE TABLE ') === 0) { + $sqlarr[$i] = preg_replace('/^CREATE TABLE (.*)/s', 'CREATE TEMPORARY TABLE $1', $sql); + } + } + return $sqlarr; + } } diff --git a/lib/dml/pdo_moodle_database.php b/lib/dml/pdo_moodle_database.php index 3a2a8471524ce..cb45e91766183 100644 --- a/lib/dml/pdo_moodle_database.php +++ b/lib/dml/pdo_moodle_database.php @@ -296,7 +296,7 @@ public function get_fieldset_sql($sql, ?array $params=null) { $rs = $this->get_recordset_sql($sql, $params); if (!$rs->valid()) { $rs->close(); // Not going to iterate (but exit), close rs - return false; + return array(); } $result = array(); foreach($rs as $value) { @@ -326,7 +326,7 @@ public function get_records_sql($sql, ?array $params=null, $limitfrom=0, $limitn $rs = $this->get_recordset_sql($sql, $params, $limitfrom, $limitnum); if (!$rs->valid()) { $rs->close(); // Not going to iterate (but exit), close rs - return false; + return array(); } $objects = array(); foreach($rs as $value) { diff --git a/lib/dml/sqlite3_pdo_moodle_database.php b/lib/dml/sqlite3_pdo_moodle_database.php index 394e257bf2c16..9a1130f0f0e2d 100644 --- a/lib/dml/sqlite3_pdo_moodle_database.php +++ b/lib/dml/sqlite3_pdo_moodle_database.php @@ -208,7 +208,7 @@ protected function fetch_columns(string $table): array { } $createsql = $this->pdb->query($sql)->fetch(); if (!$createsql) { - return false; + return array(); } $createsql = $createsql['sql']; @@ -287,7 +287,10 @@ protected function fetch_columns(string $table): array { // trim extra quotes from text default values $columninfo['default_value'] = substr($columninfo['default_value'], 1, -1); } - $structure[$columninfo['name']] = new database_column_info($columninfo); + // database_column_info reads its fields via object property access, so it must + // be given an object like the pgsql and mysqli drivers do; passing the raw array + // leaves every property (including ->name) null. + $structure[$columninfo['name']] = new database_column_info((object) $columninfo); } return $structure; @@ -378,4 +381,20 @@ public function sql_concat_join($separator="' '", $elements=array()) { public function sql_bitxor($int1, $int2) { return '( ~' . $this->sql_bitand($int1, $int2) . ' & ' . $this->sql_bitor($int1, $int2) . ')'; } + + /** + * Connect, then initialise the temp-tables controller. Older cores (4.5) + * expect each driver to do this in connect(); without it $this->temptables + * stays null and the DDL generator fails during install. + * + * @return bool true on success + */ + public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, ?array $dboptions=null) { + $return = parent::connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions); + if ($this->temptables === null) { + require_once(__DIR__ . '/moodle_temptables.php'); + $this->temptables = new moodle_temptables($this); + } + return $return; + } }