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
491b1560
Commit
491b1560
authored
Dec 28, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored pgsql import driver
parent
dbad2625
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
45 deletions
+49
-45
Pgsql.php
lib/Doctrine/Import/Pgsql.php
+49
-45
No files found.
lib/Doctrine/Import/Pgsql.php
View file @
491b1560
...
...
@@ -31,6 +31,47 @@ Doctrine::autoload('Doctrine_Import');
* @since 1.0
*/
class
Doctrine_Import_Pgsql
extends
Doctrine_Import
{
protected
$sql
=
array
(
'listDatabases'
=>
'SELECT datname FROM pg_database'
,
'listFunctions'
=>
"SELECT
proname
FROM
pg_proc pr,
pg_type tp
WHERE
tp.oid = pr.prorettype
AND pr.proisagg = FALSE
AND tp.typname <> 'trigger'
AND pr.pronamespace IN
(SELECT oid FROM pg_namespace
WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema'"
,
'listSequences'
=>
"SELECT
relname
FROM
pg_class
WHERE relkind = 'S' AND relnamespace IN
(SELECT oid FROM pg_namespace
WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')"
,
'listTables'
=>
"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_'"
,
'listViews'
=>
'SELECT viewname FROM pg_views'
,
'listUsers'
=>
'SELECT usename FROM pg_user'
);
/**
* listDatabases
* lists all databases
...
...
@@ -38,9 +79,7 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
* @return array
*/
public
function
listDatabases
()
{
$query
=
'SELECT datname FROM pg_database'
;
return
$this
->
conn
->
fetchColumn
(
$query
);
return
$this
->
conn
->
fetchColumn
(
$this
->
sql
[
'listDatabases'
]);
}
/**
* lists all availible database functions
...
...
@@ -48,20 +87,7 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
* @return array
*/
public
function
listFunctions
()
{
$query
=
"
SELECT
proname
FROM
pg_proc pr,
pg_type tp
WHERE
tp.oid = pr.prorettype
AND pr.proisagg = FALSE
AND tp.typname <> 'trigger'
AND pr.pronamespace IN
(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')"
;
return
$this
->
conn
->
fetchColumn
(
$query
);
return
$this
->
conn
->
fetchColumn
(
$this
->
sql
[
'listFunctions'
]);
}
/**
* lists all database triggers
...
...
@@ -78,11 +104,8 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
* @param string|null $database
* @return array
*/
public
function
listSequences
(
$database
=
null
)
{
$query
=
"SELECT relname FROM pg_class WHERE relkind = 'S' AND relnamespace IN"
;
$query
.=
"(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')"
;
return
$this
->
conn
->
fetchColumn
(
$query
);
public
function
listSequences
(
$database
=
null
)
{
return
$this
->
conn
->
fetchColumn
(
$this
->
sql
[
'listSequences'
]);
}
/**
* lists table constraints
...
...
@@ -163,20 +186,7 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
* @return array
*/
public
function
listTables
(
$database
=
null
)
{
$sql
=
"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
$this
->
dbh
->
query
(
$sql
)
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
return
$this
->
dbh
->
query
(
$this
->
sql
[
'listTables'
])
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
}
/**
* lists table triggers
...
...
@@ -193,9 +203,7 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
* @param string $table database table name
* @return array
*/
public
function
listTableViews
(
$table
)
{
$query
=
'SELECT viewname FROM pg_views'
;
public
function
listTableViews
(
$table
)
{
return
$this
->
conn
->
fetchColumn
(
$query
);
}
/**
...
...
@@ -204,9 +212,7 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
* @return array
*/
public
function
listUsers
()
{
$query
=
'SELECT usename FROM pg_user'
;
return
$this
->
conn
->
fetchColumn
(
$query
);
return
$this
->
conn
->
fetchColumn
(
$this
->
sql
[
'listUsers'
]);
}
/**
* lists database views
...
...
@@ -215,8 +221,6 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
* @return array
*/
public
function
listViews
(
$database
=
null
)
{
$query
=
'SELECT viewname FROM pg_views'
;
return
$this
->
conn
->
fetchColumn
(
$query
);
return
$this
->
conn
->
fetchColumn
(
$this
->
sql
[
'listViews'
]);
}
}
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