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
d4fa4640
Commit
d4fa4640
authored
Feb 10, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated index handling
parent
c70a8577
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
17 deletions
+48
-17
Mysql.php
lib/Doctrine/Export/Mysql.php
+9
-2
Sqlite.php
lib/Doctrine/Export/Sqlite.php
+39
-15
No files found.
lib/Doctrine/Export/Mysql.php
View file @
d4fa4640
...
...
@@ -92,7 +92,7 @@ class Doctrine_Export_Mysql 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'
);
...
...
@@ -104,6 +104,13 @@ class Doctrine_Export_Mysql extends Doctrine_Export
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
);
}
}
$name
=
$this
->
conn
->
quoteIdentifier
(
$name
,
true
);
$query
=
'CREATE TABLE '
.
$name
.
' ('
.
$queryFields
.
')'
;
...
...
@@ -134,7 +141,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
if
(
!
empty
(
$optionStrings
))
{
$query
.=
' '
.
implode
(
' '
,
$optionStrings
);
}
return
$
this
->
conn
->
exec
(
$query
)
;
return
$
query
;
}
/**
* alter an existing table
...
...
lib/Doctrine/Export/Sqlite.php
View file @
d4fa4640
...
...
@@ -65,29 +65,47 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
* @throws PDOException
* @return void
*/
public
function
createIndex
(
$table
,
$name
,
array
$definition
)
public
function
createIndex
Sql
(
$table
,
$name
,
array
$definition
)
{
$table
=
$this
->
conn
->
quoteIdentifier
(
$table
,
true
);
$name
=
$this
->
conn
->
getIndexName
(
$name
);
$query
=
'CREATE INDEX '
.
$name
.
' ON '
.
$table
;
$fields
=
array
();
foreach
(
$definition
[
'fields'
]
as
$fieldName
=>
$field
)
{
$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
(
isset
(
$field
[
'sorting'
]))
{
switch
(
$field
[
'sorting'
])
{
case
'ascending'
:
$fieldString
.=
' ASC'
;
break
;
case
'descending'
:
$fieldString
.=
' DESC'
;
break
;
if
(
is_array
(
$field
))
{
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
;
}
$
f
ields
[]
=
$fieldString
;
$
declF
ields
[]
=
$fieldString
;
}
$query
.=
' ('
.
implode
(
', '
,
$fields
)
.
')'
;
return
$this
->
conn
->
exec
(
$query
);
return
implode
(
', '
,
$declFields
);
}
/**
* create a new table
...
...
@@ -140,6 +158,12 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
$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
.
')'
;
...
...
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