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
61c793c2
Commit
61c793c2
authored
Nov 17, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored export drivers
parent
c1c66b6b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
82 deletions
+81
-82
Mysql.php
lib/Doctrine/Export/Mysql.php
+69
-65
Oracle.php
lib/Doctrine/Export/Oracle.php
+11
-16
Pgsql.php
lib/Doctrine/Export/Pgsql.php
+1
-1
No files found.
lib/Doctrine/Export/Mysql.php
View file @
61c793c2
...
...
@@ -87,50 +87,50 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* 'type' => 'innodb',
* );
*
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
* @return void
*/
public
function
createTable
(
$name
,
array
$fields
,
array
$options
=
array
())
{
if
(
!
$name
)
{
return
$this
->
dbh
->
raiseError
(
MDB2_ERROR_CANNOT_CREATE
,
null
,
null
,
'no valid table name specified'
,
__FUNCTION__
);
}
if
(
!
$name
)
throw
new
Doctrine_Export_Mysql_Exception
(
'no valid table name specified'
);
if
(
empty
(
$fields
))
throw
new
Doctrine_Export_Exception
(
'no fields specified for table "'
.
$name
.
'"'
);
throw
new
Doctrine_Export_
Mysql_
Exception
(
'no fields specified for table "'
.
$name
.
'"'
);
$query_fields
=
$this
->
getFieldDeclarationList
(
$fields
);
if
(
!
empty
(
$options
[
'primary'
]))
{
$query_fields
.=
', PRIMARY KEY ('
.
implode
(
', '
,
array_keys
(
$options
[
'primary'
]))
.
')'
;
}
if
(
!
empty
(
$options
[
'primary'
]))
$query_fields
.=
', PRIMARY KEY ('
.
implode
(
', '
,
array_keys
(
$options
[
'primary'
]))
.
')'
;
$name
=
$this
->
conn
->
quoteIdentifier
(
$name
,
true
);
$query
=
"CREATE TABLE
$name
(
$query_fields
)"
;
$query
=
'CREATE TABLE '
.
$name
.
' ('
.
$query_fields
.
')'
;
$options_strings
=
array
();
$optionStrings
=
array
();
if
(
!
empty
(
$options
[
'comment'
]))
$optionStrings
[
'comment'
]
=
'COMMENT = '
.
$this
->
dbh
->
quote
(
$options
[
'comment'
],
'text'
);
if
(
!
empty
(
$options
[
'comment'
]))
{
$options_strings
[
'comment'
]
=
'COMMENT = '
.
$this
->
dbh
->
quote
(
$options
[
'comment'
],
'text'
);
}
if
(
!
empty
(
$options
[
'charset'
]))
{
$options
_strings
[
'charset'
]
=
'DEFAULT CHARACTER SET '
.
$options
[
'charset'
];
if
(
!
empty
(
$options
[
'collate'
]))
{
$option
s_s
trings
[
'charset'
]
.=
' COLLATE '
.
$options
[
'collate'
];
if
(
!
empty
(
$options
[
'charset'
]))
{
$options
Sting
[
'charset'
]
=
'DEFAULT CHARACTER SET '
.
$options
[
'charset'
];
if
(
!
empty
(
$options
[
'collate'
]))
{
$option
S
trings
[
'charset'
]
.=
' COLLATE '
.
$options
[
'collate'
];
}
}
$type
=
false
;
if
(
!
empty
(
$options
[
'type'
]))
{
$type
=
$options
[
'type'
];
}
elseif
(
$this
->
dbh
->
options
[
'default_table_type'
])
{
$type
=
$this
->
dbh
->
options
[
'default_table_type'
];
}
if
(
$type
)
{
$option
s_s
trings
[]
=
"ENGINE =
$type
"
;
$option
S
trings
[]
=
"ENGINE =
$type
"
;
}
if
(
!
empty
(
$option
s_s
trings
))
{
$query
.=
' '
.
implode
(
' '
,
$option
s_s
trings
);
if
(
!
empty
(
$option
S
trings
))
{
$query
.=
' '
.
implode
(
' '
,
$option
S
trings
);
}
return
$this
->
dbh
->
query
(
$query
);
}
...
...
@@ -223,8 +223,8 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* @return boolean
*/
public
function
alterTable
(
$name
,
$changes
,
$check
)
{
foreach
(
$changes
as
$change
_n
ame
=>
$change
)
{
switch
(
$change
_n
ame
)
{
foreach
(
$changes
as
$change
N
ame
=>
$change
)
{
switch
(
$change
N
ame
)
{
case
'add'
:
case
'remove'
:
case
'change'
:
...
...
@@ -232,21 +232,21 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
case
'name'
:
break
;
default
:
throw
new
Doctrine_Export_Exception
(
'change type "'
.
$change
_n
ame
.
'" not yet supported'
);
throw
new
Doctrine_Export_Exception
(
'change type "'
.
$change
N
ame
.
'" not yet supported'
);
}
}
if
(
$check
)
{
if
(
$check
)
{
return
true
;
}
$query
=
''
;
if
(
!
empty
(
$changes
[
'name'
]))
{
if
(
!
empty
(
$changes
[
'name'
]))
{
$change_name
=
$this
->
conn
->
quoteIdentifier
(
$changes
[
'name'
],
true
);
$query
.=
'RENAME TO '
.
$change_name
;
}
if
(
!
empty
(
$changes
[
'add'
])
&&
is_array
(
$changes
[
'add'
]))
{
if
(
!
empty
(
$changes
[
'add'
])
&&
is_array
(
$changes
[
'add'
]))
{
foreach
(
$changes
[
'add'
]
as
$field_name
=>
$field
)
{
if
(
$query
)
{
$query
.=
', '
;
...
...
@@ -255,7 +255,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
}
}
if
(
!
empty
(
$changes
[
'remove'
])
&&
is_array
(
$changes
[
'remove'
]))
{
if
(
!
empty
(
$changes
[
'remove'
])
&&
is_array
(
$changes
[
'remove'
]))
{
foreach
(
$changes
[
'remove'
]
as
$field_name
=>
$field
)
{
if
(
$query
)
{
$query
.=
', '
;
...
...
@@ -266,13 +266,13 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
}
$rename
=
array
();
if
(
!
empty
(
$changes
[
'rename'
])
&&
is_array
(
$changes
[
'rename'
]))
{
if
(
!
empty
(
$changes
[
'rename'
])
&&
is_array
(
$changes
[
'rename'
]))
{
foreach
(
$changes
[
'rename'
]
as
$field_name
=>
$field
)
{
$rename
[
$field
[
'name'
]]
=
$field_name
;
}
}
if
(
!
empty
(
$changes
[
'change'
])
&&
is_array
(
$changes
[
'change'
]))
{
if
(
!
empty
(
$changes
[
'change'
])
&&
is_array
(
$changes
[
'change'
]))
{
foreach
(
$changes
[
'change'
]
as
$field_name
=>
$field
)
{
if
(
$query
)
{
$query
.=
', '
;
...
...
@@ -288,7 +288,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
}
}
if
(
!
empty
(
$rename
)
&&
is_array
(
$rename
))
{
if
(
!
empty
(
$rename
)
&&
is_array
(
$rename
))
{
foreach
(
$rename
as
$rename_name
=>
$renamed_field
)
{
if
(
$query
)
{
$query
.=
', '
;
...
...
@@ -299,7 +299,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
}
}
if
(
!
$query
)
{
if
(
!
$query
)
{
return
MDB2_OK
;
}
...
...
@@ -309,29 +309,34 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
/**
* create sequence
*
* this method has been borrowed from PEAR MDB2 database abstraction layer
*
* @param string $seq_name name of the sequence to be created
* @param string $sequenceName name of the sequence to be created
* @param string $seqcol_name the name of the sequence column
* @param string $start start value of the sequence; default is 1
* @return
mixed MDB2_OK on success, a MDB2 error on failure
* @return
boolean
*/
public
function
createSequence
(
$sequence_name
,
$seqcol_name
,
$start
=
1
)
{
$query
=
"CREATE TABLE
$sequence_name
(
$seqcol_name
INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (
$seqcol_name
))"
;
$query
.=
strlen
(
$this
->
dbh
->
options
[
'default_table_type'
])
?
' TYPE = '
.
$this
->
dbh
->
options
[
'default_table_type'
]
:
''
;
public
function
createSequence
(
$sequenceName
,
$seqcol_name
,
$start
=
1
)
{
$query
=
'CREATE TABLE '
.
$sequenceName
.
' ('
.
$seqcol_name
.
' INT NOT NULL AUTO_INCREMENT, PRIMARY KEY ('
.
$seqcol_name
.
'))'
.
strlen
(
$this
->
dbh
->
options
[
'default_table_type'
])
?
' TYPE = '
.
$this
->
dbh
->
options
[
'default_table_type'
]
:
''
;
$res
=
$this
->
dbh
->
query
(
$query
);
if
(
$start
==
1
)
{
return
MDB2_OK
;
}
if
(
$start
==
1
)
return
true
;
$query
=
'INSERT INTO '
.
$sequenceName
.
' ('
.
$seqcol_name
.
') VALUES ('
.
(
$start
-
1
)
.
')'
;
$query
=
"INSERT INTO
$sequence_name
(
$seqcol_name
) VALUES ("
.
(
$start
-
1
)
.
')'
;
$res
=
$this
->
dbh
->
query
(
$query
);
// Handle error
$result
=
$this
->
dbh
->
query
(
"DROP TABLE
$sequence_name
"
);
if
(
PEAR
::
isError
(
$result
))
{
return
$this
->
dbh
->
raiseError
(
$result
,
null
,
null
,
'could not drop inconsistent sequence table'
,
__FUNCTION__
);
try
{
$result
=
$this
->
dbh
->
query
(
'DROP TABLE '
.
$sequenceName
);
}
catch
(
Exception
$e
)
{
throw
new
Doctrine_Export_Mysql_Exception
(
'could not drop inconsistent sequence table'
);
}
return
$this
->
dbh
->
raiseError
(
$res
,
null
,
null
,
...
...
@@ -340,8 +345,6 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
/**
* Get the stucture of a field into an array
*
* this method has been borrowed from PEAR MDB2 database abstraction layer
*
* @author Leoncx
* @param string $table name of the table on which the index is to be created
* @param string $name name of the index to be created
...
...
@@ -390,24 +393,25 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
}
/**
* drop existing index
* this method has been borrowed from PEAR MDB2 database abstraction layer
*
* @param string $table name of table that should be used in method
* @param string $name name of the index to be dropped
* @return
mixed MDB2_OK on success, a MDB2 error on failure
* @return
void
*/
public
function
dropIndex
(
$table
,
$name
)
{
$table
=
$this
->
conn
->
quoteIdentifier
(
$table
,
true
);
$name
=
$this
->
conn
->
quoteIdentifier
(
$this
->
dbh
->
getIndexName
(
$name
),
true
);
return
$this
->
dbh
->
query
(
"DROP INDEX
$name
ON
$table
"
);
return
$this
->
dbh
->
query
(
'DROP INDEX '
.
$name
.
' ON '
.
$table
);
}
/**
* dropTable
*
* @param string $table name of table that should be dropped from the database
* @throws PDOException
* @return void
*/
public
function
dropTable
(
$table
)
{
$table
=
$this
->
conn
->
quoteIdentifier
(
$table
,
true
);
$this
->
dbh
->
query
(
'DROP TABLE '
.
$table
);
}
}
...
...
lib/Doctrine/Export/Oracle.php
View file @
61c793c2
...
...
@@ -41,10 +41,9 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
* @access public
*/
public
function
createDatabase
(
$name
)
{
if
(
!
$db
->
options
[
'emulate_database'
])
{
return
$db
->
raiseError
(
MDB2_ERROR_UNSUPPORTED
,
null
,
null
,
'database creation is only supported if the "emulate_database" option is enabled'
,
__FUNCTION__
);
}
if
(
!
$db
->
options
[
'emulate_database'
])
throw
new
Doctrine_Export_Oracle_Exception
(
'database creation is only supported if the "emulate_database" option is enabled'
);
$username
=
$db
->
options
[
'database_name_prefix'
]
.
$name
;
$password
=
$db
->
dsn
[
'password'
]
?
$db
->
dsn
[
'password'
]
:
$name
;
...
...
@@ -53,9 +52,7 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
$query
=
'CREATE USER '
.
$username
.
' IDENTIFIED BY '
.
$password
.
$tablespace
;
$result
=
$db
->
standaloneQuery
(
$query
,
null
,
true
);
if
(
PEAR
::
isError
(
$result
))
{
return
$result
;
}
$query
=
'GRANT CREATE SESSION, CREATE TABLE, UNLIMITED TABLESPACE, CREATE SEQUENCE, CREATE TRIGGER TO '
.
$username
;
$result
=
$db
->
standaloneQuery
(
$query
,
null
,
true
);
if
(
PEAR
::
isError
(
$result
))
{
...
...
@@ -77,10 +74,10 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
* @access public
*/
public
function
dropDatabase
(
$name
)
{
if
(
!
$db
->
options
[
'emulate_database'
])
{
return
$db
->
raiseError
(
MDB2_ERROR_UNSUPPORTED
,
null
,
null
,
'database dropping is only supported if the "emulate_database" option is enabled'
,
__FUNCTION__
);
}
if
(
!
$db
->
options
[
'emulate_database'
])
throw
new
Doctrine_Export_Oracle_Exception
(
'database dropping is only supported if the
"emulate_database" option is enabled'
);
$username
=
$db
->
options
[
'database_name_prefix'
]
.
$name
;
return
$db
->
standaloneQuery
(
'DROP USER '
.
$username
.
' CASCADE'
,
null
,
true
);
...
...
@@ -339,9 +336,7 @@ END;
* @param boolean $check indicates whether the function should just check if the DBMS driver
* can perform the requested table alterations if the value is true or
* actually perform them otherwise.
* @access public
*
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @return void
*/
public
function
alterTable
(
$name
,
$changes
,
$check
)
{
...
...
@@ -423,7 +418,7 @@ END;
* @param object $db database object that is extended by this class
* @param string $seq_name name of the sequence to be created
* @param string $start start value of the sequence; default is 1
* @return
mixed MDB2_OK on success, a MDB2 error on failure
* @return
void
*/
public
function
createSequence
(
$seq_name
,
$start
=
1
)
{
$sequence_name
=
$db
->
quoteIdentifier
(
$db
->
getSequenceName
(
$seq_name
),
true
);
...
...
@@ -436,7 +431,7 @@ END;
*
* @param object $db database object that is extended by this class
* @param string $seq_name name of the sequence to be dropped
* @return
mixed MDB2_OK on success, a MDB2 error on failure
* @return
void
*/
public
function
dropSequence
(
$seq_name
)
{
$sequence_name
=
$db
->
quoteIdentifier
(
$db
->
getSequenceName
(
$seq_name
),
true
);
...
...
lib/Doctrine/Export/Pgsql.php
View file @
61c793c2
...
...
@@ -143,7 +143,7 @@ class Doctrine_Export_Pgsql extends Doctrine_Export {
* @throws PDOException
* @return boolean
*/
function
alterTable
(
$name
,
$changes
,
$check
)
{
public
function
alterTable
(
$name
,
$changes
,
$check
)
{
foreach
(
$changes
as
$change_name
=>
$change
)
{
switch
(
$change_name
)
{
case
'add'
:
...
...
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