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
e5e3abfe
Unverified
Commit
e5e3abfe
authored
Jun 12, 2020
by
Sergei Morozov
Committed by
GitHub
Jun 12, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4066 from morozov/issues/4065
Fix DSN detection in the IBM DB2 driver
parents
3745877c
747b0420
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
130 additions
and
21 deletions
+130
-21
DB2Driver.php
lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php
+9
-20
DataSourceName.php
lib/Doctrine/DBAL/Driver/IBMDB2/DataSourceName.php
+75
-0
DataSourceNameTest.php
.../Doctrine/Tests/DBAL/Driver/IBMDB2/DataSourceNameTest.php
+45
-0
ibm_db2.travis.xml
tests/travis/ibm_db2.travis.xml
+1
-1
No files found.
lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php
View file @
e5e3abfe
...
...
@@ -14,27 +14,16 @@ class DB2Driver extends AbstractDB2Driver
*/
public
function
connect
(
array
$params
,
$username
=
null
,
$password
=
null
,
array
$driverOptions
=
[])
{
if
(
!
isset
(
$params
[
'protocol'
]))
{
$params
[
'protocol'
]
=
'TCPIP'
;
}
if
(
$params
[
'host'
]
!==
'localhost'
&&
$params
[
'host'
]
!==
'127.0.0.1'
)
{
// if the host isn't localhost, use extended connection params
$params
[
'dbname'
]
=
'DRIVER={IBM DB2 ODBC DRIVER}'
.
';DATABASE='
.
$params
[
'dbname'
]
.
';HOSTNAME='
.
$params
[
'host'
]
.
';PROTOCOL='
.
$params
[
'protocol'
]
.
';UID='
.
$username
.
';PWD='
.
$password
.
';'
;
if
(
isset
(
$params
[
'port'
]))
{
$params
[
'dbname'
]
.=
'PORT='
.
$params
[
'port'
];
}
$username
=
null
;
$password
=
null
;
}
$params
[
'user'
]
=
$username
;
$params
[
'password'
]
=
$password
;
$params
[
'dbname'
]
=
DataSourceName
::
fromConnectionParameters
(
$params
)
->
toString
();
return
new
DB2Connection
(
$params
,
(
string
)
$username
,
(
string
)
$password
,
$driverOptions
);
return
new
DB2Connection
(
$params
,
(
string
)
$username
,
(
string
)
$password
,
$driverOptions
);
}
/**
...
...
lib/Doctrine/DBAL/Driver/IBMDB2/DataSourceName.php
0 → 100644
View file @
e5e3abfe
<?php
declare
(
strict_types
=
1
);
namespace
Doctrine\DBAL\Driver\IBMDB2
;
use
function
implode
;
use
function
sprintf
;
use
function
strpos
;
/**
* IBM DB2 DSN
*/
final
class
DataSourceName
{
/** @var string */
private
$string
;
private
function
__construct
(
string
$string
)
{
$this
->
string
=
$string
;
}
public
function
toString
()
:
string
{
return
$this
->
string
;
}
/**
* Creates the object from an array representation
*
* @param array<string,mixed> $params
*/
public
static
function
fromArray
(
array
$params
)
:
self
{
$chunks
=
[];
foreach
(
$params
as
$key
=>
$value
)
{
$chunks
[]
=
sprintf
(
'%s=%s'
,
$key
,
$value
);
}
return
new
self
(
implode
(
';'
,
$chunks
));
}
/**
* Creates the object from the given DBAL connection parameters.
*
* @param array<string,mixed> $params
*/
public
static
function
fromConnectionParameters
(
array
$params
)
:
self
{
if
(
isset
(
$params
[
'dbname'
])
&&
strpos
(
$params
[
'dbname'
],
'='
)
!==
false
)
{
return
new
self
(
$params
[
'dbname'
]);
}
$dsnParams
=
[];
foreach
([
'host'
=>
'HOSTNAME'
,
'port'
=>
'PORT'
,
'protocol'
=>
'PROTOCOL'
,
'dbname'
=>
'DATABASE'
,
'user'
=>
'UID'
,
'password'
=>
'PWD'
,
]
as
$dbalParam
=>
$dsnParam
)
{
if
(
!
isset
(
$params
[
$dbalParam
]))
{
continue
;
}
$dsnParams
[
$dsnParam
]
=
$params
[
$dbalParam
];
}
return
self
::
fromArray
(
$dsnParams
);
}
}
tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DataSourceNameTest.php
0 → 100644
View file @
e5e3abfe
<?php
namespace
Doctrine\Tests\DBAL\Driver\IBMDB2
;
use
Doctrine\DBAL\Driver\IBMDB2\DataSourceName
;
use
PHPUnit\Framework\TestCase
;
class
DataSourceNameTest
extends
TestCase
{
/**
* @param mixed[] $params
*
* @dataProvider connectionParametersProvider
*/
public
function
testFromConnectionParameters
(
array
$params
,
string
$expected
)
:
void
{
$dsn
=
DataSourceName
::
fromConnectionParameters
(
$params
);
$this
->
assertSame
(
$expected
,
$dsn
->
toString
());
}
/**
* @return iterable<string,array<int,mixed>>
*/
public
static
function
connectionParametersProvider
()
:
iterable
{
yield
'empty-params'
=>
[[],
''
];
yield
'cataloged-database'
=>
[
[
'host'
=>
'localhost'
,
'port'
=>
50000
,
'dbname'
=>
'doctrine'
,
'user'
=>
'db2inst1'
,
'password'
=>
'Passw0rd'
,
],
'HOSTNAME=localhost;PORT=50000;DATABASE=doctrine;UID=db2inst1;PWD=Passw0rd'
,
];
yield
'uncataloged-database'
=>
[
[
'dbname'
=>
'HOSTNAME=localhost;PORT=50000;DATABASE=doctrine;UID=db2inst1;PWD=Passw0rd'
],
'HOSTNAME=localhost;PORT=50000;DATABASE=doctrine;UID=db2inst1;PWD=Passw0rd'
,
];
}
}
tests/travis/ibm_db2.travis.xml
View file @
e5e3abfe
...
...
@@ -14,7 +14,7 @@
<var
name=
"db_host"
value=
"127.0.0.1"
/>
<var
name=
"db_user"
value=
"db2inst1"
/>
<var
name=
"db_password"
value=
"Doctrine2018"
/>
<var
name=
"db_dbname"
value=
"
HOSTNAME=127.0.0.1;UID=db2inst1;PWD=Doctrine2018;DATABASE=
doctrine"
/>
<var
name=
"db_dbname"
value=
"doctrine"
/>
</php>
<testsuites>
...
...
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