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
5a8297a3
Commit
5a8297a3
authored
Apr 06, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #300 from deeky666/improve-sql-server-list-table-indexes
Improve list SQL Server table indexes
parents
fe04d1f1
05c1d190
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
52 deletions
+21
-52
SQLServerPlatform.php
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
+15
-1
SQLServerSchemaManager.php
lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php
+6
-51
No files found.
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
View file @
5a8297a3
...
...
@@ -553,7 +553,21 @@ class SQLServerPlatform extends AbstractPlatform
*/
public
function
getListTableIndexesSQL
(
$table
,
$currentDatabase
=
null
)
{
return
"exec sp_helpindex '"
.
$table
.
"'"
;
return
"SELECT idx.name AS key_name,
col.name AS column_name,
~idx.is_unique AS non_unique,
idx.is_primary_key AS [primary],
CASE idx.type
WHEN '1' THEN 'clustered'
WHEN '2' THEN 'nonclustered'
ELSE NULL
END AS flags
FROM sys.tables AS tbl
JOIN sys.indexes AS idx ON tbl.object_id = idx.object_id
JOIN sys.index_columns AS idxcol ON idx.object_id = idxcol.object_id AND idx.index_id = idxcol.index_id
JOIN sys.columns AS col ON idxcol.object_id = col.object_id AND idxcol.column_id = col.column_id
WHERE tbl.name = '
$table
'
ORDER BY idx.index_id ASC, idxcol.index_column_id ASC"
;
}
/**
...
...
lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php
View file @
5a8297a3
...
...
@@ -19,8 +19,6 @@
namespace
Doctrine\DBAL\Schema
;
use
Doctrine\DBAL\Events
;
use
Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs
;
use
Doctrine\DBAL\Driver\SQLSrv\SQLSrvException
;
use
Doctrine\DBAL\Types\Type
;
...
...
@@ -142,60 +140,17 @@ class SQLServerSchemaManager extends AbstractSchemaManager
}
/**
*
@override
*
{@inheritdoc}
*/
protected
function
_getPortableTableIndexesList
(
$tableIndexRows
,
$tableName
=
null
)
{
// TODO: Remove code duplication with AbstractSchemaManager;
$result
=
array
();
foreach
(
$tableIndexRows
as
$tableIndex
)
{
$indexName
=
$keyName
=
$tableIndex
[
'index_name'
];
if
(
strpos
(
$tableIndex
[
'index_description'
],
'primary key'
)
!==
false
)
{
$keyName
=
'primary'
;
}
$keyName
=
strtolower
(
$keyName
);
$flags
=
array
();
if
(
strpos
(
$tableIndex
[
'index_description'
],
'clustered'
)
!==
false
)
{
$flags
[]
=
'clustered'
;
}
else
if
(
strpos
(
$tableIndex
[
'index_description'
],
'nonclustered'
)
!==
false
)
{
$flags
[]
=
'nonclustered'
;
}
$result
[
$keyName
]
=
array
(
'name'
=>
$indexName
,
'columns'
=>
explode
(
', '
,
$tableIndex
[
'index_keys'
]),
'unique'
=>
strpos
(
$tableIndex
[
'index_description'
],
'unique'
)
!==
false
,
'primary'
=>
strpos
(
$tableIndex
[
'index_description'
],
'primary key'
)
!==
false
,
'flags'
=>
$flags
,
);
}
$eventManager
=
$this
->
_platform
->
getEventManager
();
$indexes
=
array
();
foreach
(
$result
as
$indexKey
=>
$data
)
{
$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
&
$tableIndex
)
{
$tableIndex
[
'non_unique'
]
=
(
boolean
)
$tableIndex
[
'non_unique'
];
$tableIndex
[
'primary'
]
=
(
boolean
)
$tableIndex
[
'primary'
];
$tableIndex
[
'flags'
]
=
$tableIndex
[
'flags'
]
?
array
(
$tableIndex
[
'flags'
])
:
null
;
}
return
$indexes
;
return
parent
::
_getPortableTableIndexesList
(
$tableIndexRows
,
$tableName
)
;
}
/**
...
...
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