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
a92d8d7c
Commit
a92d8d7c
authored
Feb 10, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
a56fd1c7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
21 deletions
+82
-21
Mysql.php
lib/Doctrine/Export/Mysql.php
+82
-21
No files found.
lib/Doctrine/Export/Mysql.php
View file @
a92d8d7c
...
...
@@ -101,15 +101,16 @@ class Doctrine_Export_Mysql extends Doctrine_Export
}
$queryFields
=
$this
->
getFieldDeclarationList
(
$fields
);
if
(
isset
(
$options
[
'primary'
])
&&
!
empty
(
$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
);
}
}
if
(
isset
(
$options
[
'primary'
])
&&
!
empty
(
$options
[
'primary'
]))
{
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
array_values
(
$options
[
'primary'
]))
.
')'
;
}
$name
=
$this
->
conn
->
quoteIdentifier
(
$name
,
true
);
$query
=
'CREATE TABLE '
.
$name
.
' ('
.
$queryFields
.
')'
;
...
...
@@ -231,7 +232,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
* actually perform them otherwise.
* @return boolean
*/
public
function
alterTable
(
$name
,
array
$changes
,
$check
)
public
function
alterTable
Sql
(
$name
,
array
$changes
,
$check
)
{
if
(
!
$name
)
throw
new
Doctrine_Export_Exception
(
'no valid table name specified'
);
...
...
@@ -286,18 +287,18 @@ class Doctrine_Export_Mysql extends Doctrine_Export
}
if
(
!
empty
(
$changes
[
'change'
])
&&
is_array
(
$changes
[
'change'
]))
{
foreach
(
$changes
[
'change'
]
as
$field
_n
ame
=>
$field
)
{
foreach
(
$changes
[
'change'
]
as
$field
N
ame
=>
$field
)
{
if
(
$query
)
{
$query
.=
', '
;
}
if
(
isset
(
$rename
[
$field
_n
ame
]))
{
$old
_field_name
=
$rename
[
$field_n
ame
];
unset
(
$rename
[
$field
_n
ame
]);
if
(
isset
(
$rename
[
$field
N
ame
]))
{
$old
FieldName
=
$rename
[
$fieldN
ame
];
unset
(
$rename
[
$field
N
ame
]);
}
else
{
$old
_field_name
=
$field_n
ame
;
$old
FieldName
=
$fieldN
ame
;
}
$old
_field_n
ame
=
$this
->
conn
->
quoteIdentifier
(
$old_field_name
,
true
);
$query
.=
"CHANGE
$old_field_name
"
.
$this
->
getDeclaration
(
$field
[
'definition'
][
'type'
],
$field_n
ame
,
$field
[
'definition'
]);
$old
FieldN
ame
=
$this
->
conn
->
quoteIdentifier
(
$old_field_name
,
true
);
$query
.=
"CHANGE
$oldFieldName
"
.
$this
->
getDeclaration
(
$field
[
'definition'
][
'type'
],
$fieldN
ame
,
$field
[
'definition'
]);
}
}
...
...
@@ -382,7 +383,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
* array(
* 'fields' => array(
* 'user_name' => array(
* 'sorting' => '
ascending
'
* 'sorting' => '
ASC
'
* 'length' => 10
* ),
* 'last_login' => array()
...
...
@@ -407,20 +408,80 @@ class Doctrine_Export_Mysql extends Doctrine_Export
}
}
$query
=
'CREATE '
.
$type
.
'INDEX '
.
$name
.
' ON '
.
$table
;
$query
.=
' ('
.
$this
->
getIndexFieldDeclarationList
()
.
')'
;
$fields
=
array
();
foreach
(
$definition
[
'fields'
]
as
$field
=>
$fieldinfo
)
{
if
(
!
empty
(
$fieldinfo
[
'length'
]))
{
$fields
[]
=
$field
.
'('
.
$fieldinfo
[
'length'
]
.
')'
;
}
else
{
$fields
[]
=
$field
;
return
$query
;
}
/**
* 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'
]))
{
switch
(
strtolower
(
$definition
[
'type'
]))
{
case
'fulltext'
:
case
'unique'
:
$type
=
strtoupper
(
$definition
[
'type'
])
.
' '
;
break
;
default
:
throw
new
Doctrine_Export_Exception
(
'Unknown index type '
.
$definition
[
'type'
]);
}
}
$query
.=
' ('
.
implode
(
', '
,
$fields
)
.
')'
;
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
)
{
$declFields
=
array
();
foreach
(
$fields
as
$fieldName
=>
$field
)
{
$fieldString
=
$fieldName
;
if
(
is_array
(
$field
))
{
if
(
isset
(
$field
[
'length'
]))
{
$fieldString
.=
'('
.
$field
[
'length'
]
.
')'
;
}
if
(
isset
(
$field
[
'sorting'
]))
{
$sort
=
strtoupper
(
$field
[
'sorting'
]);
switch
(
$sort
)
{
case
'ASC'
:
case
'DESC'
:
$fieldString
.=
' '
.
$sort
;
break
;
default
:
throw
new
Doctrine_Export_Exception
(
'Unknown index sorting option given.'
);
}
}
}
else
{
$fieldString
=
$field
;
}
$declFields
[]
=
$fieldString
;
}
return
implode
(
', '
,
$declFields
);
}
/**
* drop existing index
*
...
...
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