Skip to content

Debugging SQL Server in Actions #4554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 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
ACCEPT_EULA: Y
MSSQL_PID: Developer
ports:
- 1433:1433
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
redis:
image: redis
ports:
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, 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