Skip to content
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

Testing of MSSQL on Windows with AppVeyor #2617

Merged
merged 5 commits into from
Mar 16, 2018
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
108 changes: 108 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
build: false
platform:
- x64
#matrix:
# fast_finish: true # kills the build at the first failure
clone_folder: C:\projects\dbal
clone_depth: 1

cache:
- C:\ProgramData\chocolatey\bin -> .appveyor.yml
- C:\ProgramData\chocolatey\lib -> .appveyor.yml
- c:\tools\php -> .appveyor.yml
- composer.phar
- '%LOCALAPPDATA%\Composer\files'
#- vendor

## Build matrix for lowest and highest possible targets
environment:
matrix:
- db: mssql
driver: sqlsrv
db_version: sql2008r2sp2
php: 7.1
- db: mssql
driver: sqlsrv
db_version: sql2012sp1
php: 7.1
- db: mssql
driver: sqlsrv
db_version: sql2017
php: 7.1
- db: mssql
driver: pdo_sqlsrv
db_version: sql2017
php: 7.1

init:
- SET PATH=C:\Program Files\OpenSSL;c:\tools\php;%PATH%
- SET COMPOSER_NO_INTERACTION=1
- SET ANSICON=121x90 (121x90)

## Install PHP and composer, and run the appropriate composer command
install:
- ps: |
# Check if installation is cached
if (!(Test-Path c:\tools\php)) {
appveyor-retry cinst --params '""/InstallDir:C:\tools\php""' --ignore-checksums -y php --version ((choco search php --exact --all-versions -r | select-string -pattern $env:php | sort { [version]($_ -split '\|' | select -last 1) } -Descending | Select-Object -first 1) -replace '[php|]','')
# install sqlite
appveyor-retry cinst -y sqlite
Get-ChildItem -Path c:\tools\php
cd c:\tools\php

# Set PHP environment items that are always needed
copy php.ini-production php.ini
Add-Content php.ini "`n date.timezone=UTC"
Add-Content php.ini "`n extension_dir=ext"
Add-Content php.ini "`n extension=php_openssl.dll"
Add-Content php.ini "`n extension=php_mbstring.dll"
Add-Content php.ini "`n extension=php_fileinfo.dll"
Add-Content php.ini "`n extension=php_pdo_sqlite.dll"
Add-Content php.ini "`n extension=php_sqlite3.dll"

# If needed get the MSSQL DLL's
if ($env:db -eq "mssql") {
$DLLVersion = "5.2.0rc1"
cd c:\tools\php\ext
$source = "https://windows.php.net/downloads/pecl/releases/sqlsrv/$($DLLVersion)/php_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc14-x64.zip"
$destination = "c:\tools\php\ext\php_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc14-x64.zip"
Invoke-WebRequest $source -OutFile $destination
7z x -y php_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc14-x64.zip > $null
$source = "https://windows.php.net/downloads/pecl/releases/pdo_sqlsrv/$($DLLVersion)/php_pdo_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc14-x64.zip"
$destination = "c:\tools\php\ext\php_pdo_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc14-x64.zip"
Invoke-WebRequest $source -OutFile $destination
7z x -y php_pdo_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc14-x64.zip > $null
Remove-Item c:\tools\php\* -include .zip
cd c:\tools\php
Add-Content php.ini "`nextension=php_sqlsrv.dll"
Add-Content php.ini "`nextension=php_pdo_sqlsrv.dll"
Add-Content php.ini "`n"
}

cd c:\projects\dbal

if (!(Test-Path c:\projects\dbal\composer.phar)) {
appveyor-retry appveyor DownloadFile https://getcomposer.org/composer.phar
}
}
# install composer dependencies
- appveyor-retry php composer.phar self-update
- appveyor-retry php composer.phar install --no-progress --profile

before_test:
# Selectively start the services
- ps: >-
if ($env:db -eq "mssql") {
$instanceName = $env:db_version.ToUpper()
Start-Service "MSSQL`$$instanceName"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@photodude is there a reason we use Start-Service and not net start? As per the Appveyor's suggestion in appveyor/ci#2204 (comment), it could be the reason for intermittent login failures.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's based on appveyor documentation https://www.appveyor.com/docs/services-databases/

If they have some new thing they suggest to do, their documentation does not reflect that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@photodude thanks. Trying to change this in #3071.

}

