Skip to content

Commit

Permalink
Use latest MCR image for sqlsrv
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Apr 20, 2021
1 parent dfbc85a commit 4c86f53
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/test-phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 }}
Expand Down
25 changes: 19 additions & 6 deletions system/Database/SQLSRV/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
];

Expand All @@ -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
Expand All @@ -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));
}

/**
Expand Down

0 comments on commit 4c86f53

Please sign in to comment.