Skip to content

Commit c83a9cf

Browse files
authored
Use latest MCR image for sqlsrv (#4554)
1 parent 5682810 commit c83a9cf

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

.github/workflows/test-phpunit.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,14 @@ jobs:
6262
- 5432:5432
6363
options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3
6464
mssql:
65-
image: microsoft/mssql-server-linux:2017-latest
65+
image: mcr.microsoft.com/mssql/server:2019-CU10-ubuntu-20.04
6666
env:
6767
SA_PASSWORD: 1Secure*Password1
6868
ACCEPT_EULA: Y
6969
MSSQL_PID: Developer
7070
ports:
7171
- 1433:1433
72+
options: --health-cmd="/opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U sa -P 1Secure*Password1 -Q 'SELECT @@VERSION'" --health-interval=10s --health-timeout=5s --health-retries=3
7273
redis:
7374
image: redis
7475
ports:
@@ -92,7 +93,7 @@ jobs:
9293
with:
9394
php-version: ${{ matrix.php-versions }}
9495
tools: composer, pecl
95-
extensions: imagick, sqlsrv-beta, gd, sqlite3, redis, memcached, pgsql
96+
extensions: imagick, sqlsrv, gd, sqlite3, redis, memcached, pgsql
9697
coverage: xdebug
9798
env:
9899
update: true
@@ -117,7 +118,7 @@ jobs:
117118
- name: Install dependencies
118119
run: |
119120
composer update --ansi --no-interaction
120-
composer remove --ansi --dev --unused rector/rector phpstan/phpstan codeigniter4/codeigniter4-standard squizlabs/php_codesniffer
121+
composer remove --ansi --dev --unused -W rector/rector phpstan/phpstan codeigniter4/codeigniter4-standard squizlabs/php_codesniffer
121122
php -r 'file_put_contents("vendor/laminas/laminas-zendframework-bridge/src/autoload.php", "");'
122123
env:
123124
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}

system/Database/SQLSRV/Connection.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ public function __construct($params)
103103
/**
104104
* Connect to the database.
105105
*
106-
* @param boolean $persistent
106+
* @param boolean $persistent
107+
*
108+
* @throws DatabaseException
109+
*
107110
* @return mixed
108111
*/
109112
public function connect(bool $persistent = false)
@@ -114,9 +117,9 @@ public function connect(bool $persistent = false)
114117
'UID' => empty($this->username) ? '' : $this->username,
115118
'PWD' => empty($this->password) ? '' : $this->password,
116119
'Database' => $this->database,
117-
'ConnectionPooling' => ($persistent === true) ? 1 : 0,
120+
'ConnectionPooling' => $persistent ? 1 : 0,
118121
'CharacterSet' => $charset,
119-
'Encrypt' => ($this->encrypt === true) ? 1 : 0,
122+
'Encrypt' => $this->encrypt === true ? 1 : 0,
120123
'ReturnDatesAsStrings' => 1,
121124
];
122125

@@ -127,9 +130,10 @@ public function connect(bool $persistent = false)
127130
unset($connection['UID'], $connection['PWD']);
128131
}
129132

130-
if (false !== ($this->connID = sqlsrv_connect($this->hostname, $connection)))
133+
$this->connID = sqlsrv_connect($this->hostname, $connection);
134+
135+
if ($this->connID !== false)
131136
{
132-
/* Disable warnings as errors behavior. */
133137
sqlsrv_configure('WarningsReturnAsErrors', 0);
134138

135139
// Determine how identifiers are escaped
@@ -138,9 +142,18 @@ public function connect(bool $persistent = false)
138142

139143
$this->_quoted_identifier = empty($query) ? false : (bool) $query[0]->qi;
140144
$this->escapeChar = ($this->_quoted_identifier) ? '"' : ['[', ']'];
145+
146+
return $this->connID;
147+
}
148+
149+
$errors = [];
150+
151+
foreach (sqlsrv_errors(SQLSRV_ERR_ERRORS) as $error)
152+
{
153+
$errors[] = preg_replace('/(\[.+\]\[.+\](?:\[.+\])?)(.+)/', '$2', $error['message']);
141154
}
142155

143-
return $this->connID;
156+
throw new DatabaseException(implode("\n", $errors));
144157
}
145158

146159
/**

0 commit comments

Comments
 (0)