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
81a21344
Commit
81a21344
authored
Feb 10, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
1f27c65b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
198 additions
and
26 deletions
+198
-26
Connection.php
lib/Doctrine/Connection.php
+1
-11
Export.php
lib/Doctrine/Export.php
+173
-8
Import.php
lib/Doctrine/Import.php
+17
-0
Mssql.php
lib/Doctrine/Import/Mssql.php
+5
-5
Record.php
lib/Doctrine/Record.php
+2
-2
No files found.
lib/Doctrine/Connection.php
View file @
81a21344
...
...
@@ -463,17 +463,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
return
true
;
}
/**
* returns the next value in the given sequence
*
* @param string $sequence
* @throws PDOException if something went wrong at database level
* @return integer
*/
public
function
nextId
(
$sequence
)
{
throw
new
Doctrine_Connection_Exception
(
'NextId() for sequences not supported by this driver.'
);
}
/**
* Set the charset on the current connection
*
...
...
@@ -483,6 +472,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*/
public
function
setCharset
(
$charset
)
{
}
/**
* Set the date/time format for the current connection
...
...
lib/Doctrine/Export.php
View file @
81a21344
...
...
@@ -131,9 +131,9 @@ class Doctrine_Export extends Doctrine_Connection_Module
* );
* @param array $options An associative array of table options:
*
* @return
void
* @return
string
*/
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'
);
...
...
@@ -145,27 +145,56 @@ class Doctrine_Export extends Doctrine_Connection_Module
$queryFields
=
$this
->
getFieldDeclarationList
(
$fields
);
if
(
isset
(
$options
[
'primary'
])
&&
!
empty
(
$options
[
'primary'
]))
{
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
array_values
(
$options
[
'primary'
]))
.
')'
;
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
array_values
(
$options
[
'primary'
]))
.
')'
;
}
if
(
isset
(
$options
[
'indexes'
])
&&
!
empty
(
$options
[
'indexes'
]))
{
foreach
(
$options
[
'indexes'
]
as
$index
=>
$definition
)
{
$queryFields
.=
', '
.
$this
->
getIndexDeclaration
(
$index
,
$definition
);
}
}
$name
=
$this
->
conn
->
quoteIdentifier
(
$name
,
true
);
$query
=
'CREATE TABLE '
.
$name
.
' ('
.
$queryFields
.
')'
;
return
$this
->
conn
->
exec
(
$query
);
return
$query
;
}
/**
* create a new table
*
* @param string $name Name of the database that should be created
* @param array $fields Associative array that contains the definition of each field of the new table
* @param array $options An associative array of table options:
* @see Doctrine_Export::createTableSql()
*
* @return void
*/
public
function
createTable
(
$name
,
array
$fields
,
array
$options
=
array
())
{
return
$this
->
conn
->
execute
(
$this
->
createTableSql
(
$name
,
$fields
,
$options
));
}
/**
* create sequence
* (this method is implemented by the drivers)
*
* @param string $seqName name of the sequence to be created
* @param string $start start value of the sequence; default is 1
* @return void
*/
public
function
createSequence
(
$seqName
,
$start
=
1
)
{
return
$this
->
conn
->
execute
(
$this
->
createSequenceSql
(
$seqName
,
$start
=
1
));
}
/**
* return RDBMS specific create sequence statement
* (this method is implemented by the drivers)
*
* @param string $seqName name of the sequence to be created
* @param string $start start value of the sequence; default is 1
* @return string
*/
public
function
createSequenceSql
(
$seqName
,
$start
=
1
)
{
throw
new
Doctrine_Export_Exception
(
'Create sequence not supported by this driver.'
);
}
/**
* create a constraint on a table
*
...
...
@@ -479,7 +508,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
$default
=
' DEFAULT '
.
$this
->
conn
->
quote
(
$field
[
'default'
],
$field
[
'type'
]);
}
elseif
(
empty
(
$field
[
'notnull'
]))
{
$default
=
' DEFAULT NULL'
;
//
$default = ' DEFAULT NULL';
}
$charset
=
(
isset
(
$field
[
'charset'
])
&&
$field
[
'charset'
])
?
...
...
@@ -502,6 +531,142 @@ class Doctrine_Export extends Doctrine_Connection_Module
}
return
$this
->
conn
->
quoteIdentifier
(
$name
,
true
)
.
' '
.
$dec
.
$charset
.
$default
.
$notnull
.
$unique
.
$collation
;
}
/**
* Obtain DBMS specific SQL code portion needed to set an index
* declaration to be used in statements like CREATE TABLE.
*
* @param string $charset name of the index
* @param array $definition index definition
* @return string DBMS specific SQL code portion needed to set an index
*/
public
function
getIndexDeclaration
(
$name
,
array
$definition
)
{
$name
=
$this
->
conn
->
quoteIdentifier
(
$name
);
$type
=
''
;
if
(
isset
(
$definition
[
'type'
]))
{
if
(
strtolower
(
$definition
[
'type'
])
==
'unique'
)
{
$type
=
strtoupper
(
$definition
[
'type'
])
.
' '
;
}
else
{
throw
new
Doctrine_Export_Exception
(
'Unknown index type '
.
$definition
[
'type'
]);
}
}
if
(
!
isset
(
$definition
[
'fields'
])
||
!
is_array
(
$definition
[
'fields'
]))
{
throw
new
Doctrine_Export_Exception
(
'No index columns given.'
);
}
$query
=
$type
.
'INDEX '
.
$name
;
$query
.=
' ('
.
$this
->
getIndexFieldDeclarationList
(
$definition
[
'fields'
])
.
')'
;
return
$query
;
}
/**
* getIndexFieldDeclarationList
* Obtain DBMS specific SQL code portion needed to set an index
* declaration to be used in statements like CREATE TABLE.
*
* @return string
*/
public
function
getIndexFieldDeclarationList
(
array
$fields
)
{
foreach
(
$fields
as
$field
=>
$definition
)
{
if
(
is_array
(
$definition
))
{
$fields
[]
=
$this
->
conn
->
quoteIdentifier
(
$field
);
}
else
{
$fields
[]
=
$definition
;
}
}
return
implode
(
', '
,
$fields
);
}
/**
* getForeignKeyDeclaration
* Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
* of a field declaration to be used in statements like CREATE TABLE.
*
* @param array $definition an associative array with the following structure:
* name optional constraint name
*
* local the local field(s)
*
* foreign the foreign reference field(s)
*
* foreignTable the name of the foreign table
*
* onDelete referential delete action
*
* onUpdate referential update action
*
* The onDelete and onUpdate keys accept the following values:
*
* CASCADE: Delete or update the row from the parent table and automatically delete or
* update the matching rows in the child table. Both ON DELETE CASCADE and ON UPDATE CASCADE are supported.
* Between two tables, you should not define several ON UPDATE CASCADE clauses that act on the same column
* in the parent table or in the child table.
*
* SET NULL: Delete or update the row from the parent table and set the foreign key column or columns in the
* child table to NULL. This is valid only if the foreign key columns do not have the NOT NULL qualifier
* specified. Both ON DELETE SET NULL and ON UPDATE SET NULL clauses are supported.
*
* NO ACTION: In standard SQL, NO ACTION means no action in the sense that an attempt to delete or update a primary
* key value is not allowed to proceed if there is a related foreign key value in the referenced table.
*
* RESTRICT: Rejects the delete or update operation for the parent table. NO ACTION and RESTRICT are the same as
* omitting the ON DELETE or ON UPDATE clause.
*
* SET DEFAULT
*
* @return string DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
* of a field declaration.
*/
public
function
getForeignKeyDeclaration
(
$definition
)
{
$sql
=
''
;
if
(
isset
(
$definition
[
'name'
]))
{
$sql
.=
'CONSTRAINT '
.
$definition
[
'name'
];
}
if
(
!
isset
(
$definition
[
'local'
]))
{
throw
new
Doctrine_Export_Exception
(
'Local reference field missing from definition.'
);
}
if
(
!
isset
(
$definition
[
'foreign'
]))
{
throw
new
Doctrine_Export_Exception
(
'Foreign reference field missing from definition.'
);
}
if
(
!
isset
(
$definition
[
'foreignTable'
]))
{
throw
new
Doctrine_Export_Exception
(
'Foreign reference table missing from definition.'
);
}
if
(
!
is_array
(
$definition
[
'local'
]))
{
$definition
[
'local'
]
=
array
(
$definition
[
'local'
]);
}
if
(
!
is_array
(
$definition
[
'foreign'
]))
{
$definition
[
'foreign'
]
=
array
(
$definition
[
'foreign'
]);
}
$sql
.=
implode
(
', '
,
array_map
(
array
(
$this
->
conn
,
'quoteIdentifier'
),
$definition
[
'local'
]))
.
' REFERENCES '
.
$definition
[
'foreignTable'
]
.
'('
.
implode
(
', '
,
array_map
(
array
(
$this
->
conn
,
'quoteIdentifier'
),
$definition
[
'foreign'
]))
.
')'
;
$a
=
array
(
'onUpdate'
,
'onDelete'
);
foreach
(
$a
as
$v
)
{
$keyword
=
(
$v
==
'onUpdate'
)
?
' ON UPDATE '
:
' ON DELETE '
;
if
(
isset
(
$definition
[
$v
]))
{
switch
(
$definition
[
$v
])
{
case
'CASCADE'
:
case
'SET NULL'
:
case
'NO ACTION'
:
case
'RESTRICT'
:
case
'SET DEFAULT'
:
$sql
.=
$keyword
.
$definition
[
$v
];
break
;
default
:
throw
new
Doctrine_Export_Exception
(
'Unknown foreign key referential action option given.'
);
}
}
}
return
$sql
;
}
/**
* Obtain DBMS specific SQL code portion needed to set the UNIQUE constraint
* of a field declaration to be used in statements like CREATE TABLE.
...
...
lib/Doctrine/Import.php
View file @
81a21344
...
...
@@ -174,4 +174,21 @@ class Doctrine_Import extends Doctrine_Connection_Module
return
$this
->
conn
->
fetchColumn
(
$this
->
sql
[
'listViews'
]);
}
/**
* import
*
* method for importing existing schema to Doctrine_Record classes
*
* @param string $directory
* @param array $databases
*/
public
function
import
(
$directory
,
array
$databases
=
array
())
{
$builder
=
new
Doctrine_Import_Builder
();
$builder
->
setTargetPath
(
$directory
);
foreach
(
$this
->
listTables
()
as
$table
)
{
$builder
->
buildRecord
(
$table
,
$this
->
listTableColumns
(
$table
));
}
}
}
lib/Doctrine/Import/Mssql.php
View file @
81a21344
lib/Doctrine/Record.php
View file @
81a21344
...
...
@@ -1067,8 +1067,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$a
[
$v
]
=
$this
->
_data
[
$v
];
}
}
foreach
(
$
this
->
_table
->
inheritanceM
ap
as
$k
=>
$v
)
{
$map
=
$this
->
_table
->
inheritanceMap
;
foreach
(
$
m
ap
as
$k
=>
$v
)
{
$old
=
$this
->
get
(
$k
,
false
);
if
((
string
)
$old
!==
(
string
)
$v
||
$old
===
null
)
{
...
...
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