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
17c1476e
Commit
17c1476e
authored
Dec 12, 2010
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DBAL-75 - Fix handling of schema in PostgreSQL Platform and SchemaManager.
parent
16e2d112
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
29 deletions
+73
-29
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+26
-26
PostgreSqlSchemaManager.php
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
+13
-3
PostgreSqlSchemaManagerTest.php
...ts/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php
+34
-0
No files found.
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
17c1476e
...
...
@@ -154,30 +154,17 @@ class PostgreSqlPlatform extends AbstractPlatform
public
function
getListSequencesSQL
(
$database
)
{
return
"SELECT
rel
name
c.relname, n.nspname AS schema
name
FROM
pg_class
WHERE relkind = 'S' AND relnamespace IN
(SELECT oid FROM pg_namespace
WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')"
;
pg_class c, pg_namespace n
WHERE relkind = 'S' AND n.oid = c.relnamespace AND
(n.nspname NOT LIKE 'pg_%' AND n.nspname != 'information_schema')"
;
}
public
function
getListTablesSQL
()
{
return
"SELECT
c.relname AS table_name
FROM pg_class c, pg_user u
WHERE c.relowner = u.usesysid
AND c.relkind = 'r'
AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname)
AND c.relname !~ '^(pg_|sql_)'
UNION
SELECT c.relname AS table_name
FROM pg_class c
WHERE c.relkind = 'r'
AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname)
AND NOT EXISTS (SELECT 1 FROM pg_user WHERE usesysid = c.relowner)
AND c.relname !~ '^pg_'"
;
return
"SELECT tablename AS table_name, schemaname AS schema_name
FROM pg_tables WHERE schemaname NOT LIKE 'pg_%' AND schemaname != 'information_schema'"
;
}
public
function
getListViewsSQL
(
$database
)
...
...
@@ -192,9 +179,9 @@ class PostgreSqlPlatform extends AbstractPlatform
WHERE r.conrelid =
(
SELECT c.oid
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname = '"
.
$table
.
"' AND pg_catalog.pg_table_is_visible(c.oid)
FROM pg_catalog.pg_class c
, pg_catalog.pg_namespace n
WHERE "
.
$this
->
getTableWhereClause
(
$table
)
.
"
AND n.oid = c.relnamespace
)
AND r.contype = 'f'"
;
}
...
...
@@ -237,11 +224,23 @@ class PostgreSqlPlatform extends AbstractPlatform
FROM pg_class, pg_index
WHERE oid IN (
SELECT indexrelid
FROM pg_index
, pg_class
WHERE
pg_class.relname='
$table
' AND pg_class.oid=pg_index.indrel
id
FROM pg_index
si, pg_class sc, pg_namespace sn
WHERE
"
.
$this
->
getTableWhereClause
(
$table
,
'sc'
,
'sn'
)
.
" AND sc.oid=si.indrelid AND sc.relnamespace = sn.o
id
) AND pg_index.indexrelid = oid"
;
}
private
function
getTableWhereClause
(
$table
,
$classAlias
=
'c'
,
$namespaceAlias
=
'n'
)
{
$whereClause
=
""
;
if
(
strpos
(
$table
,
"."
)
!==
false
)
{
list
(
$schema
,
$table
)
=
explode
(
"."
,
$table
);
$whereClause
=
"
$classAlias
.relname = '"
.
$table
.
"' AND
$namespaceAlias
.nspname = '"
.
$schema
.
"'"
;
}
else
{
$whereClause
=
"
$classAlias
.relname = '"
.
$table
.
"'"
;
}
return
$whereClause
;
}
public
function
getListTableColumnsSQL
(
$table
)
{
return
"SELECT
...
...
@@ -264,11 +263,12 @@ class PostgreSqlPlatform extends AbstractPlatform
WHERE c.oid = pg_attrdef.adrelid
AND pg_attrdef.adnum=a.attnum
) AS default
FROM pg_attribute a, pg_class c, pg_type t
WHERE
c.relname = '
$table
'
FROM pg_attribute a, pg_class c, pg_type t
, pg_namespace n
WHERE
"
.
$this
->
getTableWhereClause
(
$table
,
'c'
,
'n'
)
.
"
AND a.attnum > 0
AND a.attrelid = c.oid
AND a.atttypid = t.oid
AND n.oid = c.relnamespace
ORDER BY a.attnum"
;
}
...
...
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
View file @
17c1476e
...
...
@@ -109,7 +109,11 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
protected
function
_getPortableTableDefinition
(
$table
)
{
return
$table
[
'table_name'
];
if
(
$table
[
'schema_name'
]
==
'public'
)
{
return
$table
[
'table_name'
];
}
else
{
return
$table
[
'schema_name'
]
.
"."
.
$table
[
'table_name'
];
}
}
/**
...
...
@@ -155,8 +159,14 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
protected
function
_getPortableSequenceDefinition
(
$sequence
)
{
$data
=
$this
->
_conn
->
fetchAll
(
'SELECT min_value, increment_by FROM '
.
$sequence
[
'relname'
]);
return
new
Sequence
(
$sequence
[
'relname'
],
$data
[
0
][
'increment_by'
],
$data
[
0
][
'min_value'
]);
if
(
$sequence
[
'schemaname'
]
!=
'public'
)
{
$sequenceName
=
$sequence
[
'schemaname'
]
.
"."
.
$sequence
[
'relname'
];
}
else
{
$sequenceName
=
$sequence
[
'relname'
];
}
$data
=
$this
->
_conn
->
fetchAll
(
'SELECT min_value, increment_by FROM '
.
$sequenceName
);
return
new
Sequence
(
$sequenceName
,
$data
[
0
][
'increment_by'
],
$data
[
0
][
'min_value'
]);
}
protected
function
_getPortableTableColumnDefinition
(
$tableColumn
)
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php
View file @
17c1476e
...
...
@@ -98,6 +98,40 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$tableFinal
=
$this
->
_sm
->
listTableDetails
(
'autoinc_table_drop'
);
$this
->
assertFalse
(
$tableFinal
->
getColumn
(
'id'
)
->
getAutoincrement
());
}
/**
* @group DBAL-75
*/
public
function
testTableWithSchema
()
{
$this
->
_conn
->
exec
(
'CREATE SCHEMA nested'
);
$nestedRelatedTable
=
new
\Doctrine\DBAL\Schema\Table
(
'nested.schemarelated'
);
$column
=
$nestedRelatedTable
->
addColumn
(
'id'
,
'integer'
);
$column
->
setAutoincrement
(
true
);
$nestedRelatedTable
->
setPrimaryKey
(
array
(
'id'
));
$nestedSchemaTable
=
new
\Doctrine\DBAL\Schema\Table
(
'nested.schematable'
);
$column
=
$nestedSchemaTable
->
addColumn
(
'id'
,
'integer'
);
$column
->
setAutoincrement
(
true
);
$nestedSchemaTable
->
setPrimaryKey
(
array
(
'id'
));
$nestedSchemaTable
->
addUnnamedForeignKeyConstraint
(
$nestedRelatedTable
,
array
(
'id'
),
array
(
'id'
));
$this
->
_sm
->
createTable
(
$nestedRelatedTable
);
$this
->
_sm
->
createTable
(
$nestedSchemaTable
);
$tables
=
$this
->
_sm
->
listTableNames
();
$this
->
assertContains
(
'nested.schematable'
,
$tables
,
"The table should be detected with its non-public schema."
);
$nestedSchemaTable
=
$this
->
_sm
->
listTableDetails
(
'nested.schematable'
);
$this
->
assertTrue
(
$nestedSchemaTable
->
hasColumn
(
'id'
));
$this
->
assertEquals
(
array
(
'id'
),
$nestedSchemaTable
->
getPrimaryKey
()
->
getColumns
());
$relatedFks
=
$nestedSchemaTable
->
getForeignKeys
();
$this
->
assertEquals
(
1
,
count
(
$relatedFks
));
$relatedFk
=
array_pop
(
$relatedFks
);
$this
->
assertEquals
(
"nested.schemarelated"
,
$relatedFk
->
getForeignTableName
());
}
}
class
MoneyType
extends
Type
...
...
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