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
0397f760
Commit
0397f760
authored
Jun 26, 2011
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'DBAL-126' into 2.0.x
parents
fea10ddb
ad6b0cca
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
15 deletions
+77
-15
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+22
-7
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+26
-7
MySqlPlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
+29
-1
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
0397f760
...
...
@@ -959,18 +959,33 @@ abstract class AbstractPlatform
if
(
count
(
$columns
)
==
0
)
{
throw
new
\InvalidArgumentException
(
"Incomplete definition. 'columns' required."
);
}
if
(
$index
->
isPrimary
())
{
return
$this
->
getCreatePrimaryKeySQL
(
$index
,
$table
);
}
else
{
$type
=
''
;
if
(
$index
->
isUnique
())
{
$type
=
'UNIQUE '
;
}
$type
=
''
;
if
(
$index
->
isUnique
())
{
$type
=
'UNIQUE '
;
$query
=
'CREATE '
.
$type
.
'INDEX '
.
$name
.
' ON '
.
$table
;
$query
.=
' ('
.
$this
->
getIndexFieldDeclarationListSQL
(
$columns
)
.
')'
;
}
$query
=
'CREATE '
.
$type
.
'INDEX '
.
$name
.
' ON '
.
$table
;
$query
.=
' ('
.
$this
->
getIndexFieldDeclarationListSQL
(
$columns
)
.
')'
;
return
$query
;
}
/**
* Get SQL to create an unnamed primary key constraint.
*
* @param Index $index
* @param string|Table $table
* @return string
*/
public
function
getCreatePrimaryKeySQL
(
Index
$index
,
$table
)
{
return
'ALTER TABLE '
.
$table
.
' ADD PRIMARY KEY ('
.
$this
->
getIndexFieldDeclarationListSQL
(
$index
->
getColumns
())
.
')'
;
}
/**
* Quotes a string so that it can be safely used as a table or column name,
...
...
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
0397f760
...
...
@@ -20,7 +20,9 @@
namespace
Doctrine\DBAL\Platforms
;
use
Doctrine\DBAL\DBALException
,
Doctrine\DBAL\Schema\TableDiff
;
Doctrine\DBAL\Schema\TableDiff
,
Doctrine\DBAL\Schema\Index
,
Doctrine\DBAL\Schema\Table
;
/**
* The MySqlPlatform provides the behavior, features and SQL dialect of the
...
...
@@ -523,20 +525,37 @@ class MySqlPlatform extends AbstractPlatform
* @override
*/
public
function
getDropIndexSQL
(
$index
,
$table
=
null
)
{
if
(
$index
instanceof
\Doctrine\DBAL\Schema\Index
)
{
$index
=
$index
->
getQuotedName
(
$this
);
}
else
if
(
!
is_string
(
$index
))
{
{
if
(
$index
instanceof
Index
)
{
$indexName
=
$index
->
getQuotedName
(
$this
);
}
else
if
(
is_string
(
$index
))
{
$indexName
=
$index
;
}
else
{
throw
new
\InvalidArgumentException
(
'MysqlPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'
);
}
if
(
$table
instanceof
\Doctrine\DBAL\Schema\
Table
)
{
if
(
$table
instanceof
Table
)
{
$table
=
$table
->
getQuotedName
(
$this
);
}
else
if
(
!
is_string
(
$table
))
{
throw
new
\InvalidArgumentException
(
'MysqlPlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'
);
}
if
(
$index
instanceof
Index
&&
$index
->
isPrimary
())
{
// mysql primary keys are always named "PRIMARY",
// so we cannot use them in statements because of them being keyword.
return
$this
->
getDropPrimaryKeySQL
(
$table
);
}
return
'DROP INDEX '
.
$index
.
' ON '
.
$table
;
return
'DROP INDEX '
.
$indexName
.
' ON '
.
$table
;
}
/**
* @param Index $index
* @param Table $table
*/
protected
function
getDropPrimaryKeySQL
(
$table
)
{
return
'ALTER TABLE '
.
$table
.
' DROP PRIMARY KEY'
;
}
/**
...
...
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
View file @
0397f760
...
...
@@ -4,6 +4,8 @@ namespace Doctrine\Tests\DBAL\Platforms;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\Schema
;
require_once
__DIR__
.
'/../../TestInit.php'
;
...
...
@@ -16,7 +18,7 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
public
function
testGenerateMixedCaseTableCreate
()
{
$table
=
new
\Doctrine\DBAL\Schema\
Table
(
"Foo"
);
$table
=
new
Table
(
"Foo"
);
$table
->
addColumn
(
"Bar"
,
"integer"
);
$sql
=
$this
->
_platform
->
getCreateTableSQL
(
$table
);
...
...
@@ -144,6 +146,32 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
{
return
'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table(id)'
;
}
/**
* @group DBAL-126
*/
public
function
testUniquePrimaryKey
()
{
$keyTable
=
new
Table
(
"foo"
);
$keyTable
->
addColumn
(
"bar"
,
"integer"
);
$keyTable
->
addColumn
(
"baz"
,
"string"
);
$keyTable
->
setPrimaryKey
(
array
(
"bar"
));
$keyTable
->
addUniqueIndex
(
array
(
"baz"
));
$oldTable
=
new
Table
(
"foo"
);
$oldTable
->
addColumn
(
"bar"
,
"integer"
);
$oldTable
->
addColumn
(
"baz"
,
"string"
);
$c
=
new
\Doctrine\DBAL\Schema\Comparator
;
$diff
=
$c
->
diffTable
(
$oldTable
,
$keyTable
);
$sql
=
$this
->
_platform
->
getAlterTableSQL
(
$diff
);
$this
->
assertEquals
(
array
(
"ALTER TABLE foo ADD PRIMARY KEY (bar)"
,
"CREATE UNIQUE INDEX UNIQ_8C73652178240498 ON foo (baz)"
,
),
$sql
);
}
public
function
testModifyLimitQuery
()
{
...
...
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