From d17d7263fdbc9c649f4dece1e4181b9c6a3aa4ad Mon Sep 17 00:00:00 2001 From: Meirza Date: Fri, 16 Dec 2022 20:52:11 +0700 Subject: [PATCH] MDL-77669 dml: Added extrainfo in the DB options config. extrainfo is an extra information for the DB driver, e.g. SQL Server, has additional configuration according to its environment, which the administrator can specify to alter and override any connection options. Co-authored-by: LukeCarrier This is a backport of MDL-64153. --- config-dist.php | 4 ++++ lib/dml/sqlsrv_native_moodle_database.php | 27 ++++++++++++++--------- lib/upgrade.txt | 5 +++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/config-dist.php b/config-dist.php index f96aeea7127..9355072d785 100644 --- a/config-dist.php +++ b/config-dist.php @@ -70,6 +70,10 @@ $CFG->dboptions = array( // can be removed for MySQL (by default it will // use 'utf8mb4_unicode_ci'. This option should // be removed for all other databases. + // 'extrainfo' => [], // Extra information for the DB driver, e.g. SQL Server, + // has additional configuration according to its environment, + // which the administrator can specify to alter and + // override any connection options. // 'fetchbuffersize' => 100000, // On PostgreSQL, this option sets a limit // on the number of rows that are fetched into // memory when doing a large recordset query diff --git a/lib/dml/sqlsrv_native_moodle_database.php b/lib/dml/sqlsrv_native_moodle_database.php index 86349f3c24e..308393216d1 100644 --- a/lib/dml/sqlsrv_native_moodle_database.php +++ b/lib/dml/sqlsrv_native_moodle_database.php @@ -208,21 +208,28 @@ class sqlsrv_native_moodle_database extends moodle_database { $this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions); + $options = [ + 'UID' => $this->dbuser, + 'PWD' => $this->dbpass, + 'Database' => $this->dbname, + 'CharacterSet' => 'UTF-8', + 'MultipleActiveResultSets' => true, + 'ConnectionPooling' => !empty($this->dboptions['dbpersist']), + 'ReturnDatesAsStrings' => true, + ]; + $dbhost = $this->dbhost; if (!empty($dboptions['dbport'])) { $dbhost .= ',' . $dboptions['dbport']; } - $this->sqlsrv = sqlsrv_connect($dbhost, array - ( - 'UID' => $this->dbuser, - 'PWD' => $this->dbpass, - 'Database' => $this->dbname, - 'CharacterSet' => 'UTF-8', - 'MultipleActiveResultSets' => true, - 'ConnectionPooling' => !empty($this->dboptions['dbpersist']), - 'ReturnDatesAsStrings' => true, - )); + // The sqlsrv_connect() has a lot of connection options to be used. + // Users can add any supported options with the 'extrainfo' key in the dboptions. + if (isset($this->dboptions['extrainfo'])) { + $options = array_merge($options, $this->dboptions['extrainfo']); + } + + $this->sqlsrv = sqlsrv_connect($dbhost, $options); if ($this->sqlsrv === false) { $this->sqlsrv = null; diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 5e91604c3bf..8b4d3d651eb 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -1,6 +1,11 @@ This files describes API changes in core libraries and APIs, information provided here is intended especially for developers. +===3.9.21=== +* Added 'extrainfo' in the DB options config. Its extra information for the DB driver, e.g. SQL Server, + has additional configuration according to its environment, which the administrator can specify to alter and + override any connection options. + ===3.9.12=== * Two new helper functions have been added to lib/datalib.php, for safely preparing SQL ORDER BY statements where user interactions define sort parameters (see the respective docblocks for full details and examples):