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
8784fe66
Commit
8784fe66
authored
Jun 18, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
e1d295f3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
69 deletions
+80
-69
Pgsql.php
lib/Doctrine/DataDict/Pgsql.php
+2
-1
Export.php
lib/Doctrine/Export.php
+63
-48
Sqlite.php
lib/Doctrine/Export/Sqlite.php
+15
-20
No files found.
lib/Doctrine/DataDict/Pgsql.php
View file @
8784fe66
...
...
@@ -368,7 +368,8 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict
case
'string'
:
case
'array'
:
case
'object'
:
case
'varchar'
:
case
'varchar'
:
case
'gzip'
:
$length
=
(
isset
(
$field
[
'length'
])
&&
$field
[
'length'
])
?
$field
[
'length'
]
:
null
;
// TODO: $this->conn->options['default_text_field_length'];
...
...
lib/Doctrine/Export.php
View file @
8784fe66
...
...
@@ -875,21 +875,21 @@ class Doctrine_Export extends Doctrine_Connection_Module
*/
public
function
export
(
$directory
=
null
)
{
if
(
$directory
!==
null
)
{
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$directory
),
RecursiveIteratorIterator
::
LEAVES_ONLY
);
foreach
(
$it
as
$file
)
{
$e
=
explode
(
'.'
,
$file
->
getFileName
());
if
(
end
(
$e
)
===
'php'
&&
count
(
$e
)
===
2
)
{
require_once
$e
->
getPathName
();
}
$sql
=
$this
->
exportSql
(
$directory
);
foreach
(
$sql
as
$query
)
{
try
{
$this
->
conn
->
exec
(
$query
);
}
catch
(
Doctrine_Connection_Exception
$e
)
{
// we only want to silence table already exists errors
if
(
$e
->
getPortableCode
()
!==
Doctrine
::
ERR_ALREADY_EXISTS
)
{
throw
$e
;
}
}
}
return
$this
->
exportClasses
(
get_declared_classes
());
}
}
/**
* export
* export
Classes
* method for exporting Doctrine_Record classes to a schema
*
* @throws Doctrine_Connection_Exception if some error other than Doctrine::ERR_ALREADY_EXISTS
...
...
@@ -899,51 +899,31 @@ class Doctrine_Export extends Doctrine_Connection_Module
*/
public
function
exportClasses
(
array
$classes
)
{
$parent
=
new
ReflectionClass
(
'Doctrine_Record'
);
foreach
(
$classes
as
$name
)
{
$class
=
new
ReflectionClass
(
$name
);
$conn
=
Doctrine_Manager
::
getInstance
()
->
getConnectionForComponent
(
$name
);
$sql
=
$this
->
exportClassesSql
(
$classes
);
if
(
$class
->
isSubclassOf
(
$parent
)
&&
!
$class
->
isAbstract
())
{
$record
=
new
$name
();
$table
=
$record
->
getTable
();
$conn
->
export
->
exportTable
(
$table
);
foreach
(
$sql
as
$query
)
{
try
{
$this
->
conn
->
exec
(
$query
);
}
catch
(
Doctrine_Connection_Exception
$e
)
{
// we only want to silence table already exists errors
if
(
$e
->
getPortableCode
()
!==
Doctrine
::
ERR_ALREADY_EXISTS
)
{
print
$query
.
"<br>"
;
throw
$e
;
}
}
}
}
/**
* export
* returns the sql for exporting Doctrine_Record classes to a schema
*
* if the directory parameter is given this method first iterates
* recursively trhough the given directory in order to find any model classes
*
* Then it iterates through all declared classes and creates tables for the ones
* that extend Doctrine_Record and are not abstract classes
* exportClassesSql
* method for exporting Doctrine_Record classes to a schema
*
* @throws Doctrine_Connection_Exception if some error other than Doctrine::ERR_ALREADY_EXISTS
* occurred during the create table operation
* @param
string $directory optional directory parameter
* @param
array $classes
* @return void
*/
public
function
export
Sql
(
$directory
=
null
)
public
function
export
ClassesSql
(
array
$classes
)
{
$declared
=
get_declared_classes
();
if
(
$directory
!==
null
)
{
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$directory
),
RecursiveIteratorIterator
::
LEAVES_ONLY
);
foreach
(
$it
as
$file
)
{
$e
=
explode
(
'.'
,
$file
->
getFileName
());
if
(
end
(
$e
)
===
'php'
&&
count
(
$e
)
===
2
)
{
require_once
$file
->
getPathName
();
}
}
}
$parent
=
new
ReflectionClass
(
'Doctrine_Record'
);
$sql
=
array
();
...
...
@@ -951,7 +931,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
// we iterate trhough the diff of previously declared classes
// and currently declared classes
foreach
(
array_diff
(
get_declared_classes
(),
$declared
)
as
$name
)
{
foreach
(
$classes
as
$name
)
{
$class
=
new
ReflectionClass
(
$name
);
$conn
=
Doctrine_Manager
::
getInstance
()
->
getConnectionForComponent
(
$name
);
...
...
@@ -978,13 +958,48 @@ class Doctrine_Export extends Doctrine_Connection_Module
foreach
(
$fks
as
$tableName
=>
$fk
)
{
foreach
(
$fk
as
$k
=>
$definition
)
{
if
(
is_array
(
$definition
))
{
$sql
[]
=
$this
->
createForeignKeySql
(
$definition
[
'table'
],
$definition
);
}
}
}
return
$sql
;
}
/**
* exportSql
* returns the sql for exporting Doctrine_Record classes to a schema
*
* if the directory parameter is given this method first iterates
* recursively trhough the given directory in order to find any model classes
*
* Then it iterates through all declared classes and creates tables for the ones
* that extend Doctrine_Record and are not abstract classes
*
* @throws Doctrine_Connection_Exception if some error other than Doctrine::ERR_ALREADY_EXISTS
* occurred during the create table operation
* @param string $directory optional directory parameter
* @return void
*/
public
function
exportSql
(
$directory
=
null
)
{
$declared
=
get_declared_classes
();
if
(
$directory
!==
null
)
{
foreach
((
array
)
$directory
as
$dir
)
{
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$dir
),
RecursiveIteratorIterator
::
LEAVES_ONLY
);
foreach
(
$it
as
$file
)
{
$e
=
explode
(
'.'
,
$file
->
getFileName
());
if
(
end
(
$e
)
===
'php'
&&
count
(
$e
)
===
2
)
{
require_once
$file
->
getPathName
();
}
}
}
$declared
=
array_diff
(
get_declared_classes
(),
$declared
);
}
return
$this
->
exportClassesSql
(
$declared
);
}
/**
* exportTable
* exports given table into database based on column and option definitions
...
...
lib/Doctrine/Export/Sqlite.php
View file @
8784fe66
...
...
@@ -155,7 +155,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
*
* @return void
*/
public
function
createTable
(
$name
,
array
$fields
,
array
$options
=
array
())
public
function
createTable
Sql
(
$name
,
array
$fields
,
array
$options
=
array
())
{
if
(
!
$name
)
{
throw
new
Doctrine_Export_Exception
(
'no valid table name specified'
);
...
...
@@ -168,7 +168,8 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
$autoinc
=
false
;
foreach
(
$fields
as
$field
)
{
if
(
isset
(
$field
[
'autoincrement'
])
&&
$field
[
'autoincrement'
])
{
if
(
isset
(
$field
[
'autoincrement'
])
&&
$field
[
'autoincrement'
]
||
(
isset
(
$field
[
'autoinc'
])
&&
$field
[
'autoinc'
]))
{
$autoinc
=
true
;
break
;
}
...
...
@@ -177,19 +178,6 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
if
(
!
$autoinc
&&
isset
(
$options
[
'primary'
])
&&
!
empty
(
$options
[
'primary'
]))
{
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
array_values
(
$options
[
'primary'
]))
.
')'
;
}
// sqlite doesn't support foreign key declaration but it parses those anyway
$fk
=
array
();
if
(
isset
(
$options
[
'foreignKeys'
])
&&
!
empty
(
$options
[
'foreignKeys'
]))
{
foreach
(
$options
[
'foreignKeys'
]
as
$definition
)
{
//$queryFields .= ', ' . $this->getForeignKeyDeclaration($definition);
if
(
isset
(
$definition
[
'onDelete'
]))
{
$fk
[]
=
$definition
;
}
}
}
if
(
isset
(
$options
[
'indexes'
])
&&
!
empty
(
$options
[
'indexes'
]))
{
foreach
(
$options
[
'indexes'
]
as
$index
=>
$definition
)
{
...
...
@@ -199,15 +187,19 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
$name
=
$this
->
conn
->
quoteIdentifier
(
$name
,
true
);
$query
=
'CREATE TABLE '
.
$name
.
' ('
.
$queryFields
.
')'
;
return
$query
;
/**
try {
/**
if ( ! empty($fk)) {
$this->conn->beginTransaction();
}
*/
$ret = $this->conn->exec($query);
/**
if ( ! empty($fk)) {
foreach ($fk as $definition) {
...
...
@@ -228,13 +220,15 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
$this->conn->commit();
}
*/
} catch(Doctrine_Exception $e) {
$this->conn->rollback();
throw $e;
}
*/
}
/**
* getAdvancedForeignKeyOptions
...
...
@@ -316,6 +310,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
public
function
dropSequenceSql
(
$sequenceName
)
{
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
getSequenceName
(
$sequenceName
),
true
);
return
'DROP TABLE '
.
$sequenceName
;
}
}
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