-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
4.1.6
-
None
-
MOODLE_401_STABLE
-
fix_mssql_is-null-temptable
We are operating Moodle with Microsoft SQL Server. Sometimes we find SQL errors in the log files saying
PHP Fatal error: Uncaught Error: Call to a member function is_temptable() on null in /var/www/html/moodle/lib/dml/sqlsrv_native_moodle_database.php:365")
I looked into that particular file and found that the usage of is_temptable(...) method is sometimes being checked for the caller being a null object but sometimes it is not! That's why I supplemented the check for null object caller at any occurrence.
You can see my patch at my GitHub fork: fix(sqlsrv): Fix for calling is_temptable(...) method on null object or here
diff --git a/lib/dml/sqlsrv_native_moodle_database.php b/lib/dml/sqlsrv_native_moodle_database.php
|
index 272b63387cd..20f5c32c4aa 100644 |
--- a/lib/dml/sqlsrv_native_moodle_database.php
|
+++ b/lib/dml/sqlsrv_native_moodle_database.php
|
@@ -362,7 +362,7 @@ class sqlsrv_native_moodle_database extends moodle_database { |
foreach ($matches[0] as $key => $match) { |
$name = $matches[1][$key]; |
|
- if ($this->temptables->is_temptable($name)) { |
+ if ($this->temptables && $this->temptables->is_temptable($name)) { |
$sql = str_replace($match, $this->temptables->get_correct_name($name), $sql); |
} else { |
$sql = str_replace($match, $this->prefix.$name, $sql); |
@@ -549,7 +549,7 @@ class sqlsrv_native_moodle_database extends moodle_database { |
protected function fetch_columns(string $table): array { |
$structure = array();
|
|
- if (!$this->temptables->is_temptable($table)) { // normal table, get metadata from own schema |
+ if ($this->temptables && !$this->temptables->is_temptable($table)) { // normal table, get metadata from own schema |
$sql = "SELECT column_name AS name,
|
data_type AS type,
|
numeric_precision AS max_length,
|