From 4c86f53abafc469909499ac9f96b71c08edf0800 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Wed, 21 Apr 2021 02:19:43 +0800 Subject: [PATCH] Use latest MCR image for sqlsrv --- .github/workflows/test-phpunit.yml | 11 ++++++----- system/Database/SQLSRV/Connection.php | 25 +++++++++++++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test-phpunit.yml b/.github/workflows/test-phpunit.yml index 3e37cff45cce..f16abb4da35f 100644 --- a/.github/workflows/test-phpunit.yml +++ b/.github/workflows/test-phpunit.yml @@ -62,13 +62,14 @@ jobs: - 5432:5432 options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3 mssql: - image: microsoft/mssql-server-linux:2017-latest + image: mcr.microsoft.com/mssql/server:2019-CU10-ubuntu-20.04 env: - SA_PASSWORD: 1Secure*Password1 + MSSQL_SA_PASSWORD: 1Secure*Password1 ACCEPT_EULA: Y MSSQL_PID: Developer ports: - 1433:1433 + options: --name=mssql --health-cmd="/opt/mssql-tools/bin/sqlcmd -S 127.0.0.1,1433 -U sa -P '1Secure*Password1' -Q 'SELECT @@VERSION'" --health-interval=10s --health-timeout=5s --health-retries=3 redis: image: redis ports: @@ -82,7 +83,7 @@ jobs: steps: - name: Create database for MSSQL Server if: matrix.db-platforms == 'SQLSRV' - run: sqlcmd -S 127.0.0.1 -U sa -P 1Secure*Password1 -Q "CREATE DATABASE test" + run: docker exec -i mssql /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1,1433 -U sa -P '1Secure*Password1' -Q 'CREATE DATABASE test' - name: Checkout uses: actions/checkout@v2 @@ -92,7 +93,7 @@ jobs: with: php-version: ${{ matrix.php-versions }} tools: composer, pecl - extensions: imagick, sqlsrv-beta, gd, sqlite3, redis, memcached, pgsql + extensions: imagick, sqlsrv-5.9.0preview1, gd, sqlite3, redis, memcached, pgsql coverage: xdebug env: update: true @@ -117,7 +118,7 @@ jobs: - name: Install dependencies run: | composer update --ansi --no-interaction - composer remove --ansi --dev --unused rector/rector phpstan/phpstan codeigniter4/codeigniter4-standard squizlabs/php_codesniffer + composer remove --ansi --dev --unused -W rector/rector phpstan/phpstan codeigniter4/codeigniter4-standard squizlabs/php_codesniffer php -r 'file_put_contents("vendor/laminas/laminas-zendframework-bridge/src/autoload.php", "");' env: COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }} diff --git a/system/Database/SQLSRV/Connection.php b/system/Database/SQLSRV/Connection.php index 51a906ed0d58..c7b6b1da28e8 100755 --- a/system/Database/SQLSRV/Connection.php +++ b/system/Database/SQLSRV/Connection.php @@ -103,7 +103,10 @@ public function __construct($params) /** * Connect to the database. * - * @param boolean $persistent + * @param boolean $persistent + * + * @throws DatabaseException + * * @return mixed */ public function connect(bool $persistent = false) @@ -114,9 +117,9 @@ public function connect(bool $persistent = false) 'UID' => empty($this->username) ? '' : $this->username, 'PWD' => empty($this->password) ? '' : $this->password, 'Database' => $this->database, - 'ConnectionPooling' => ($persistent === true) ? 1 : 0, + 'ConnectionPooling' => $persistent ? 1 : 0, 'CharacterSet' => $charset, - 'Encrypt' => ($this->encrypt === true) ? 1 : 0, + 'Encrypt' => $this->encrypt === true ? 1 : 0, 'ReturnDatesAsStrings' => 1, ]; @@ -127,9 +130,10 @@ public function connect(bool $persistent = false) unset($connection['UID'], $connection['PWD']); } - if (false !== ($this->connID = sqlsrv_connect($this->hostname, $connection))) + $this->connID = sqlsrv_connect($this->hostname, $connection); + + if ($this->connID !== false) { - /* Disable warnings as errors behavior. */ sqlsrv_configure('WarningsReturnAsErrors', 0); // Determine how identifiers are escaped @@ -138,9 +142,18 @@ public function connect(bool $persistent = false) $this->_quoted_identifier = empty($query) ? false : (bool) $query[0]->qi; $this->escapeChar = ($this->_quoted_identifier) ? '"' : ['[', ']']; + + return $this->connID; + } + + $errors = []; + + foreach (sqlsrv_errors(SQLSRV_ERR_ERRORS) as $error) + { + $errors[] = preg_replace('/(\[.+\]\[.+\](?:\[.+\])?)(.+)/', '$2', $error['message']); } - return $this->connID; + throw new DatabaseException(implode("\n", $errors)); } /**