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
e7b76919
Commit
e7b76919
authored
Dec 29, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #467 from deeky666/DBAL-472
[DBAL-472] Fix altering column from notnull to null in Oracle
parents
597fdfad
0782e925
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
6 deletions
+68
-6
OraclePlatform.php
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
+26
-1
OracleSchemaManagerTest.php
.../Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php
+31
-0
OraclePlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
+11
-5
No files found.
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
View file @
e7b76919
...
...
@@ -687,7 +687,7 @@ LEFT JOIN user_cons_columns r_cols
$columnInfo
[
'notnull'
]
=
false
;
}
$fields
[]
=
$column
->
getQuotedName
(
$this
)
.
' '
.
$this
->
getColumnDeclarationSQL
(
''
,
$columnInfo
);
$fields
[]
=
$column
->
getQuotedName
(
$this
)
.
$this
->
getColumnDeclarationSQL
(
''
,
$columnInfo
);
}
if
(
$columnHasChangedComment
)
{
...
...
@@ -737,6 +737,31 @@ LEFT JOIN user_cons_columns r_cols
return
array_merge
(
$sql
,
$tableSql
,
$columnSql
);
}
/**
* {@inheritdoc}
*/
public
function
getColumnDeclarationSQL
(
$name
,
array
$field
)
{
if
(
isset
(
$field
[
'columnDefinition'
]))
{
$columnDef
=
$this
->
getCustomTypeDeclarationSQL
(
$field
);
}
else
{
$default
=
$this
->
getDefaultValueDeclarationSQL
(
$field
);
$notnull
=
empty
(
$field
[
'notnull'
])
?
' NULL'
:
' NOT NULL'
;
$unique
=
(
isset
(
$field
[
'unique'
])
&&
$field
[
'unique'
])
?
' '
.
$this
->
getUniqueFieldDeclarationSQL
()
:
''
;
$check
=
(
isset
(
$field
[
'check'
])
&&
$field
[
'check'
])
?
' '
.
$field
[
'check'
]
:
''
;
$typeDecl
=
$field
[
'type'
]
->
getSqlDeclaration
(
$field
,
$this
);
$columnDef
=
$typeDecl
.
$default
.
$notnull
.
$unique
.
$check
;
}
return
$name
.
' '
.
$columnDef
;
}
/**
* {@inheritDoc}
*/
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php
View file @
e7b76919
...
...
@@ -57,4 +57,35 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this
->
assertInstanceOf
(
'Doctrine\DBAL\Types\BinaryType'
,
$table
->
getColumn
(
'column_binary'
)
->
getType
());
$this
->
assertFalse
(
$table
->
getColumn
(
'column_binary'
)
->
getFixed
());
}
/**
* @group DBAL-472
*/
public
function
testAlterTableColumnNotNull
()
{
$comparator
=
new
Schema\Comparator
();
$tableName
=
'list_table_column_notnull'
;
$table
=
new
Schema\Table
(
$tableName
);
$table
->
addColumn
(
'id'
,
'integer'
);
$table
->
addColumn
(
'foo'
,
'integer'
);
$table
->
setPrimaryKey
(
array
(
'id'
));
$this
->
_sm
->
dropAndCreateTable
(
$table
);
$columns
=
$this
->
_sm
->
listTableColumns
(
$tableName
);
$this
->
assertTrue
(
$columns
[
'id'
]
->
getNotnull
());
$this
->
assertTrue
(
$columns
[
'foo'
]
->
getNotnull
());
$diffTable
=
clone
$table
;
$diffTable
->
changeColumn
(
'foo'
,
array
(
'notnull'
=>
false
));
$this
->
_sm
->
alterTable
(
$comparator
->
diffTable
(
$table
,
$diffTable
));
$columns
=
$this
->
_sm
->
listTableColumns
(
$tableName
);
$this
->
assertTrue
(
$columns
[
'id'
]
->
getNotnull
());
$this
->
assertFalse
(
$columns
[
'foo'
]
->
getNotnull
());
}
}
tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
View file @
e7b76919
...
...
@@ -63,13 +63,13 @@ class OraclePlatformTest extends AbstractPlatformTestCase
public
function
getGenerateTableSql
()
{
return
'CREATE TABLE test (id NUMBER(10) NOT NULL, test VARCHAR2(255) DEFAULT NULL, PRIMARY KEY(id))'
;
return
'CREATE TABLE test (id NUMBER(10) NOT NULL, test VARCHAR2(255) DEFAULT NULL
NULL
, PRIMARY KEY(id))'
;
}
public
function
getGenerateTableWithMultiColumnUniqueIndexSql
()
{
return
array
(
'CREATE TABLE test (foo VARCHAR2(255) DEFAULT NULL
, bar VARCHAR2(255) DEFAULT
NULL)'
,
'CREATE TABLE test (foo VARCHAR2(255) DEFAULT NULL
NULL, bar VARCHAR2(255) DEFAULT NULL
NULL)'
,
'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)'
,
);
}
...
...
@@ -77,7 +77,7 @@ class OraclePlatformTest extends AbstractPlatformTestCase
public
function
getGenerateAlterTableSql
()
{
return
array
(
'ALTER TABLE mytable ADD (quota NUMBER(10) DEFAULT NULL)'
,
'ALTER TABLE mytable ADD (quota NUMBER(10) DEFAULT NULL
NULL
)'
,
"ALTER TABLE mytable MODIFY (baz VARCHAR2(255) DEFAULT 'def' NOT NULL, bloo NUMBER(1) DEFAULT '0' NOT NULL)"
,
"ALTER TABLE mytable DROP (foo)"
,
"ALTER TABLE mytable RENAME TO userlist"
,
...
...
@@ -326,9 +326,15 @@ class OraclePlatformTest extends AbstractPlatformTestCase
),
array
(
'type'
,
'notnull'
)
);
$tableDiff
->
changedColumns
[
'metar'
]
=
new
\Doctrine\DBAL\Schema\ColumnDiff
(
'metar'
,
new
\Doctrine\DBAL\Schema\Column
(
'metar'
,
\Doctrine\DBAL\Types\Type
::
getType
(
'string'
),
array
(
'length'
=>
2000
,
'notnull'
=>
false
)
),
array
(
'notnull'
)
);
$expectedSql
=
array
(
"ALTER TABLE mytable MODIFY (foo
VARCHAR2(255) DEFAULT 'bla', baz VARCHAR2(255) DEFAULT 'bla' NOT
NULL)"
,
"ALTER TABLE mytable MODIFY (foo
VARCHAR2(255) DEFAULT 'bla' NULL, baz VARCHAR2(255) DEFAULT 'bla' NOT NULL, metar VARCHAR2(2000) DEFAULT NULL
NULL)"
,
);
$this
->
assertEquals
(
$expectedSql
,
$this
->
_platform
->
getAlterTableSQL
(
$tableDiff
));
}
...
...
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