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
06147703
Commit
06147703
authored
Dec 16, 2013
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize table indexes introspection in DB2
parent
390db30f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
40 deletions
+25
-40
DB2Platform.php
lib/Doctrine/DBAL/Platforms/DB2Platform.php
+15
-1
Connection.php
lib/Doctrine/DBAL/Portability/Connection.php
+3
-0
DB2SchemaManager.php
lib/Doctrine/DBAL/Schema/DB2SchemaManager.php
+5
-37
SchemaManagerFunctionalTestCase.php
...BAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
+2
-2
No files found.
lib/Doctrine/DBAL/Platforms/DB2Platform.php
View file @
06147703
...
...
@@ -232,7 +232,21 @@ class DB2Platform extends AbstractPlatform
*/
public
function
getListTableIndexesSQL
(
$table
,
$currentDatabase
=
null
)
{
return
"SELECT NAME, COLNAMES, UNIQUERULE FROM SYSIBM.SYSINDEXES WHERE TBNAME = UPPER('"
.
$table
.
"')"
;
return
"SELECT idx.INDNAME AS key_name,
idxcol.COLNAME AS column_name,
CASE
WHEN idx.UNIQUERULE = 'P' THEN 1
ELSE 0
END AS primary,
CASE
WHEN idx.UNIQUERULE = 'D' THEN 1
ELSE 0
END AS non_unique
FROM SYSCAT.INDEXES AS idx
JOIN SYSCAT.INDEXCOLUSE AS idxcol
ON idx.INDSCHEMA = idxcol.INDSCHEMA AND idx.INDNAME = idxcol.INDNAME
WHERE idx.TABNAME = UPPER('"
.
$table
.
"')
ORDER BY idxcol.COLSEQ ASC"
;
}
/**
...
...
lib/Doctrine/DBAL/Portability/Connection.php
View file @
06147703
...
...
@@ -37,6 +37,7 @@ class Connection extends \Doctrine\DBAL\Connection
const
PORTABILITY_EMPTY_TO_NULL
=
4
;
const
PORTABILITY_FIX_CASE
=
8
;
const
PORTABILITY_DB2
=
1
;
const
PORTABILITY_ORACLE
=
9
;
const
PORTABILITY_POSTGRESQL
=
13
;
const
PORTABILITY_SQLITE
=
13
;
...
...
@@ -76,6 +77,8 @@ class Connection extends \Doctrine\DBAL\Connection
$params
[
'portability'
]
=
self
::
PORTABILITY_SQLANYWHERE
;
}
else
if
(
$this
->
_platform
->
getName
()
===
'sqlsrv'
)
{
$params
[
'portability'
]
=
$params
[
'portabililty'
]
&
self
::
PORTABILITY_SQLSRV
;
}
else
if
(
$this
->
_platform
->
getName
()
===
'db2'
)
{
$params
[
'portability'
]
=
$params
[
'portabililty'
]
&
self
::
PORTABILITY_DB2
;
}
else
{
$params
[
'portability'
]
=
$params
[
'portability'
]
&
self
::
PORTABILITY_OTHERVENDORS
;
}
...
...
lib/Doctrine/DBAL/Schema/DB2SchemaManager.php
View file @
06147703
...
...
@@ -118,46 +118,14 @@ class DB2SchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected
function
_getPortableTableIndexesList
(
$tableIndex
es
,
$tableName
=
null
)
protected
function
_getPortableTableIndexesList
(
$tableIndex
Rows
,
$tableName
=
null
)
{
$eventManager
=
$this
->
_platform
->
getEventManager
();
$indexes
=
array
();
foreach
(
$tableIndexes
as
$indexKey
=>
$data
)
{
$data
=
array_change_key_case
(
$data
,
\CASE_LOWER
);
$unique
=
(
$data
[
'uniquerule'
]
==
"D"
)
?
false
:
true
;
$primary
=
(
$data
[
'uniquerule'
]
==
"P"
);
$indexName
=
strtolower
(
$data
[
'name'
]);
$data
=
array
(
'name'
=>
$indexName
,
'columns'
=>
explode
(
"+"
,
ltrim
(
$data
[
'colnames'
],
'+'
)),
'unique'
=>
$unique
,
'primary'
=>
$primary
);
$index
=
null
;
$defaultPrevented
=
false
;
if
(
null
!==
$eventManager
&&
$eventManager
->
hasListeners
(
Events
::
onSchemaIndexDefinition
))
{
$eventArgs
=
new
SchemaIndexDefinitionEventArgs
(
$data
,
$tableName
,
$this
->
_conn
);
$eventManager
->
dispatchEvent
(
Events
::
onSchemaIndexDefinition
,
$eventArgs
);
$defaultPrevented
=
$eventArgs
->
isDefaultPrevented
();
$index
=
$eventArgs
->
getIndex
();
}
if
(
!
$defaultPrevented
)
{
$index
=
new
Index
(
$data
[
'name'
],
$data
[
'columns'
],
$data
[
'unique'
],
$data
[
'primary'
]);
}
if
(
$index
)
{
$indexes
[
$indexKey
]
=
$index
;
}
foreach
(
$tableIndexRows
as
&
$tableIndexRow
)
{
$tableIndexRow
=
array_change_key_case
(
$tableIndexRow
,
\CASE_LOWER
);
$tableIndexRow
[
'primary'
]
=
(
boolean
)
$tableIndexRow
[
'primary'
];
}
return
$indexes
;
return
parent
::
_getPortableTableIndexesList
(
$tableIndexRows
,
$tableName
)
;
}
/**
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
View file @
06147703
...
...
@@ -273,12 +273,12 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this
->
assertTrue
(
$tableIndexes
[
'primary'
]
->
isUnique
());
$this
->
assertTrue
(
$tableIndexes
[
'primary'
]
->
isPrimary
());
$this
->
assertEquals
(
'test_index_name'
,
$tableIndexes
[
'test_index_name'
]
->
getName
(
));
$this
->
assertEquals
(
'test_index_name'
,
strtolower
(
$tableIndexes
[
'test_index_name'
]
->
getName
()
));
$this
->
assertEquals
(
array
(
'test'
),
array_map
(
'strtolower'
,
$tableIndexes
[
'test_index_name'
]
->
getColumns
()));
$this
->
assertTrue
(
$tableIndexes
[
'test_index_name'
]
->
isUnique
());
$this
->
assertFalse
(
$tableIndexes
[
'test_index_name'
]
->
isPrimary
());
$this
->
assertEquals
(
'test_composite_idx'
,
$tableIndexes
[
'test_composite_idx'
]
->
getName
(
));
$this
->
assertEquals
(
'test_composite_idx'
,
strtolower
(
$tableIndexes
[
'test_composite_idx'
]
->
getName
()
));
$this
->
assertEquals
(
array
(
'id'
,
'test'
),
array_map
(
'strtolower'
,
$tableIndexes
[
'test_composite_idx'
]
->
getColumns
()));
$this
->
assertFalse
(
$tableIndexes
[
'test_composite_idx'
]
->
isUnique
());
$this
->
assertFalse
(
$tableIndexes
[
'test_composite_idx'
]
->
isPrimary
());
...
...
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