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
61c5e4e3
Unverified
Commit
61c5e4e3
authored
Mar 29, 2018
by
Sergei Morozov
Committed by
GitHub
Mar 29, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3020 from stlrnz/mssql-schema
Improve handling of schemas in SQL Server >= 2008
parents
179ff5d9
3f0fd621
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
181 additions
and
37 deletions
+181
-37
SQLServer2008Platform.php
lib/Doctrine/DBAL/Platforms/SQLServer2008Platform.php
+10
-0
SQLServerPlatform.php
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
+35
-6
SQLServerSchemaManager.php
lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php
+4
-0
SchemaManagerFunctionalTestCase.php
...BAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
+44
-0
AbstractSQLServerPlatformTestCase.php
...ests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php
+88
-31
No files found.
lib/Doctrine/DBAL/Platforms/SQLServer2008Platform.php
View file @
61c5e4e3
...
...
@@ -27,6 +27,16 @@ namespace Doctrine\DBAL\Platforms;
*/
class
SQLServer2008Platform
extends
SQLServer2005Platform
{
/**
* {@inheritDoc}
*/
public
function
getListTablesSQL
()
{
// "sysdiagrams" table must be ignored as it's internal SQL Server table for Database Diagrams
// Category 2 must be ignored as it is "MS SQL Server 'pseudo-system' object[s]" for replication
return
"SELECT name, SCHEMA_NAME (uid) AS schema_name FROM sysobjects WHERE type = 'U' AND name != 'sysdiagrams' AND category != 2 ORDER BY name"
;
}
/**
* {@inheritDoc}
*/
...
...
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
View file @
61c5e4e3
...
...
@@ -28,8 +28,10 @@ use Doctrine\DBAL\Schema\Index;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\Types
;
use
function
explode
;
use
function
implode
;
use
function
sprintf
;
use
function
strpos
;
/**
* The SQLServerPlatform provides the behavior, features and SQL dialect of the
...
...
@@ -330,13 +332,22 @@ class SQLServerPlatform extends AbstractPlatform
*/
protected
function
getCreateColumnCommentSQL
(
$tableName
,
$columnName
,
$comment
)
{
if
(
strpos
(
$tableName
,
'.'
)
!==
false
)
{
[
$schemaSQL
,
$tableSQL
]
=
explode
(
'.'
,
$tableName
);
$schemaSQL
=
$this
->
quoteStringLiteral
(
$schemaSQL
);
$tableSQL
=
$this
->
quoteStringLiteral
(
$tableSQL
);
}
else
{
$schemaSQL
=
"'dbo'"
;
$tableSQL
=
$this
->
quoteStringLiteral
(
$tableName
);
}
return
$this
->
getAddExtendedPropertySQL
(
'MS_Description'
,
$comment
,
'SCHEMA'
,
'dbo'
,
$schemaSQL
,
'TABLE'
,
$table
Name
,
$table
SQL
,
'COLUMN'
,
$columnName
);
...
...
@@ -678,13 +689,22 @@ class SQLServerPlatform extends AbstractPlatform
*/
protected
function
getAlterColumnCommentSQL
(
$tableName
,
$columnName
,
$comment
)
{
if
(
strpos
(
$tableName
,
'.'
)
!==
false
)
{
[
$schemaSQL
,
$tableSQL
]
=
explode
(
'.'
,
$tableName
);
$schemaSQL
=
$this
->
quoteStringLiteral
(
$schemaSQL
);
$tableSQL
=
$this
->
quoteStringLiteral
(
$tableSQL
);
}
else
{
$schemaSQL
=
"'dbo'"
;
$tableSQL
=
$this
->
quoteStringLiteral
(
$tableName
);
}
return
$this
->
getUpdateExtendedPropertySQL
(
'MS_Description'
,
$comment
,
'SCHEMA'
,
'dbo'
,
$schemaSQL
,
'TABLE'
,
$table
Name
,
$table
SQL
,
'COLUMN'
,
$columnName
);
...
...
@@ -708,12 +728,21 @@ class SQLServerPlatform extends AbstractPlatform
*/
protected
function
getDropColumnCommentSQL
(
$tableName
,
$columnName
)
{
if
(
strpos
(
$tableName
,
'.'
)
!==
false
)
{
[
$schemaSQL
,
$tableSQL
]
=
explode
(
'.'
,
$tableName
);
$schemaSQL
=
$this
->
quoteStringLiteral
(
$schemaSQL
);
$tableSQL
=
$this
->
quoteStringLiteral
(
$tableSQL
);
}
else
{
$schemaSQL
=
"'dbo'"
;
$tableSQL
=
$this
->
quoteStringLiteral
(
$tableName
);
}
return
$this
->
getDropExtendedPropertySQL
(
'MS_Description'
,
'SCHEMA'
,
'dbo'
,
$schemaSQL
,
'TABLE'
,
$table
Name
,
$table
SQL
,
'COLUMN'
,
$columnName
);
...
...
lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php
View file @
61c5e4e3
...
...
@@ -198,6 +198,10 @@ class SQLServerSchemaManager extends AbstractSchemaManager
*/
protected
function
_getPortableTableDefinition
(
$table
)
{
if
(
isset
(
$table
[
'schema_name'
])
&&
$table
[
'schema_name'
]
!==
'dbo'
)
{
return
$table
[
'schema_name'
]
.
'.'
.
$table
[
'name'
];
}
return
$table
[
'name'
];
}
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
View file @
61c5e4e3
...
...
@@ -3,11 +3,13 @@
namespace
Doctrine\Tests\DBAL\Functional\Schema
;
use
Doctrine\Common\EventManager
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Events
;
use
Doctrine\DBAL\Platforms\OraclePlatform
;
use
Doctrine\DBAL\Schema\Column
;
use
Doctrine\DBAL\Schema\ColumnDiff
;
use
Doctrine\DBAL\Schema\Comparator
;
use
Doctrine\DBAL\Schema\SchemaDiff
;
use
Doctrine\DBAL\Schema\Sequence
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\TableDiff
;
...
...
@@ -42,6 +44,23 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this
->
_sm
=
$this
->
_conn
->
getSchemaManager
();
}
protected
function
tearDown
()
{
parent
::
tearDown
();
$this
->
_sm
->
tryMethod
(
'dropTable'
,
'testschema.my_table_in_namespace'
);
//TODO: SchemaDiff does not drop removed namespaces?
try
{
//sql server versions below 2016 do not support 'IF EXISTS' so we have to catch the exception here
$this
->
_conn
->
exec
(
'DROP SCHEMA testschema'
);
}
catch
(
DBALException
$e
)
{
return
;
}
}
/**
* @group DBAL-1220
*/
...
...
@@ -570,6 +589,31 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
}
}
public
function
testTableInNamespace
()
{
if
(
!
$this
->
_sm
->
getDatabasePlatform
()
->
supportsSchemas
())
{
$this
->
markTestSkipped
(
'Schema definition is not supported by this platform.'
);
}
//create schema
$diff
=
new
SchemaDiff
();
$diff
->
newNamespaces
[]
=
'testschema'
;
foreach
(
$diff
->
toSql
(
$this
->
_sm
->
getDatabasePlatform
())
as
$sql
)
{
$this
->
_conn
->
exec
(
$sql
);
}
//test if table is create in namespace
$this
->
createTestTable
(
'testschema.my_table_in_namespace'
);
self
::
assertContains
(
'testschema.my_table_in_namespace'
,
$this
->
_sm
->
listTableNames
());
//tables without namespace should be created in default namespace
//default namespaces are ignored in table listings
$this
->
createTestTable
(
'my_table_not_in_namespace'
);
self
::
assertContains
(
'my_table_not_in_namespace'
,
$this
->
_sm
->
listTableNames
());
}
public
function
testCreateAndListViews
()
{
if
(
!
$this
->
_sm
->
getDatabasePlatform
()
->
supportsViews
())
{
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php
View file @
61c5e4e3
This diff is collapsed.
Click to expand it.
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