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
b40c969f
Commit
b40c969f
authored
Dec 28, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored import and pgsql import driver
parent
491b1560
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
93 deletions
+108
-93
Import.php
lib/Doctrine/Import.php
+52
-18
Pgsql.php
lib/Doctrine/Import/Pgsql.php
+56
-75
No files found.
lib/Doctrine/Import.php
View file @
b40c969f
...
...
@@ -34,22 +34,34 @@ Doctrine::autoload('Doctrine_Connection_Module');
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
*/
class
Doctrine_Import
extends
Doctrine_Connection_Module
{
class
Doctrine_Import
extends
Doctrine_Connection_Module
{
protected
$sql
=
array
();
/**
* lists all databases
*
* @return array
*/
public
function
listDatabases
()
{
throw
new
Doctrine_Import_Exception
(
__FUNCTION__
.
' not supported by this driver.'
);
public
function
listDatabases
()
{
if
(
!
isset
(
$this
->
sql
[
'listDatabases'
]))
{
throw
new
Doctrine_Import_Exception
(
__FUNCTION__
.
' not supported by this driver.'
);
}
return
$this
->
conn
->
fetchColumn
(
$this
->
sql
[
'listDatabases'
]);
}
/**
* lists all availible database functions
*
* @return array
*/
public
function
listFunctions
()
{
throw
new
Doctrine_Import_Exception
(
__FUNCTION__
.
' not supported by this driver.'
);
public
function
listFunctions
()
{
if
(
!
isset
(
$this
->
sql
[
'listFunctions'
]))
{
throw
new
Doctrine_Import_Exception
(
__FUNCTION__
.
' not supported by this driver.'
);
}
return
$this
->
conn
->
fetchColumn
(
$this
->
sql
[
'listFunctions'
]);
}
/**
* lists all database triggers
...
...
@@ -57,7 +69,8 @@ class Doctrine_Import extends Doctrine_Connection_Module {
* @param string|null $database
* @return array
*/
public
function
listTriggers
(
$database
=
null
)
{
public
function
listTriggers
(
$database
=
null
)
{
throw
new
Doctrine_Import_Exception
(
__FUNCTION__
.
' not supported by this driver.'
);
}
/**
...
...
@@ -66,8 +79,13 @@ class Doctrine_Import extends Doctrine_Connection_Module {
* @param string|null $database
* @return array
*/
public
function
listSequences
(
$database
=
null
)
{
throw
new
Doctrine_Import_Exception
(
__FUNCTION__
.
' not supported by this driver.'
);
public
function
listSequences
(
$database
=
null
)
{
if
(
!
isset
(
$this
->
sql
[
'listSequences'
]))
{
throw
new
Doctrine_Import_Exception
(
__FUNCTION__
.
' not supported by this driver.'
);
}
return
$this
->
conn
->
fetchColumn
(
$this
->
sql
[
'listSequences'
]);
}
/**
* lists table constraints
...
...
@@ -75,7 +93,8 @@ class Doctrine_Import extends Doctrine_Connection_Module {
* @param string $table database table name
* @return array
*/
public
function
listTableConstraints
(
$table
)
{
public
function
listTableConstraints
(
$table
)
{
throw
new
Doctrine_Import_Exception
(
__FUNCTION__
.
' not supported by this driver.'
);
}
/**
...
...
@@ -84,7 +103,8 @@ class Doctrine_Import extends Doctrine_Connection_Module {
* @param string $table database table name
* @return array
*/
public
function
listTableColumns
(
$table
)
{
public
function
listTableColumns
(
$table
)
{
throw
new
Doctrine_Import_Exception
(
__FUNCTION__
.
' not supported by this driver.'
);
}
/**
...
...
@@ -93,7 +113,8 @@ class Doctrine_Import extends Doctrine_Connection_Module {
* @param string $table database table name
* @return array
*/
public
function
listTableIndexes
(
$table
)
{
public
function
listTableIndexes
(
$table
)
{
throw
new
Doctrine_Import_Exception
(
__FUNCTION__
.
' not supported by this driver.'
);
}
/**
...
...
@@ -102,7 +123,8 @@ class Doctrine_Import extends Doctrine_Connection_Module {
* @param string|null $database
* @return array
*/
public
function
listTables
(
$database
=
null
)
{
public
function
listTables
(
$database
=
null
)
{
throw
new
Doctrine_Import_Exception
(
__FUNCTION__
.
' not supported by this driver.'
);
}
/**
...
...
@@ -111,7 +133,8 @@ class Doctrine_Import extends Doctrine_Connection_Module {
* @param string $table database table name
* @return array
*/
public
function
listTableTriggers
(
$table
)
{
public
function
listTableTriggers
(
$table
)
{
throw
new
Doctrine_Import_Exception
(
__FUNCTION__
.
' not supported by this driver.'
);
}
/**
...
...
@@ -120,7 +143,8 @@ class Doctrine_Import extends Doctrine_Connection_Module {
* @param string $table database table name
* @return array
*/
public
function
listTableViews
(
$table
)
{
public
function
listTableViews
(
$table
)
{
throw
new
Doctrine_Import_Exception
(
__FUNCTION__
.
' not supported by this driver.'
);
}
/**
...
...
@@ -128,8 +152,13 @@ class Doctrine_Import extends Doctrine_Connection_Module {
*
* @return array
*/
public
function
listUsers
()
{
throw
new
Doctrine_Import_Exception
(
__FUNCTION__
.
' not supported by this driver.'
);
public
function
listUsers
()
{
if
(
!
isset
(
$this
->
sql
[
'listUsers'
]))
{
throw
new
Doctrine_Import_Exception
(
__FUNCTION__
.
' not supported by this driver.'
);
}
return
$this
->
conn
->
fetchColumn
(
$this
->
sql
[
'listUsers'
]);
}
/**
* lists database views
...
...
@@ -137,7 +166,12 @@ class Doctrine_Import extends Doctrine_Connection_Module {
* @param string|null $database
* @return array
*/
public
function
listViews
(
$database
=
null
)
{
throw
new
Doctrine_Import_Exception
(
__FUNCTION__
.
' not supported by this driver.'
);
public
function
listViews
(
$database
=
null
)
{
if
(
!
isset
(
$this
->
sql
[
'listViews'
]))
{
throw
new
Doctrine_Import_Exception
(
__FUNCTION__
.
' not supported by this driver.'
);
}
return
$this
->
conn
->
fetchColumn
(
$this
->
sql
[
'listViews'
]);
}
}
lib/Doctrine/Import/Pgsql.php
View file @
b40c969f
...
...
@@ -34,7 +34,7 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
protected
$sql
=
array
(
'listDatabases'
=>
'SELECT datname FROM pg_database'
,
'listFunctions'
=>
"SELECT
'listFunctions'
=>
"SELECT
proname
FROM
pg_proc pr,
...
...
@@ -46,14 +46,14 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
AND pr.pronamespace IN
(SELECT oid FROM pg_namespace
WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema'"
,
'listSequences'
=>
"SELECT
'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
'listTables'
=>
"SELECT
c.relname AS table_name
FROM pg_class c, pg_user u
WHERE c.relowner = u.usesysid
...
...
@@ -68,27 +68,54 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
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'
'listUsers'
=>
'SELECT usename FROM pg_user'
,
'listTableConstraints'
=>
"SELECT
relname
FROM
pg_class
WHERE oid IN (
SELECT indexrelid
FROM pg_index, pg_class
WHERE pg_class.relname = %s
AND pg_class.oid = pg_index.indrelid
AND (indisunique = 't' OR indisprimary = 't')
)"
,
'listTableIndexes'
=>
"SELECT
relname
FROM
pg_class
WHERE oid IN (
SELECT indexrelid
FROM pg_index, pg_class
WHERE pg_class.relname=%s
AND pg_class.oid=pg_index.indrelid
AND indisunique != 't'
AND indisprimary != 't'
)"
,
'listTableColumns'
=>
"SELECT
a.attnum,
a.attname AS field,
t.typname AS type,
format_type(a.atttypid, a.atttypmod) AS complete_type,
a.attnotnull AS isnotnull,
(SELECT 't'
FROM pg_index
WHERE c.oid = pg_index.indrelid
AND pg_index.indkey[0] = a.attnum
AND pg_index.indisprimary = 't'
) AS pri,
(SELECT pg_attrdef.adsrc
FROM pg_attrdef
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 = %s
AND a.attnum > 0
AND a.attrelid = c.oid
AND a.atttypid = t.oid
ORDER BY a.attnum"
,
);
/**
* listDatabases
* lists all databases
*
* @return array
*/
public
function
listDatabases
()
{
return
$this
->
conn
->
fetchColumn
(
$this
->
sql
[
'listDatabases'
]);
}
/**
* lists all availible database functions
*
* @return array
*/
public
function
listFunctions
()
{
return
$this
->
conn
->
fetchColumn
(
$this
->
sql
[
'listFunctions'
]);
}
/**
* lists all database triggers
*
...
...
@@ -97,15 +124,6 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
*/
public
function
listTriggers
(
$database
=
null
)
{
}
/**
* lists all database sequences
*
* @param string|null $database
* @return array
*/
public
function
listSequences
(
$database
=
null
)
{
return
$this
->
conn
->
fetchColumn
(
$this
->
sql
[
'listSequences'
]);
}
/**
* lists table constraints
...
...
@@ -114,10 +132,8 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
* @return array
*/
public
function
listTableConstraints
(
$table
)
{
$table
=
$db
->
quote
(
$table
,
'text'
);
$subquery
=
"SELECT indexrelid FROM pg_index, pg_class"
;
$subquery
.=
" WHERE pg_class.relname=
$table
AND pg_class.oid=pg_index.indrelid AND (indisunique = 't' OR indisprimary = 't')"
;
$query
=
"SELECT relname FROM pg_class WHERE oid IN (
$subquery
)"
;
$table
=
$this
->
conn
->
quote
(
$table
);
$query
=
sprintf
(
$this
->
sql
[
'listTableConstraints'
],
$table
);
return
$this
->
conn
->
fetchColumn
(
$query
);
}
...
...
@@ -128,24 +144,8 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
* @return array
*/
public
function
listTableColumns
(
$table
)
{
$sql
=
"SELECT a.attnum, a.attname AS field, t.typname AS type, format_type(a.atttypid, a.atttypmod) AS complete_type, "
.
"a.attnotnull AS isnotnull, "
.
"( SELECT 't' "
.
"FROM pg_index "
.
"WHERE c.oid = pg_index.indrelid "
.
"AND pg_index.indkey[0] = a.attnum "
.
"AND pg_index.indisprimary = 't') AS pri, "
.
"(SELECT pg_attrdef.adsrc "
.
"FROM pg_attrdef "
.
"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
.
"' "
.
"AND a.attnum > 0 "
.
"AND a.attrelid = c.oid "
.
"AND a.atttypid = t.oid "
.
"ORDER BY a.attnum "
;
$result
=
$this
->
dbh
->
query
(
$sql
)
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
$result
=
$this
->
dbh
->
query
(
$this
->
sql
[
'listTableColumns'
])
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
$columns
=
array
();
foreach
(
$result
as
$key
=>
$val
)
{
if
(
$val
[
'type'
]
===
'varchar'
)
{
...
...
@@ -172,10 +172,8 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
* @return array
*/
public
function
listTableIndexes
(
$table
)
{
$table
=
$db
->
quote
(
$table
,
'text'
);
$subquery
=
"SELECT indexrelid FROM pg_index, pg_class"
;
$subquery
.=
" WHERE pg_class.relname=
$table
AND pg_class.oid=pg_index.indrelid AND indisunique != 't' AND indisprimary != 't'"
;
$query
=
"SELECT relname FROM pg_class WHERE oid IN (
$subquery
)"
;
$table
=
$this
->
conn
->
quote
(
$table
);
$query
=
sprintf
(
$this
->
sql
[
'listTableIndexes'
],
$table
);
return
$this
->
conn
->
fetchColumn
(
$query
);
}
...
...
@@ -206,21 +204,4 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
public
function
listTableViews
(
$table
)
{
return
$this
->
conn
->
fetchColumn
(
$query
);
}
/**
* lists database users
*
* @return array
*/
public
function
listUsers
()
{
return
$this
->
conn
->
fetchColumn
(
$this
->
sql
[
'listUsers'
]);
}
/**
* lists database views
*
* @param string|null $database
* @return array
*/
public
function
listViews
(
$database
=
null
)
{
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