From 0cc9a140cd25e9cf48d5e7ec451a696872872923 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Tue, 13 Oct 2020 16:08:27 +1300 Subject: [PATCH] FIX Silverstripe expects dates as strings --- src/MSSQLAzureDatabase.php | 1 + src/MSSQLDatabaseConfigurationHelper.php | 3 ++- src/SQLServerConnector.php | 15 +++++++++------ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/MSSQLAzureDatabase.php b/src/MSSQLAzureDatabase.php index f9611a4..043b6d4 100644 --- a/src/MSSQLAzureDatabase.php +++ b/src/MSSQLAzureDatabase.php @@ -57,6 +57,7 @@ protected function connectDatabase($database) { $parameters = $this->parameters; $parameters['database'] = $database; + $parameters['returndatesasstrings'] = 1; $parameters['multipleactiveresultsets'] = 1; // Ensure that driver is available (required by PDO) diff --git a/src/MSSQLDatabaseConfigurationHelper.php b/src/MSSQLDatabaseConfigurationHelper.php index e3ac96c..e71da73 100644 --- a/src/MSSQLDatabaseConfigurationHelper.php +++ b/src/MSSQLDatabaseConfigurationHelper.php @@ -45,7 +45,8 @@ protected function createConnection($databaseConfig, &$error) // Azure has additional parameter requirements if ($this->isAzure($databaseConfig)) { $parameters['database'] = $databaseConfig['database']; - $parameters['multipleactiveresultsets'] = 0; + $parameters['multipleactiveresultsets'] = 1; + $parameters['returndatesasstrings'] = 1; } $conn = @sqlsrv_connect($databaseConfig['server'], $parameters); diff --git a/src/SQLServerConnector.php b/src/SQLServerConnector.php index f6aa4bf..91c11b5 100644 --- a/src/SQLServerConnector.php +++ b/src/SQLServerConnector.php @@ -47,13 +47,16 @@ public function connect($parameters, $selectDB = false) } $charset = isset($parameters['charset']) ? $parameters : 'UTF-8'; - $multiResultSets = isset($parameters['multipleactiveresultsets']) - ? $parameters['multipleactiveresultsets'] - : true; - $options = array( + + $options = [ 'CharacterSet' => $charset, - 'MultipleActiveResultSets' => $multiResultSets - ); + 'ReturnDatesAsStrings' => isset($parameters['returndatesasstrings']) + ? $parameters['returndatesasstrings'] + : true, + 'MultipleActiveResultSets' => isset($parameters['multipleactiveresultsets']) + ? $parameters['multipleactiveresultsets'] + : true + ]; if (!(defined('MSSQL_USE_WINDOWS_AUTHENTICATION') && MSSQL_USE_WINDOWS_AUTHENTICATION == true) && empty($parameters['windowsauthentication'])