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
6e0bf10e
Commit
6e0bf10e
authored
Feb 20, 2011
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DBAL-42] Add support for Oracle and PostgreSQL Doctrine Type detection through comments.
parent
28c7e09d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
23 deletions
+44
-23
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+18
-5
OraclePlatform.php
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
+2
-2
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+8
-6
OracleSchemaManager.php
lib/Doctrine/DBAL/Schema/OracleSchemaManager.php
+3
-0
PostgreSqlSchemaManager.php
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
+12
-10
PostgreSqlPlatformTest.php
.../Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
+1
-0
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
6e0bf10e
...
...
@@ -26,6 +26,7 @@ use Doctrine\DBAL\DBALException,
Doctrine\DBAL\Schema\Index
,
Doctrine\DBAL\Schema\ForeignKeyConstraint
,
Doctrine\DBAL\Schema\TableDiff
,
Doctrine\DBAL\Schema\Column
,
Doctrine\DBAL\Types\Type
;
/**
...
...
@@ -268,6 +269,21 @@ abstract class AbstractPlatform
return
'(DC2Type:'
.
$doctrineType
->
getName
()
.
')'
;
}
/**
* Return the comment of a passed column modified by potential doctrine type comment hints.
*
* @param Column $column
* @return string
*/
protected
function
getColumnComment
(
Column
$column
)
{
$comment
=
$column
->
getComment
();
if
(
$this
->
isCommentedDoctrineType
(
$column
->
getType
()))
{
$comment
.=
$this
->
getDoctrineTypeComment
(
$column
->
getType
());
}
return
$comment
;
}
/**
* Gets the character used for identifier quoting.
*
...
...
@@ -856,10 +872,7 @@ abstract class AbstractPlatform
$columnData
[
'default'
]
=
$column
->
getDefault
();
$columnData
[
'columnDefinition'
]
=
$column
->
getColumnDefinition
();
$columnData
[
'autoincrement'
]
=
$column
->
getAutoincrement
();
$columnData
[
'comment'
]
=
$column
->
getComment
();
if
(
$this
->
isCommentedDoctrineType
(
$column
->
getType
()))
{
$columnData
[
'comment'
]
.=
$this
->
getDoctrineTypeComment
(
$column
->
getType
());
}
$columnData
[
'comment'
]
=
$this
->
getColumnComment
(
$column
);
if
(
in_array
(
$column
->
getName
(),
$options
[
'primary'
]))
{
$columnData
[
'primary'
]
=
true
;
...
...
@@ -879,7 +892,7 @@ abstract class AbstractPlatform
if
(
$this
->
supportsCommentOnStatement
())
{
foreach
(
$table
->
getColumns
()
AS
$column
)
{
if
(
$column
->
getComment
())
{
$sql
[]
=
$this
->
getCommentOnColumnSQL
(
$tableName
,
$column
->
getName
(),
$
column
->
getComment
(
));
$sql
[]
=
$this
->
getCommentOnColumnSQL
(
$tableName
,
$column
->
getName
(),
$
this
->
getColumnComment
(
$column
));
}
}
}
...
...
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
View file @
6e0bf10e
...
...
@@ -507,7 +507,7 @@ LEFT JOIN all_cons_columns r_cols
foreach
(
$diff
->
addedColumns
AS
$column
)
{
$fields
[]
=
$this
->
getColumnDeclarationSQL
(
$column
->
getQuotedName
(
$this
),
$column
->
toArray
());
if
(
$column
->
getComment
())
{
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
getName
(),
$
column
->
getComment
(
));
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
getName
(),
$
this
->
getColumnComment
(
$column
));
}
}
if
(
count
(
$fields
))
{
...
...
@@ -519,7 +519,7 @@ LEFT JOIN all_cons_columns r_cols
$column
=
$columnDiff
->
column
;
$fields
[]
=
$column
->
getQuotedName
(
$this
)
.
' '
.
$this
->
getColumnDeclarationSQL
(
''
,
$column
->
toArray
());
if
(
$columnDiff
->
hasChanged
(
'comment'
)
&&
$column
->
getComment
())
{
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
getName
(),
$
column
->
getComment
(
));
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
getName
(),
$
this
->
getColumnComment
(
$column
));
}
}
if
(
count
(
$fields
))
{
...
...
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
6e0bf10e
...
...
@@ -269,7 +269,7 @@ class PostgreSqlPlatform extends AbstractPlatform
AND pg_attrdef.adnum=a.attnum
) AS default,
(SELECT pg_description.description
FROM pg_description WHERE pg_description.objoid = c.oid
FROM pg_description WHERE pg_description.objoid = c.oid
AND a.attnum = pg_description.objsubid
) AS comment
FROM pg_attribute a, pg_class c, pg_type t, pg_namespace n
WHERE "
.
$this
->
getTableWhereClause
(
$table
,
'c'
,
'n'
)
.
"
...
...
@@ -348,10 +348,14 @@ class PostgreSqlPlatform extends AbstractPlatform
public
function
getAlterTableSQL
(
TableDiff
$diff
)
{
$sql
=
array
();
$commentsSQL
=
array
();
foreach
(
$diff
->
addedColumns
as
$column
)
{
$query
=
'ADD '
.
$this
->
getColumnDeclarationSQL
(
$column
->
getQuotedName
(
$this
),
$column
->
toArray
());
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' '
.
$query
;
if
(
$column
->
getComment
())
{
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
getName
(),
$this
->
getColumnComment
(
$column
));
}
}
foreach
(
$diff
->
removedColumns
as
$column
)
{
...
...
@@ -393,8 +397,8 @@ class PostgreSqlPlatform extends AbstractPlatform
$sql
[]
=
"ALTER TABLE "
.
$diff
->
name
.
" "
.
$query
;
}
}
if
(
$columnDiff
->
hasChanged
(
'comment'
))
{
$
sql
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
getName
(),
$column
->
getComment
(
));
if
(
$columnDiff
->
hasChanged
(
'comment'
)
&&
$column
->
getComment
()
)
{
$
commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
getName
(),
$this
->
getColumnComment
(
$column
));
}
}
...
...
@@ -406,9 +410,7 @@ class PostgreSqlPlatform extends AbstractPlatform
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' RENAME TO '
.
$diff
->
newName
;
}
$sql
=
array_merge
(
$sql
,
$this
->
_getAlterTableIndexForeignKeySQL
(
$diff
));
return
$sql
;
return
array_merge
(
$sql
,
$this
->
_getAlterTableIndexForeignKeySQL
(
$diff
),
$commentsSQL
);
}
/**
...
...
lib/Doctrine/DBAL/Schema/OracleSchemaManager.php
View file @
6e0bf10e
...
...
@@ -117,6 +117,9 @@ class OracleSchemaManager extends AbstractSchemaManager
$scale
=
null
;
$type
=
$this
->
_platform
->
getDoctrineTypeMapping
(
$dbType
);
$type
=
$this
->
extractDoctrineTypeFromComment
(
$tableColumn
[
'comments'
],
$type
);
$tableColumn
[
'comments'
]
=
$this
->
removeDoctrineTypeFromComment
(
$tableColumn
[
'comments'
],
$type
);
switch
(
$dbType
)
{
case
'number'
:
if
(
$tableColumn
[
'data_precision'
]
==
20
&&
$tableColumn
[
'data_scale'
]
==
0
)
{
...
...
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
View file @
6e0bf10e
...
...
@@ -201,7 +201,6 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
if
((
int
)
$length
<=
0
)
{
$length
=
null
;
}
$type
=
array
();
$fixed
=
null
;
if
(
!
isset
(
$tableColumn
[
'name'
]))
{
...
...
@@ -219,6 +218,9 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
}
$type
=
$this
->
_platform
->
getDoctrineTypeMapping
(
$dbType
);
$type
=
$this
->
extractDoctrineTypeFromComment
(
$tableColumn
[
'comment'
],
$type
);
$tableColumn
[
'comment'
]
=
$this
->
removeDoctrineTypeFromComment
(
$tableColumn
[
'comment'
],
$type
);
switch
(
$dbType
)
{
case
'smallint'
:
case
'int2'
:
...
...
@@ -270,16 +272,16 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
}
$options
=
array
(
'length'
=>
$length
,
'notnull'
=>
(
bool
)
$tableColumn
[
'isnotnull'
],
'default'
=>
$tableColumn
[
'default'
],
'primary'
=>
(
bool
)
(
$tableColumn
[
'pri'
]
==
't'
),
'precision'
=>
$precision
,
'scale'
=>
$scale
,
'fixed'
=>
$fixed
,
'unsigned'
=>
false
,
'length'
=>
$length
,
'notnull'
=>
(
bool
)
$tableColumn
[
'isnotnull'
],
'default'
=>
$tableColumn
[
'default'
],
'primary'
=>
(
bool
)
(
$tableColumn
[
'pri'
]
==
't'
),
'precision'
=>
$precision
,
'scale'
=>
$scale
,
'fixed'
=>
$fixed
,
'unsigned'
=>
false
,
'autoincrement'
=>
$autoincrement
,
'comment'
=>
$tableColumn
[
'comment'
],
'comment'
=>
$tableColumn
[
'comment'
],
);
return
new
Column
(
$tableColumn
[
'field'
],
\Doctrine\DBAL\Types\Type
::
getType
(
$type
),
$options
);
...
...
tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
View file @
6e0bf10e
...
...
@@ -212,6 +212,7 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
{
return
array
(
"ALTER TABLE mytable ADD quota INT NOT NULL"
,
"COMMENT ON COLUMN mytable.quota IS 'A comment'"
,
"COMMENT ON COLUMN mytable.baz IS 'B comment'"
,
);
}
...
...
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