diff --git a/lib/dml/mssql_native_moodle_recordset.php b/lib/dml/mssql_native_moodle_recordset.php index 2c7b7110fbd..1bc800bdda4 100644 --- a/lib/dml/mssql_native_moodle_recordset.php +++ b/lib/dml/mssql_native_moodle_recordset.php @@ -41,9 +41,16 @@ class mssql_native_moodle_recordset extends moodle_recordset { } private function fetch_next() { - if ($row = mssql_fetch_assoc($this->rsrc)) { - $row = array_change_key_case($row, CASE_LOWER); + if (!$this->rsrc) { + return false; } + if (!$row = mssql_fetch_assoc($this->rsrc)) { + mssql_free_result($this->rsrc); + $this->rsrc = null; + return false; + } + + $row = array_change_key_case($row, CASE_LOWER); return $row; } diff --git a/lib/dml/mysqli_native_moodle_recordset.php b/lib/dml/mysqli_native_moodle_recordset.php index 230ef8c6edc..522eac5cacd 100644 --- a/lib/dml/mysqli_native_moodle_recordset.php +++ b/lib/dml/mysqli_native_moodle_recordset.php @@ -49,9 +49,16 @@ class mysqli_native_moodle_recordset extends moodle_recordset { } private function fetch_next() { - if ($row = $this->result->fetch_assoc()) { - $row = array_change_key_case($row, CASE_LOWER); + if (!$this->result) { + return false; } + if (!$row = $this->result->fetch_assoc()) { + $this->result->close(); + $this->result = null; + return false; + } + + $row = array_change_key_case($row, CASE_LOWER); return $row; } diff --git a/lib/dml/oci_native_moodle_recordset.php b/lib/dml/oci_native_moodle_recordset.php index e21e2310542..55ba1af64d8 100644 --- a/lib/dml/oci_native_moodle_recordset.php +++ b/lib/dml/oci_native_moodle_recordset.php @@ -41,11 +41,18 @@ class oci_native_moodle_recordset extends moodle_recordset { } private function fetch_next() { - if ($row = oci_fetch_array($this->stmt, OCI_ASSOC + OCI_RETURN_NULLS + OCI_RETURN_LOBS)) { - $row = array_change_key_case($row, CASE_LOWER); - unset($row['oracle_rownum']); - array_walk($row, array('oci_native_moodle_database', 'onespace2empty')); + if (!$this->stmt) { + return false; } + if (!$row = oci_fetch_array($this->stmt, OCI_ASSOC + OCI_RETURN_NULLS + OCI_RETURN_LOBS)) { + oci_free_statement($this->stmt); + $this->stmt = null; + return false; + } + + $row = array_change_key_case($row, CASE_LOWER); + unset($row['oracle_rownum']); + array_walk($row, array('oci_native_moodle_database', 'onespace2empty')); return $row; } diff --git a/lib/dml/pgsql_native_moodle_recordset.php b/lib/dml/pgsql_native_moodle_recordset.php index 76fe53ea01f..fd1f905e370 100644 --- a/lib/dml/pgsql_native_moodle_recordset.php +++ b/lib/dml/pgsql_native_moodle_recordset.php @@ -62,7 +62,14 @@ class pgsql_native_moodle_recordset extends moodle_recordset { } private function fetch_next() { - $row = pg_fetch_assoc($this->result); + if (!$this->result) { + return false; + } + if (!$row = pg_fetch_assoc($this->result)) { + pg_free_result($this->result); + $this->result = null; + return false; + } if ($this->blobs) { foreach ($this->blobs as $blob) { diff --git a/lib/dml/sqlsrv_native_moodle_recordset.php b/lib/dml/sqlsrv_native_moodle_recordset.php index 6ca88aad323..e397e2e52a2 100644 --- a/lib/dml/sqlsrv_native_moodle_recordset.php +++ b/lib/dml/sqlsrv_native_moodle_recordset.php @@ -41,10 +41,17 @@ class sqlsrv_native_moodle_recordset extends moodle_recordset { } private function fetch_next() { - if ($row = sqlsrv_fetch_array($this->rsrc, SQLSRV_FETCH_ASSOC)) { - unset($row['sqlsrvrownumber']); - $row = array_change_key_case($row, CASE_LOWER); + if (!$this->rsrc) { + return false; } + if (!$row = sqlsrv_fetch_array($this->rsrc, SQLSRV_FETCH_ASSOC)) { + sqlsrv_free_stmt($this->rsrc); + $this->rsrc = null; + return false; + } + + unset($row['sqlsrvrownumber']); + $row = array_change_key_case($row, CASE_LOWER); return $row; }