Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions admin/environment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4523,6 +4523,7 @@
<VENDOR name="postgres" version="13" />
<VENDOR name="mssql" version="14.0" />
<VENDOR name="oracle" version="19" />
<VENDOR name="sqlite" version="3.0" />
</DATABASE>
<PHP version="8.1.0" level="required">
<RESTRICT function="restrict_php_version_84" message="unsupportedphpversion84" />
Expand Down
22 changes: 20 additions & 2 deletions lib/ddl/sqlite_sql_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions lib/dml/pdo_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
23 changes: 21 additions & 2 deletions lib/dml/sqlite3_pdo_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Loading