Skip to content

Commit

Permalink
MDL-64153 dml: Added extrainfo in the DB options config.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
meirzamoodle and LukeCarrier committed Jan 5, 2023
1 parent b8b905c commit f8537ff
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
4 changes: 4 additions & 0 deletions config-dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
// e.g. PaaS on Azure. Default is false/unset.
// Uncomment and set to true to force MySQL and
// MariaDB to use 'SELECT VERSION();'.
// '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
Expand Down
27 changes: 17 additions & 10 deletions lib/dml/sqlsrv_native_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,21 +208,28 @@ public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dbop

$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;
Expand Down
3 changes: 3 additions & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ information provided here is intended especially for developers.
It only worked with http sites and did not officially support SSL, and is at risk of disappearing should Yahoo! decide
to remove it.
* New `properties_filter` method of persistent class for filtering properties of a record against persistent definition
* 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.

=== 4.1 ===

Expand Down

0 comments on commit f8537ff

Please sign in to comment.