Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
b8f58f2a
Unverified
Commit
b8f58f2a
authored
Jun 12, 2020
by
Sergei Morozov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix handling host and port configuration in sqlsrv and pdo_sqlsrv drivers
parent
e5e3abfe
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
17 deletions
+44
-17
PortWithoutHost.php
...e/DBAL/Driver/AbstractSQLServerDriver/PortWithoutHost.php
+20
-0
Driver.php
lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php
+6
-3
Driver.php
lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php
+10
-6
AbstractSQLServerDriverTest.php
...octrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php
+8
-8
No files found.
lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver/PortWithoutHost.php
0 → 100644
View file @
b8f58f2a
<?php
declare
(
strict_types
=
1
);
namespace
Doctrine\DBAL\Driver\AbstractSQLServerDriver
;
use
Doctrine\DBAL\Driver\AbstractDriverException
;
/**
* @internal
*
* @psalm-immutable
*/
final
class
PortWithoutHost
extends
AbstractDriverException
{
public
static
function
new
()
:
self
{
return
new
self
(
'Connection port specified without the host'
);
}
}
lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php
View file @
b8f58f2a
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
Doctrine\DBAL\Driver\PDOSqlsrv
;
namespace
Doctrine\DBAL\Driver\PDOSqlsrv
;
use
Doctrine\DBAL\Driver\AbstractSQLServerDriver
;
use
Doctrine\DBAL\Driver\AbstractSQLServerDriver
;
use
Doctrine\DBAL\Driver\AbstractSQLServerDriver\PortWithoutHost
;
use
function
is_int
;
use
function
is_int
;
use
function
sprintf
;
use
function
sprintf
;
...
@@ -48,10 +49,12 @@ class Driver extends AbstractSQLServerDriver
...
@@ -48,10 +49,12 @@ class Driver extends AbstractSQLServerDriver
if
(
isset
(
$params
[
'host'
]))
{
if
(
isset
(
$params
[
'host'
]))
{
$dsn
.=
$params
[
'host'
];
$dsn
.=
$params
[
'host'
];
}
if
(
isset
(
$params
[
'port'
])
&&
!
empty
(
$params
[
'port'
]))
{
if
(
isset
(
$params
[
'port'
]))
{
$dsn
.=
','
.
$params
[
'port'
];
$dsn
.=
','
.
$params
[
'port'
];
}
}
elseif
(
isset
(
$params
[
'port'
]))
{
throw
PortWithoutHost
::
new
();
}
}
if
(
isset
(
$params
[
'dbname'
]))
{
if
(
isset
(
$params
[
'dbname'
]))
{
...
...
lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php
View file @
b8f58f2a
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
Doctrine\DBAL\Driver\SQLSrv
;
namespace
Doctrine\DBAL\Driver\SQLSrv
;
use
Doctrine\DBAL\Driver\AbstractSQLServerDriver
;
use
Doctrine\DBAL\Driver\AbstractSQLServerDriver
;
use
Doctrine\DBAL\Driver\AbstractSQLServerDriver\PortWithoutHost
;
/**
/**
* Driver for ext/sqlsrv.
* Driver for ext/sqlsrv.
...
@@ -14,13 +15,16 @@ class Driver extends AbstractSQLServerDriver
...
@@ -14,13 +15,16 @@ class Driver extends AbstractSQLServerDriver
*/
*/
public
function
connect
(
array
$params
,
$username
=
null
,
$password
=
null
,
array
$driverOptions
=
[])
public
function
connect
(
array
$params
,
$username
=
null
,
$password
=
null
,
array
$driverOptions
=
[])
{
{
if
(
!
isset
(
$params
[
'host'
]))
{
$serverName
=
''
;
throw
new
SQLSrvException
(
"Missing 'host' in configuration for sqlsrv driver."
);
}
if
(
isset
(
$params
[
'host'
]))
{
$serverName
=
$params
[
'host'
];
$serverName
=
$params
[
'host'
];
if
(
isset
(
$params
[
'port'
]))
{
if
(
isset
(
$params
[
'port'
]))
{
$serverName
.=
','
.
$params
[
'port'
];
$serverName
.=
', '
.
$params
[
'port'
];
}
}
elseif
(
isset
(
$params
[
'port'
]))
{
throw
PortWithoutHost
::
new
();
}
}
if
(
isset
(
$params
[
'dbname'
]))
{
if
(
isset
(
$params
[
'dbname'
]))
{
...
...
tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php
View file @
b8f58f2a
...
@@ -3,8 +3,7 @@
...
@@ -3,8 +3,7 @@
namespace
Doctrine\Tests\DBAL\Driver
;
namespace
Doctrine\Tests\DBAL\Driver
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver\AbstractSQLServerDriver\PortWithoutHost
;
use
Doctrine\DBAL\Driver\AbstractSQLServerDriver
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Platforms\SQLServer2005Platform
;
use
Doctrine\DBAL\Platforms\SQLServer2005Platform
;
use
Doctrine\DBAL\Platforms\SQLServer2008Platform
;
use
Doctrine\DBAL\Platforms\SQLServer2008Platform
;
...
@@ -13,13 +12,8 @@ use Doctrine\DBAL\Platforms\SQLServerPlatform;
...
@@ -13,13 +12,8 @@ use Doctrine\DBAL\Platforms\SQLServerPlatform;
use
Doctrine\DBAL\Schema\AbstractSchemaManager
;
use
Doctrine\DBAL\Schema\AbstractSchemaManager
;
use
Doctrine\DBAL\Schema\SQLServerSchemaManager
;
use
Doctrine\DBAL\Schema\SQLServerSchemaManager
;
class
AbstractSQLServerDriverTest
extends
AbstractDriverTest
abstract
class
AbstractSQLServerDriverTest
extends
AbstractDriverTest
{
{
protected
function
createDriver
()
:
Driver
{
return
$this
->
getMockForAbstractClass
(
AbstractSQLServerDriver
::
class
);
}
protected
function
createPlatform
()
:
AbstractPlatform
protected
function
createPlatform
()
:
AbstractPlatform
{
{
return
new
SQLServer2008Platform
();
return
new
SQLServer2008Platform
();
...
@@ -64,4 +58,10 @@ class AbstractSQLServerDriverTest extends AbstractDriverTest
...
@@ -64,4 +58,10 @@ class AbstractSQLServerDriverTest extends AbstractDriverTest
[
'12'
,
SQLServer2012Platform
::
class
],
[
'12'
,
SQLServer2012Platform
::
class
],
];
];
}
}
public
function
testPortWithoutHost
()
:
void
{
$this
->
expectException
(
PortWithoutHost
::
class
);
$this
->
driver
->
connect
([
'port'
=>
1433
]);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment