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
1ae87bf3
Commit
1ae87bf3
authored
Nov 16, 2011
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DBAL-177 - Make sure schema.table syntax is supported in Assets for quoted assets
parent
bb844961
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
34 deletions
+106
-34
AbstractAsset.php
lib/Doctrine/DBAL/Schema/AbstractAsset.php
+7
-24
PostgreSqlSchemaManager.php
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
+69
-1
PostgreSqlSchemaManagerTest.php
...ts/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php
+11
-0
TableTest.php
tests/Doctrine/Tests/DBAL/Schema/TableTest.php
+19
-9
No files found.
lib/Doctrine/DBAL/Schema/AbstractAsset.php
View file @
1ae87bf3
<?php
<?php
/*
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...
@@ -32,7 +30,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
...
@@ -32,7 +30,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @link www.doctrine-project.org
* @since 2.0
* @since 2.0
* @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
*/
abstract
class
AbstractAsset
abstract
class
AbstractAsset
...
@@ -77,7 +74,7 @@ abstract class AbstractAsset
...
@@ -77,7 +74,7 @@ abstract class AbstractAsset
*/
*/
protected
function
trimQuotes
(
$identifier
)
protected
function
trimQuotes
(
$identifier
)
{
{
return
trim
(
$identifier
,
'`"'
);
return
str_replace
(
array
(
'`'
,
'"'
),
''
,
$identifier
);
}
}
/**
/**
...
@@ -100,7 +97,12 @@ abstract class AbstractAsset
...
@@ -100,7 +97,12 @@ abstract class AbstractAsset
public
function
getQuotedName
(
AbstractPlatform
$platform
)
public
function
getQuotedName
(
AbstractPlatform
$platform
)
{
{
$keywords
=
$platform
->
getReservedKeywordsList
();
$keywords
=
$platform
->
getReservedKeywordsList
();
return
(
$this
->
_quoted
||
$keywords
->
isKeyword
(
$this
->
_name
))
?
$platform
->
quoteIdentifier
(
$this
->
_name
)
:
$this
->
_name
;
$parts
=
explode
(
"."
,
$this
->
_name
);
foreach
(
$parts
AS
$k
=>
$v
)
{
$parts
[
$k
]
=
(
$this
->
_quoted
||
$keywords
->
isKeyword
(
$v
))
?
$platform
->
quoteIdentifier
(
$v
)
:
$v
;
}
return
implode
(
"."
,
$parts
);
}
}
/**
/**
...
@@ -117,25 +119,6 @@ abstract class AbstractAsset
...
@@ -117,25 +119,6 @@ abstract class AbstractAsset
*/
*/
protected
function
_generateIdentifierName
(
$columnNames
,
$prefix
=
''
,
$maxSize
=
30
)
protected
function
_generateIdentifierName
(
$columnNames
,
$prefix
=
''
,
$maxSize
=
30
)
{
{
/*$columnCount = count($columnNames);
$postfixLen = strlen($postfix);
$parts = array_map(function($columnName) use($columnCount, $postfixLen, $maxSize) {
return substr($columnName, -floor(($maxSize-$postfixLen)/$columnCount - 1));
}, $columnNames);
$parts[] = $postfix;
$identifier = trim(implode("_", $parts), '_');
// using implicit schema support of DB2 and Postgres there might be dots in the auto-generated
// identifier names which can easily be replaced by underscores.
$identifier = str_replace(".", "_", $identifier);
if (is_numeric(substr($identifier, 0, 1))) {
$identifier = "i" . substr($identifier, 0, strlen($identifier)-1);
}
return $identifier;*/
$hash
=
implode
(
""
,
array_map
(
function
(
$column
)
{
$hash
=
implode
(
""
,
array_map
(
function
(
$column
)
{
return
dechex
(
crc32
(
$column
));
return
dechex
(
crc32
(
$column
));
},
$columnNames
));
},
$columnNames
));
...
...
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
View file @
1ae87bf3
...
@@ -32,6 +32,70 @@ namespace Doctrine\DBAL\Schema;
...
@@ -32,6 +32,70 @@ namespace Doctrine\DBAL\Schema;
*/
*/
class
PostgreSqlSchemaManager
extends
AbstractSchemaManager
class
PostgreSqlSchemaManager
extends
AbstractSchemaManager
{
{
/**
* @var array
*/
private
$existingSchemaPaths
;
/**
* Get all the existing schema names.
*
* @return array
*/
public
function
getSchemaNames
()
{
$rows
=
$this
->
_conn
->
fetchAll
(
'SELECT schema_name FROM information_schema.schemata'
);
return
array_map
(
function
(
$v
)
{
return
$v
[
'schema_name'
];
},
$rows
);
}
/**
* Return an array of schema search paths
*
* This is a PostgreSQL only function.
*
* @return array
*/
public
function
getSchemaSearchPaths
()
{
$params
=
$this
->
_conn
->
getParams
();
$schema
=
explode
(
","
,
$this
->
_conn
->
fetchColumn
(
'SHOW search_path'
));
if
(
isset
(
$params
[
'user'
]))
{
$schema
=
str_replace
(
'"$user"'
,
$params
[
'user'
],
$schema
);
}
return
$schema
;
}
/**
* Get names of all existing schemas in the current users search path.
*
* This is a PostgreSQL only function.
*
* @return array
*/
public
function
getExistingSchemaSearchPaths
()
{
if
(
$this
->
existingSchemaPaths
===
null
)
{
$this
->
determineExistingSchemaSearchPaths
();
}
return
$this
->
existingSchemaPaths
;
}
/**
* Use this to set or reset the order of the existing schemas in the current search path of the user
*
* This is a PostgreSQL only function.
*
* @return type
*/
public
function
determineExistingSchemaSearchPaths
()
{
$names
=
$this
->
getSchemaNames
();
$paths
=
$this
->
getSchemaSearchPaths
();
$this
->
existingSchemaPaths
=
array_filter
(
$paths
,
function
(
$v
)
use
(
$names
)
{
return
in_array
(
$v
,
$names
);
});
}
protected
function
_getPortableTableForeignKeyDefinition
(
$tableForeignKey
)
protected
function
_getPortableTableForeignKeyDefinition
(
$tableForeignKey
)
{
{
...
@@ -111,7 +175,11 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
...
@@ -111,7 +175,11 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
protected
function
_getPortableTableDefinition
(
$table
)
protected
function
_getPortableTableDefinition
(
$table
)
{
{
if
(
$table
[
'schema_name'
]
==
'public'
)
{
$schemas
=
$this
->
getExistingSchemaSearchPaths
();
$firstSchema
=
array_shift
(
$schemas
);
var_dump
(
$firstSchema
);
if
(
$table
[
'schema_name'
]
==
$firstSchema
)
{
return
$table
[
'table_name'
];
return
$table
[
'table_name'
];
}
else
{
}
else
{
return
$table
[
'schema_name'
]
.
"."
.
$table
[
'table_name'
];
return
$table
[
'schema_name'
]
.
"."
.
$table
[
'table_name'
];
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php
View file @
1ae87bf3
...
@@ -10,6 +10,17 @@ require_once __DIR__ . '/../../../TestInit.php';
...
@@ -10,6 +10,17 @@ require_once __DIR__ . '/../../../TestInit.php';
class
PostgreSqlSchemaManagerTest
extends
SchemaManagerFunctionalTestCase
class
PostgreSqlSchemaManagerTest
extends
SchemaManagerFunctionalTestCase
{
{
/**
* @group DBAL-177
*/
public
function
testGetSearchPath
()
{
$params
=
$this
->
_conn
->
getParams
();
$paths
=
$this
->
_sm
->
getSchemaSearchPaths
();
$this
->
assertEquals
(
array
(
$params
[
'user'
],
'public'
),
$paths
);
}
/**
/**
* @group DBAL-21
* @group DBAL-21
*/
*/
...
...
tests/Doctrine/Tests/DBAL/Schema/TableTest.php
View file @
1ae87bf3
...
@@ -12,7 +12,7 @@ use Doctrine\DBAL\Schema\Index;
...
@@ -12,7 +12,7 @@ use Doctrine\DBAL\Schema\Index;
use
Doctrine\DBAL\Schema\ForeignKeyConstraint
;
use
Doctrine\DBAL\Schema\ForeignKeyConstraint
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Types\Type
;
class
TableTest
extends
\
PHPUnit_Framework_
TestCase
class
TableTest
extends
\
Doctrine\Tests\Dbal
TestCase
{
{
public
function
testCreateWithInvalidTableName
()
public
function
testCreateWithInvalidTableName
()
{
{
...
@@ -473,4 +473,14 @@ class TableTest extends \PHPUnit_Framework_TestCase
...
@@ -473,4 +473,14 @@ class TableTest extends \PHPUnit_Framework_TestCase
$table
->
addColumn
(
'bar'
,
'integer'
);
$table
->
addColumn
(
'bar'
,
'integer'
);
$table
->
addForeignKeyConstraint
(
'"boing"'
,
array
(
'"foo"'
,
'"bar"'
),
array
(
"id"
));
$table
->
addForeignKeyConstraint
(
'"boing"'
,
array
(
'"foo"'
,
'"bar"'
),
array
(
"id"
));
}
}
/**
* @group DBAL-177
*/
public
function
testQuoteSchemaPrefixed
()
{
$table
=
new
Table
(
"`test`.`test`"
);
$this
->
assertEquals
(
"test.test"
,
$table
->
getName
());
$this
->
assertEquals
(
"`test`.`test`"
,
$table
->
getQuotedName
(
new
\Doctrine\DBAL\Platforms\MySqlPlatform
));
}
}
}
\ No newline at end of file
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