test_script:
- cd C:\projects\dbal
- ps: >-
if ($env:db_version) {
vendor\bin\phpunit -c tests\appveyor\%db%.%db_version%.%driver%.appveyor.xml
}
else {
vendor\bin\phpunit -c tests\appveyor\%db%.%driver%.appveyor.xml
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.gitattributes export-ignore
.gitignore export-ignore
.gitmodules export-ignore
.appveyor.yml export-ignore
.travis.yml export-ignore
build.properties export-ignore
build.xml export-ignore
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
}
},
"archive": {
"exclude": ["!vendor", "tests", "*phpunit.xml", ".travis.yml", "build.xml", "build.properties", "composer.phar"]
"exclude": ["!vendor", "tests", "*phpunit.xml", ".appveyor.yml", ".travis.yml", "build.xml", "build.properties", "composer.phar"]
}
}
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ public function lastInsertId($name = null)
if ($name !== null) {
$stmt = $this->prepare('SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?');
$stmt->execute([$name]);

return $stmt->fetchColumn();
} else {
$stmt = $this->query('SELECT @@IDENTITY');
}

return $this->lastInsertId->getId();
return $stmt->fetchColumn();
}

/**
Expand Down
7 changes: 4 additions & 3 deletions lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use Doctrine\DBAL\Driver\Statement;
use function func_get_args;

/**
* SQL Server Statement.
Expand Down Expand Up @@ -348,19 +349,19 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n

switch ($fetchMode) {
case FetchMode::CUSTOM_OBJECT:
while ($row = call_user_func_array([$this, 'fetch'], func_get_args())) {
while (($row = $this->fetch(...func_get_args())) !== false) {
$rows[] = $row;
}
break;

case FetchMode::COLUMN:
while ($row = $this->fetchColumn()) {
while (($row = $this->fetchColumn()) !== false) {
$rows[] = $row;
}
break;

default:
while ($row = $this->fetch($fetchMode)) {
while (($row = $this->fetch($fetchMode)) !== false) {
$rows[] = $row;
}
}
Expand Down
27 changes: 19 additions & 8 deletions lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Types;
use function implode;
use function sprintf;

/**
* The SQLServerPlatform provides the behavior, features and SQL dialect of the
Expand Down Expand Up @@ -1207,19 +1209,29 @@ public function getBooleanTypeDeclarationSQL(array $field)
*/
protected function doModifyLimitQuery($query, $limit, $offset = null)
{
if ($limit === null) {
return $query;
$where = [];

if ($offset > 0) {
$where[] = sprintf('doctrine_rownum >= %d', $offset + 1);
}

$start = $offset + 1;
$end = $offset + $limit;
if ($limit !== null) {
$where[] = sprintf('doctrine_rownum <= %d', $offset + $limit);
$top = sprintf('TOP %d', $offset + $limit);
} else {
$top = 'TOP 9223372036854775807';
}

if (empty($where)) {
return $query;
}

// We'll find a SELECT or SELECT distinct and prepend TOP n to it
// Even if the TOP n is very large, the use of a CTE will
// allow the SQL Server query planner to optimize it so it doesn't
// actually scan the entire range covered by the TOP clause.
$selectPattern = '/^(\s*SELECT\s+(?:DISTINCT\s+)?)(.*)$/im';
$replacePattern = sprintf('$1%s $2', "TOP $end");
$replacePattern = sprintf('$1%s $2', $top);
$query = preg_replace($selectPattern, $replacePattern, $query);

if (stristr($query, "ORDER BY")) {
Expand All @@ -1234,10 +1246,9 @@ protected function doModifyLimitQuery($query, $limit, $offset = null)
. "SELECT * FROM ("
. "SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS doctrine_rownum FROM dctrn_cte"
. ") AS doctrine_tbl "
. "WHERE doctrine_rownum BETWEEN %d AND %d ORDER BY doctrine_rownum ASC",
. 'WHERE %s ORDER BY doctrine_rownum ASC',
$query,
$start,
$end
implode(' AND ', $where)
);
}

Expand Down
11 changes: 7 additions & 4 deletions tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

use Doctrine\DBAL\Driver\Mysqli\MysqliConnection;
use Doctrine\DBAL\Driver\Mysqli\MysqliException;
use Doctrine\Tests\DbalTestCase;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\Tests\DbalFunctionalTestCase;

class MysqliConnectionTest extends DbalTestCase
class MysqliConnectionTest extends DbalFunctionalTestCase
{
/**
* The mysqli driver connection mock under test.
Expand All @@ -23,6 +24,10 @@ protected function setUp()

parent::setUp();

if (! $this->_conn->getDatabasePlatform() instanceof MySqlPlatform) {
$this->markTestSkipped('MySQL only test.');
}

$this->connectionMock = $this->getMockBuilder(MysqliConnection::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
Expand All @@ -49,6 +54,4 @@ public function testRestoresErrorHandlerOnException()
restore_error_handler();
restore_error_handler();
}

}

Loading