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
148a049d
Commit
148a049d
authored
Jan 29, 2012
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote branch 'origin/2.1.x' into 2.1.x
parents
4d74fc0f
41359f21
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
195 additions
and
40 deletions
+195
-40
DB2Driver.php
lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php
+6
-3
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+1
-1
MsSqlPlatform.php
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
+1
-1
OraclePlatform.php
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
+16
-10
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+3
-2
SqlitePlatform.php
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
+1
-0
AbstractSchemaManager.php
lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
+3
-3
MySqlSchemaManager.php
lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php
+35
-17
Table.php
lib/Doctrine/DBAL/Schema/Table.php
+1
-1
SchemaManagerFunctionalTestCase.php
...BAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
+15
-1
AbstractPlatformTestCase.php
...octrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
+16
-1
MySqlPlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
+5
-0
OraclePlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
+8
-0
PostgreSqlPlatformTest.php
.../Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
+8
-0
MySqlSchemaManagerTest.php
tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php
+76
-0
No files found.
lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php
View file @
148a049d
...
@@ -41,8 +41,8 @@ class DB2Driver implements Driver
...
@@ -41,8 +41,8 @@ class DB2Driver implements Driver
*/
*/
public
function
connect
(
array
$params
,
$username
=
null
,
$password
=
null
,
array
$driverOptions
=
array
())
public
function
connect
(
array
$params
,
$username
=
null
,
$password
=
null
,
array
$driverOptions
=
array
())
{
{
if
(
!
isset
(
$params
[
'schema'
])
)
{
if
(
!
isset
(
$params
[
'protocol'
])
)
{
$params
[
'protocol'
]
=
'TCPIP'
;
}
}
if
(
$params
[
'host'
]
!==
'localhost'
&&
$params
[
'host'
]
!=
'127.0.0.1'
)
{
if
(
$params
[
'host'
]
!==
'localhost'
&&
$params
[
'host'
]
!=
'127.0.0.1'
)
{
...
@@ -50,10 +50,13 @@ class DB2Driver implements Driver
...
@@ -50,10 +50,13 @@ class DB2Driver implements Driver
$params
[
'dbname'
]
=
'DRIVER={IBM DB2 ODBC DRIVER}'
.
$params
[
'dbname'
]
=
'DRIVER={IBM DB2 ODBC DRIVER}'
.
';DATABASE='
.
$params
[
'dbname'
]
.
';DATABASE='
.
$params
[
'dbname'
]
.
';HOSTNAME='
.
$params
[
'host'
]
.
';HOSTNAME='
.
$params
[
'host'
]
.
';PORT='
.
$params
[
'port'
]
.
';PROTOCOL='
.
$params
[
'protocol'
]
.
';PROTOCOL='
.
$params
[
'protocol'
]
.
';UID='
.
$username
.
';UID='
.
$username
.
';PWD='
.
$password
.
';'
;
';PWD='
.
$password
.
';'
;
if
(
isset
(
$params
[
'port'
]))
{
$params
[
'dbname'
]
.=
'PORT='
.
$params
[
'port'
];
}
$username
=
null
;
$username
=
null
;
$password
=
null
;
$password
=
null
;
}
}
...
...
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
148a049d
...
@@ -987,7 +987,7 @@ abstract class AbstractPlatform
...
@@ -987,7 +987,7 @@ abstract class AbstractPlatform
$sql
=
$this
->
_getCreateTableSQL
(
$tableName
,
$columns
,
$options
);
$sql
=
$this
->
_getCreateTableSQL
(
$tableName
,
$columns
,
$options
);
if
(
$this
->
supportsCommentOnStatement
())
{
if
(
$this
->
supportsCommentOnStatement
())
{
foreach
(
$table
->
getColumns
()
AS
$column
)
{
foreach
(
$table
->
getColumns
()
AS
$column
)
{
if
(
$
column
->
getComment
(
))
{
if
(
$
this
->
getColumnComment
(
$column
))
{
$sql
[]
=
$this
->
getCommentOnColumnSQL
(
$tableName
,
$column
->
getName
(),
$this
->
getColumnComment
(
$column
));
$sql
[]
=
$this
->
getCommentOnColumnSQL
(
$tableName
,
$column
->
getName
(),
$this
->
getColumnComment
(
$column
));
}
}
}
}
...
...
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
View file @
148a049d
...
@@ -596,7 +596,7 @@ class MsSqlPlatform extends AbstractPlatform
...
@@ -596,7 +596,7 @@ class MsSqlPlatform extends AbstractPlatform
}
}
if
(
$offset
==
0
)
{
if
(
$offset
==
0
)
{
$query
=
preg_replace
(
'/^
SELECT\s/i'
,
'SELECT
TOP '
.
$count
.
' '
,
$query
);
$query
=
preg_replace
(
'/^
(SELECT\s(DISTINCT\s)?)/i'
,
'\1
TOP '
.
$count
.
' '
,
$query
);
}
else
{
}
else
{
$orderby
=
stristr
(
$query
,
'ORDER BY'
);
$orderby
=
stristr
(
$query
,
'ORDER BY'
);
...
...
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
View file @
148a049d
...
@@ -450,16 +450,13 @@ END;';
...
@@ -450,16 +450,13 @@ END;';
cols.position,
cols.position,
r_alc.table_name
\"
references_table
\"
,
r_alc.table_name
\"
references_table
\"
,
r_cols.column_name
\"
foreign_column
\"
r_cols.column_name
\"
foreign_column
\"
FROM
all
_cons_columns cols
FROM
user
_cons_columns cols
LEFT JOIN
all
_constraints alc
LEFT JOIN
user
_constraints alc
ON alc.constraint_name = cols.constraint_name
ON alc.constraint_name = cols.constraint_name
AND alc.owner = cols.owner
LEFT JOIN user_constraints r_alc
LEFT JOIN all_constraints r_alc
ON alc.r_constraint_name = r_alc.constraint_name
ON alc.r_constraint_name = r_alc.constraint_name
AND alc.r_owner = r_alc.owner
LEFT JOIN user_cons_columns r_cols
LEFT JOIN all_cons_columns r_cols
ON r_alc.constraint_name = r_cols.constraint_name
ON r_alc.constraint_name = r_cols.constraint_name
AND r_alc.owner = r_cols.owner
AND cols.position = r_cols.position
AND cols.position = r_cols.position
WHERE alc.constraint_name = cols.constraint_name
WHERE alc.constraint_name = cols.constraint_name
AND alc.constraint_type = 'R'
AND alc.constraint_type = 'R'
...
@@ -475,9 +472,18 @@ LEFT JOIN all_cons_columns r_cols
...
@@ -475,9 +472,18 @@ LEFT JOIN all_cons_columns r_cols
public
function
getListTableColumnsSQL
(
$table
,
$database
=
null
)
public
function
getListTableColumnsSQL
(
$table
,
$database
=
null
)
{
{
$table
=
strtoupper
(
$table
);
$table
=
strtoupper
(
$table
);
return
"SELECT c.*, d.comments FROM all_tab_columns c "
.
"INNER JOIN all_col_comments d ON d.OWNER = c.OWNER AND d.TABLE_NAME = c.TABLE_NAME AND d.COLUMN_NAME = c.COLUMN_NAME "
.
$tabColumnsTableName
=
"user_tab_columns"
;
"WHERE c.table_name = '"
.
$table
.
"' ORDER BY c.column_name"
;
$ownerCondition
=
''
;
if
(
null
!==
$database
){
$database
=
strtoupper
(
$database
);
$tabColumnsTableName
=
"all_tab_columns"
;
$ownerCondition
=
"AND c.owner = '"
.
$database
.
"'"
;
}
return
"SELECT c.*, d.comments FROM
$tabColumnsTableName
c "
.
"INNER JOIN user_col_comments d ON d.TABLE_NAME = c.TABLE_NAME AND d.COLUMN_NAME = c.COLUMN_NAME "
.
"WHERE c.table_name = '"
.
$table
.
"' "
.
$ownerCondition
.
" ORDER BY c.column_name"
;
}
}
/**
/**
...
...
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
148a049d
...
@@ -269,10 +269,11 @@ class PostgreSqlPlatform extends AbstractPlatform
...
@@ -269,10 +269,11 @@ class PostgreSqlPlatform extends AbstractPlatform
$whereClause
=
$namespaceAlias
.
".nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast') AND "
;
$whereClause
=
$namespaceAlias
.
".nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast') AND "
;
if
(
strpos
(
$table
,
"."
)
!==
false
)
{
if
(
strpos
(
$table
,
"."
)
!==
false
)
{
list
(
$schema
,
$table
)
=
explode
(
"."
,
$table
);
list
(
$schema
,
$table
)
=
explode
(
"."
,
$table
);
$
whereClause
.=
"
$classAlias
.relname = '"
.
$table
.
"' AND
$namespaceAlias
.nspname =
'"
.
$schema
.
"'"
;
$
schema
=
"
'"
.
$schema
.
"'"
;
}
else
{
}
else
{
$
whereClause
.=
"
$classAlias
.relname = '"
.
$table
.
"'
"
;
$
schema
=
"ANY(string_to_array((select setting from pg_catalog.pg_settings where name = 'search_path'),','))
"
;
}
}
$whereClause
.=
"
$classAlias
.relname = '"
.
$table
.
"' AND
$namespaceAlias
.nspname =
$schema
"
;
return
$whereClause
;
return
$whereClause
;
}
}
...
...
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
View file @
148a049d
...
@@ -470,6 +470,7 @@ class SqlitePlatform extends AbstractPlatform
...
@@ -470,6 +470,7 @@ class SqlitePlatform extends AbstractPlatform
'longtext'
=>
'text'
,
'longtext'
=>
'text'
,
'text'
=>
'text'
,
'text'
=>
'text'
,
'varchar'
=>
'string'
,
'varchar'
=>
'string'
,
'longvarchar'
=>
'string'
,
'varchar2'
=>
'string'
,
'varchar2'
=>
'string'
,
'nvarchar'
=>
'string'
,
'nvarchar'
=>
'string'
,
'image'
=>
'string'
,
'image'
=>
'string'
,
...
...
lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
View file @
148a049d
...
@@ -473,8 +473,8 @@ abstract class AbstractSchemaManager
...
@@ -473,8 +473,8 @@ abstract class AbstractSchemaManager
*/
*/
public
function
dropAndCreateSequence
(
Sequence
$sequence
)
public
function
dropAndCreateSequence
(
Sequence
$sequence
)
{
{
$this
->
tryMethod
(
'
createSequence'
,
$seqName
,
$start
,
$allocationSize
);
$this
->
tryMethod
(
'
dropSequence'
,
$sequence
->
getQuotedName
(
$this
->
_platform
)
);
$this
->
createSequence
(
$seq
Name
,
$start
,
$allocationSiz
e
);
$this
->
createSequence
(
$seq
uenc
e
);
}
}
/**
/**
...
@@ -799,4 +799,4 @@ abstract class AbstractSchemaManager
...
@@ -799,4 +799,4 @@ abstract class AbstractSchemaManager
{
{
return
str_replace
(
'(DC2Type:'
.
$type
.
')'
,
''
,
$comment
);
return
str_replace
(
'(DC2Type:'
.
$type
.
')'
,
''
,
$comment
);
}
}
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php
View file @
148a049d
...
@@ -170,26 +170,44 @@ class MySqlSchemaManager extends AbstractSchemaManager
...
@@ -170,26 +170,44 @@ class MySqlSchemaManager extends AbstractSchemaManager
return
new
Column
(
$tableColumn
[
'field'
],
\Doctrine\DBAL\Types\Type
::
getType
(
$type
),
$options
);
return
new
Column
(
$tableColumn
[
'field'
],
\Doctrine\DBAL\Types\Type
::
getType
(
$type
),
$options
);
}
}
p
ublic
function
_getPortableTableForeignKeyDefinition
(
$tableForeignKey
)
p
rotected
function
_getPortableTableForeignKeysList
(
$tableForeignKeys
)
{
{
$tableForeignKey
=
array_change_key_case
(
$tableForeignKey
,
CASE_LOWER
);
$list
=
array
();
foreach
(
$tableForeignKeys
as
$key
=>
$value
)
{
$value
=
array_change_key_case
(
$value
,
CASE_LOWER
);
if
(
!
isset
(
$list
[
$value
[
'constraint_name'
]]))
{
if
(
!
isset
(
$value
[
'delete_rule'
])
||
$value
[
'delete_rule'
]
==
"RESTRICT"
)
{
$value
[
'delete_rule'
]
=
null
;
}
if
(
!
isset
(
$value
[
'update_rule'
])
||
$value
[
'update_rule'
]
==
"RESTRICT"
)
{
$value
[
'update_rule'
]
=
null
;
}
if
(
!
isset
(
$tableForeignKey
[
'delete_rule'
])
||
$tableForeignKey
[
'delete_rule'
]
==
"RESTRICT"
)
{
$list
[
$value
[
'constraint_name'
]]
=
array
(
$tableForeignKey
[
'delete_rule'
]
=
null
;
'name'
=>
$value
[
'constraint_name'
],
'local'
=>
array
(),
'foreign'
=>
array
(),
'foreignTable'
=>
$value
[
'referenced_table_name'
],
'onDelete'
=>
$value
[
'delete_rule'
],
'onUpdate'
=>
$value
[
'update_rule'
],
);
}
$list
[
$value
[
'constraint_name'
]][
'local'
][]
=
$value
[
'column_name'
];
$list
[
$value
[
'constraint_name'
]][
'foreign'
][]
=
$value
[
'referenced_column_name'
];
}
}
if
(
!
isset
(
$tableForeignKey
[
'update_rule'
])
||
$tableForeignKey
[
'update_rule'
]
==
"RESTRICT"
)
{
$tableForeignKey
[
'update_rule'
]
=
null
;
$result
=
array
();
foreach
(
$list
AS
$constraint
)
{
$result
[]
=
new
ForeignKeyConstraint
(
array_values
(
$constraint
[
'local'
]),
$constraint
[
'foreignTable'
],
array_values
(
$constraint
[
'foreign'
]),
$constraint
[
'name'
],
array
(
'onDelete'
=>
$constraint
[
'onDelete'
],
'onUpdate'
=>
$constraint
[
'onUpdate'
],
)
);
}
}
return
new
ForeignKeyConstraint
(
return
$result
;
(
array
)
$tableForeignKey
[
'column_name'
],
$tableForeignKey
[
'referenced_table_name'
],
(
array
)
$tableForeignKey
[
'referenced_column_name'
],
$tableForeignKey
[
'constraint_name'
],
array
(
'onUpdate'
=>
$tableForeignKey
[
'update_rule'
],
'onDelete'
=>
$tableForeignKey
[
'delete_rule'
],
)
);
}
}
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Schema/Table.php
View file @
148a049d
...
@@ -167,7 +167,7 @@ class Table extends AbstractAsset
...
@@ -167,7 +167,7 @@ class Table extends AbstractAsset
*/
*/
public
function
addUniqueIndex
(
array
$columnNames
,
$indexName
=
null
)
public
function
addUniqueIndex
(
array
$columnNames
,
$indexName
=
null
)
{
{
if
(
$indexName
==
null
)
{
if
(
$indexName
==
=
null
)
{
$indexName
=
$this
->
_generateIdentifierName
(
$indexName
=
$this
->
_generateIdentifierName
(
array_merge
(
array
(
$this
->
getName
()),
$columnNames
),
"uniq"
,
$this
->
_getMaxIdentifierLength
()
array_merge
(
array
(
$this
->
getName
()),
$columnNames
),
"uniq"
,
$this
->
_getMaxIdentifierLength
()
);
);
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
View file @
148a049d
...
@@ -31,6 +31,19 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
...
@@ -31,6 +31,19 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this
->
_sm
=
$this
->
_conn
->
getSchemaManager
();
$this
->
_sm
=
$this
->
_conn
->
getSchemaManager
();
}
}
/**
* @group DBAL-195
*/
public
function
testDropAndCreateSequence
()
{
if
(
!
$this
->
_conn
->
getDatabasePlatform
()
->
supportsSequences
())
{
$this
->
markTestSkipped
(
$this
->
_conn
->
getDriver
()
->
getName
()
.
' does not support sequences.'
);
}
$sequence
=
new
\Doctrine\DBAL\Schema\Sequence
(
'dropcreate_sequences_test_seq'
,
20
,
10
);
$this
->
_sm
->
dropAndCreateSequence
(
$sequence
);
}
public
function
testListSequences
()
public
function
testListSequences
()
{
{
if
(
!
$this
->
_conn
->
getDatabasePlatform
()
->
supportsSequences
())
{
if
(
!
$this
->
_conn
->
getDatabasePlatform
()
->
supportsSequences
())
{
...
@@ -522,4 +535,5 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
...
@@ -522,4 +535,5 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
}
}
$this
->
assertTrue
(
$foundTable
,
"Could not find new table"
);
$this
->
assertTrue
(
$foundTable
,
"Could not find new table"
);
}
}
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
View file @
148a049d
...
@@ -205,6 +205,16 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
...
@@ -205,6 +205,16 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this
->
assertEquals
(
$this
->
getAlterTableColumnCommentsSQL
(),
$this
->
_platform
->
getAlterTableSQL
(
$tableDiff
));
$this
->
assertEquals
(
$this
->
getAlterTableColumnCommentsSQL
(),
$this
->
_platform
->
getAlterTableSQL
(
$tableDiff
));
}
}
public
function
testCreateTableColumnTypeComments
()
{
$table
=
new
\Doctrine\DBAL\Schema\Table
(
'test'
);
$table
->
addColumn
(
'id'
,
'integer'
);
$table
->
addColumn
(
'data'
,
'array'
);
$table
->
setPrimaryKey
(
array
(
'id'
));
$this
->
assertEquals
(
$this
->
getCreateTableColumnTypeCommentsSQL
(),
$this
->
_platform
->
getCreateTableSQL
(
$table
));
}
public
function
getCreateTableColumnCommentsSQL
()
public
function
getCreateTableColumnCommentsSQL
()
{
{
$this
->
markTestSkipped
(
'Platform does not support Column comments.'
);
$this
->
markTestSkipped
(
'Platform does not support Column comments.'
);
...
@@ -214,7 +224,12 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
...
@@ -214,7 +224,12 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
{
{
$this
->
markTestSkipped
(
'Platform does not support Column comments.'
);
$this
->
markTestSkipped
(
'Platform does not support Column comments.'
);
}
}
public
function
getCreateTableColumnTypeCommentsSQL
()
{
$this
->
markTestSkipped
(
'Platform does not support Column comments.'
);
}
/**
/**
* @group DBAL-45
* @group DBAL-45
*/
*/
...
...
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
View file @
148a049d
...
@@ -204,4 +204,9 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
...
@@ -204,4 +204,9 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
{
{
return
array
(
"ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'"
);
return
array
(
"ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'"
);
}
}
public
function
getCreateTableColumnTypeCommentsSQL
()
{
return
array
(
"CREATE TABLE test (id INT NOT NULL, data LONGTEXT NOT NULL COMMENT '(DC2Type:array)', PRIMARY KEY(id)) ENGINE = InnoDB"
);
}
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
View file @
148a049d
...
@@ -195,6 +195,14 @@ class OraclePlatformTest extends AbstractPlatformTestCase
...
@@ -195,6 +195,14 @@ class OraclePlatformTest extends AbstractPlatformTestCase
);
);
}
}
public
function
getCreateTableColumnTypeCommentsSQL
()
{
return
array
(
"CREATE TABLE test (id NUMBER(10) NOT NULL, data CLOB NOT NULL, PRIMARY KEY(id))"
,
"COMMENT ON COLUMN test.data IS '(DC2Type:array)'"
);
}
public
function
getAlterTableColumnCommentsSQL
()
public
function
getAlterTableColumnCommentsSQL
()
{
{
return
array
(
return
array
(
...
...
tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
View file @
148a049d
...
@@ -216,4 +216,12 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
...
@@ -216,4 +216,12 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
"COMMENT ON COLUMN mytable.baz IS 'B comment'"
,
"COMMENT ON COLUMN mytable.baz IS 'B comment'"
,
);
);
}
}
public
function
getCreateTableColumnTypeCommentsSQL
()
{
return
array
(
"CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY(id))"
,
"COMMENT ON COLUMN test.data IS '(DC2Type:array)'"
);
}
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php
0 → 100644
View file @
148a049d
<?php
namespace
Doctrine\Tests\DBAL\Schema
;
require_once
__DIR__
.
'/../../TestInit.php'
;
use
Doctrine\Common\EventManager
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Configuration
;
use
Doctrine\DBAL\Events
;
use
Doctrine\DBAL\Schema\MySqlSchemaManager
;
use
Doctrine\Tests\DBAL\Mocks
;
use
Doctrine\Tests\TestUtil
;
class
MySqlSchemaManagerTest
extends
\PHPUnit_Framework_TestCase
{
/**
*
* @var \Doctrine\DBAL\Schema\AbstractSchemaManager
*/
private
$manager
;
public
function
setUp
()
{
$eventManager
=
new
EventManager
();
$driverMock
=
$this
->
getMock
(
'Doctrine\DBAL\Driver'
);
$platform
=
$this
->
getMock
(
'Doctrine\DBAL\Platforms\MySqlPlatform'
);
$this
->
conn
=
$this
->
getMock
(
'Doctrine\DBAL\Connection'
,
array
(
'fetchAll'
),
array
(
array
(
'platform'
=>
$platform
),
$driverMock
,
new
Configuration
(),
$eventManager
)
);
$this
->
manager
=
new
MySqlSchemaManager
(
$this
->
conn
);
}
public
function
testCompositeForeignKeys
()
{
$this
->
conn
->
expects
(
$this
->
once
())
->
method
(
'fetchAll'
)
->
will
(
$this
->
returnValue
(
$this
->
getFKDefinition
()));
$fkeys
=
$this
->
manager
->
listTableForeignKeys
(
'dummy'
);
$this
->
assertEquals
(
1
,
count
(
$fkeys
),
"Table has to have one foreign key."
);
$this
->
assertInstanceOf
(
'Doctrine\DBAL\Schema\ForeignKeyConstraint'
,
$fkeys
[
0
]);
$this
->
assertEquals
(
array
(
'column_1'
,
'column_2'
,
'column_3'
),
array_map
(
'strtolower'
,
$fkeys
[
0
]
->
getLocalColumns
()));
$this
->
assertEquals
(
array
(
'column_1'
,
'column_2'
,
'column_3'
),
array_map
(
'strtolower'
,
$fkeys
[
0
]
->
getForeignColumns
()));
}
public
function
getFKDefinition
()
{
return
array
(
array
(
"CONSTRAINT_NAME"
=>
"FK_C1B1712387FE737264DE5A5511B8B3E"
,
"COLUMN_NAME"
=>
"column_1"
,
"REFERENCED_TABLE_NAME"
=>
"dummy"
,
"REFERENCED_COLUMN_NAME"
=>
"column_1"
,
"update_rule"
=>
"RESTRICT"
,
"delete_rule"
=>
"RESTRICT"
,
),
array
(
"CONSTRAINT_NAME"
=>
"FK_C1B1712387FE737264DE5A5511B8B3E"
,
"COLUMN_NAME"
=>
"column_2"
,
"REFERENCED_TABLE_NAME"
=>
"dummy"
,
"REFERENCED_COLUMN_NAME"
=>
"column_2"
,
"update_rule"
=>
"RESTRICT"
,
"delete_rule"
=>
"RESTRICT"
,
),
array
(
"CONSTRAINT_NAME"
=>
"FK_C1B1712387FE737264DE5A5511B8B3E"
,
"COLUMN_NAME"
=>
"column_3"
,
"REFERENCED_TABLE_NAME"
=>
"dummy"
,
"REFERENCED_COLUMN_NAME"
=>
"column_3"
,
"update_rule"
=>
"RESTRICT"
,
"delete_rule"
=>
"RESTRICT"
,
)
);
}
}
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