Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-80464

Calling method on null object with SQLSRV a.k.a. MSSQL

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.1.6
    • Database SQL/XMLDB
    • None

      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, 

            Unassigned Unassigned
            mkwasnic Markus Kwaśnicki
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 minute
                1m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.