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
27b78e0a
Commit
27b78e0a
authored
Jun 26, 2011
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'DBAL-126'
parents
48c78a2d
4c383bd8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
8 deletions
+51
-8
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+22
-7
MySqlPlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
+29
-1
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
27b78e0a
...
@@ -1124,18 +1124,33 @@ abstract class AbstractPlatform
...
@@ -1124,18 +1124,33 @@ abstract class AbstractPlatform
throw
new
\InvalidArgumentException
(
"Incomplete definition. 'columns' required."
);
throw
new
\InvalidArgumentException
(
"Incomplete definition. 'columns' required."
);
}
}
if
(
$index
->
isPrimary
())
{
return
$this
->
getCreatePrimaryKeySQL
(
$index
,
$table
);
}
else
{
$type
=
''
;
$type
=
''
;
if
(
$index
->
isUnique
())
{
if
(
$index
->
isUnique
())
{
$type
=
'UNIQUE '
;
$type
=
'UNIQUE '
;
}
}
$query
=
'CREATE '
.
$type
.
'INDEX '
.
$name
.
' ON '
.
$table
;
$query
=
'CREATE '
.
$type
.
'INDEX '
.
$name
.
' ON '
.
$table
;
$query
.=
' ('
.
$this
->
getIndexFieldDeclarationListSQL
(
$columns
)
.
')'
;
$query
.=
' ('
.
$this
->
getIndexFieldDeclarationListSQL
(
$columns
)
.
')'
;
}
return
$query
;
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,
* Quotes a string so that it can be safely used as a table or column name,
* even if it is a reserved word of the platform.
* even if it is a reserved word of the platform.
...
...
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
View file @
27b78e0a
...
@@ -4,6 +4,8 @@ namespace Doctrine\Tests\DBAL\Platforms;
...
@@ -4,6 +4,8 @@ namespace Doctrine\Tests\DBAL\Platforms;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\Schema
;
require_once
__DIR__
.
'/../../TestInit.php'
;
require_once
__DIR__
.
'/../../TestInit.php'
;
...
@@ -16,7 +18,7 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
...
@@ -16,7 +18,7 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
public
function
testGenerateMixedCaseTableCreate
()
public
function
testGenerateMixedCaseTableCreate
()
{
{
$table
=
new
\Doctrine\DBAL\Schema\
Table
(
"Foo"
);
$table
=
new
Table
(
"Foo"
);
$table
->
addColumn
(
"Bar"
,
"integer"
);
$table
->
addColumn
(
"Bar"
,
"integer"
);
$sql
=
$this
->
_platform
->
getCreateTableSQL
(
$table
);
$sql
=
$this
->
_platform
->
getCreateTableSQL
(
$table
);
...
@@ -145,6 +147,32 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
...
@@ -145,6 +147,32 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
return
'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table(id)'
;
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
()
public
function
testModifyLimitQuery
()
{
{
$sql
=
$this
->
_platform
->
modifyLimitQuery
(
'SELECT * FROM user'
,
10
,
0
);
$sql
=
$this
->
_platform
->
modifyLimitQuery
(
'SELECT * FROM user'
,
10
,
0
);
...
...
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