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
01a3e063
Commit
01a3e063
authored
Sep 30, 2007
by
jackbravo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed some identifier quoting on sqlite, mysql and pgsql. Added some tests too
parent
73c90e85
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
149 additions
and
12 deletions
+149
-12
Export.php
lib/Doctrine/Export.php
+1
-1
Mysql.php
lib/Doctrine/Export/Mysql.php
+8
-5
Pgsql.php
lib/Doctrine/Export/Pgsql.php
+3
-1
Sqlite.php
lib/Doctrine/Export/Sqlite.php
+7
-5
MysqlTestCase.php
tests/Export/MysqlTestCase.php
+45
-0
PgsqlTestCase.php
tests/Export/PgsqlTestCase.php
+46
-0
SqliteTestCase.php
tests/Export/SqliteTestCase.php
+39
-0
No files found.
lib/Doctrine/Export.php
View file @
01a3e063
...
...
@@ -920,7 +920,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
$sql
.=
implode
(
', '
,
array_map
(
array
(
$this
->
conn
,
'quoteIdentifier'
),
$definition
[
'local'
]))
.
') REFERENCES '
.
$
definition
[
'foreignTable'
]
.
'('
.
$
this
->
conn
->
quoteIdentifier
(
$definition
[
'foreignTable'
])
.
'('
.
implode
(
', '
,
array_map
(
array
(
$this
->
conn
,
'quoteIdentifier'
),
$definition
[
'foreign'
]))
.
')'
;
return
$sql
;
...
...
lib/Doctrine/Export/Mysql.php
View file @
01a3e063
...
...
@@ -134,7 +134,9 @@ class Doctrine_Export_Mysql extends Doctrine_Export
// attach all primary keys
if
(
isset
(
$options
[
'primary'
])
&&
!
empty
(
$options
[
'primary'
]))
{
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
array_values
(
$options
[
'primary'
]))
.
')'
;
$keyColumns
=
array_values
(
$options
[
'primary'
]);
$keyColumns
=
array_map
(
array
(
$this
->
conn
,
'quoteIdentifier'
),
$keyColumns
);
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
$keyColumns
)
.
')'
;
}
$query
=
'CREATE TABLE '
.
$this
->
conn
->
quoteIdentifier
(
$name
,
true
)
.
' ('
.
$queryFields
.
')'
;
...
...
@@ -470,6 +472,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
{
$table
=
$table
;
$name
=
$this
->
conn
->
getIndexName
(
$name
);
$name
=
$this
->
conn
->
quoteIdentifier
(
$name
);
$type
=
''
;
if
(
isset
(
$definition
[
'type'
]))
{
switch
(
strtolower
(
$definition
[
'type'
]))
{
...
...
@@ -523,7 +526,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
*/
public
function
getIndexDeclaration
(
$name
,
array
$definition
)
{
$name
=
$this
->
conn
->
quoteIdentifier
(
$name
);
$name
=
$this
->
conn
->
formatter
->
getIndexName
(
$name
);
$type
=
''
;
if
(
isset
(
$definition
[
'type'
]))
{
switch
(
strtolower
(
$definition
[
'type'
]))
{
...
...
@@ -543,7 +546,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
$definition
[
'fields'
]
=
array
(
$definition
[
'fields'
]);
}
$query
=
$type
.
'INDEX '
.
$this
->
conn
->
formatter
->
getIndexName
(
$name
);
$query
=
$type
.
'INDEX '
.
$this
->
conn
->
quoteIdentifier
(
$name
);
$query
.=
' ('
.
$this
->
getIndexFieldDeclarationList
(
$definition
[
'fields'
])
.
')'
;
...
...
@@ -561,7 +564,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
$declFields
=
array
();
foreach
(
$fields
as
$fieldName
=>
$field
)
{
$fieldString
=
$
fieldName
;
$fieldString
=
$
this
->
conn
->
quoteIdentifier
(
$fieldName
)
;
if
(
is_array
(
$field
))
{
if
(
isset
(
$field
[
'length'
]))
{
...
...
@@ -580,7 +583,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
}
}
}
else
{
$fieldString
=
$
field
;
$fieldString
=
$
this
->
conn
->
quoteIdentifier
(
$field
)
;
}
$declFields
[]
=
$fieldString
;
}
...
...
lib/Doctrine/Export/Pgsql.php
View file @
01a3e063
...
...
@@ -305,7 +305,9 @@ class Doctrine_Export_Pgsql extends Doctrine_Export
if
(
isset
(
$options
[
'primary'
])
&&
!
empty
(
$options
[
'primary'
]))
{
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
array_values
(
$options
[
'primary'
]))
.
')'
;
$keyColumns
=
array_values
(
$options
[
'primary'
]);
$keyColumns
=
array_map
(
array
(
$this
->
conn
,
'quoteIdentifier'
),
$keyColumns
);
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
$keyColumns
)
.
')'
;
}
$query
=
'CREATE TABLE '
.
$this
->
conn
->
quoteIdentifier
(
$name
,
true
)
.
' ('
.
$queryFields
.
')'
;
...
...
lib/Doctrine/Export/Sqlite.php
View file @
01a3e063
...
...
@@ -87,8 +87,8 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
*/
public
function
createIndexSql
(
$table
,
$name
,
array
$definition
)
{
$table
=
$this
->
conn
->
quoteIdentifier
(
$table
,
true
);
$name
=
$this
->
conn
->
formatter
->
getIndexName
(
$name
);
$name
=
$this
->
conn
->
quoteIdentifier
(
$name
);
$query
=
'CREATE INDEX '
.
$name
.
' ON '
.
$table
;
$query
.=
' ('
.
$this
->
getIndexFieldDeclarationList
(
$definition
[
'fields'
])
.
')'
;
...
...
@@ -106,7 +106,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
$declFields
=
array
();
foreach
(
$fields
as
$fieldName
=>
$field
)
{
$fieldString
=
$
fieldName
;
$fieldString
=
$
this
->
conn
->
quoteIdentifier
(
$fieldName
)
;
if
(
is_array
(
$field
))
{
if
(
isset
(
$field
[
'sorting'
]))
{
...
...
@@ -121,7 +121,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
}
}
}
else
{
$fieldString
=
$
field
;
$fieldString
=
$
this
->
conn
->
quoteIdentifier
(
$field
)
;
}
$declFields
[]
=
$fieldString
;
}
...
...
@@ -176,7 +176,9 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
}
if
(
!
$autoinc
&&
isset
(
$options
[
'primary'
])
&&
!
empty
(
$options
[
'primary'
]))
{
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
array_values
(
$options
[
'primary'
]))
.
')'
;
$keyColumns
=
array_values
(
$options
[
'primary'
]);
$keyColumns
=
array_map
(
array
(
$this
->
conn
,
'quoteIdentifier'
),
$keyColumns
);
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
$keyColumns
)
.
')'
;
}
$name
=
$this
->
conn
->
quoteIdentifier
(
$name
,
true
);
...
...
tests/Export/MysqlTestCase.php
View file @
01a3e063
...
...
@@ -189,6 +189,51 @@ class Doctrine_Export_Mysql_TestCase extends Doctrine_UnitTestCase
$this
->
assertEqual
(
$sql
[
0
],
'CREATE TABLE mytable (id TINYINT(1), foreignKey INT, INDEX foreignKey_idx (foreignKey)) ENGINE = INNODB'
);
$this
->
assertEqual
(
$sql
[
1
],
'ALTER TABLE mytable ADD CONSTRAINT FOREIGN KEY (foreignKey) REFERENCES sometable(id)'
);
}
public
function
testForeignKeyIdentifierQuoting
()
{
$this
->
conn
->
setAttribute
(
Doctrine
::
ATTR_QUOTE_IDENTIFIER
,
true
);
$name
=
'mytable'
;
$fields
=
array
(
'id'
=>
array
(
'type'
=>
'boolean'
,
'primary'
=>
true
),
'foreignKey'
=>
array
(
'type'
=>
'integer'
)
);
$options
=
array
(
'type'
=>
'INNODB'
,
'foreignKeys'
=>
array
(
array
(
'local'
=>
'foreignKey'
,
'foreign'
=>
'id'
,
'foreignTable'
=>
'sometable'
))
);
$sql
=
$this
->
export
->
createTableSql
(
$name
,
$fields
,
$options
);
$this
->
assertEqual
(
$sql
[
0
],
'CREATE TABLE `mytable` (`id` TINYINT(1), `foreignKey` INT, INDEX `foreignKey_idx` (`foreignKey`)) ENGINE = INNODB'
);
$this
->
assertEqual
(
$sql
[
1
],
'ALTER TABLE `mytable` ADD CONSTRAINT FOREIGN KEY (`foreignKey`) REFERENCES `sometable`(`id`)'
);
$this
->
conn
->
setAttribute
(
Doctrine
::
ATTR_QUOTE_IDENTIFIER
,
false
);
}
public
function
testIndexIdentifierQuoting
()
{
$this
->
conn
->
setAttribute
(
Doctrine
::
ATTR_QUOTE_IDENTIFIER
,
true
);
$fields
=
array
(
'id'
=>
array
(
'type'
=>
'integer'
,
'unsigned'
=>
1
,
'autoincrement'
=>
true
,
'unique'
=>
true
),
'name'
=>
array
(
'type'
=>
'string'
,
'length'
=>
4
),
);
$options
=
array
(
'primary'
=>
array
(
'id'
),
'indexes'
=>
array
(
'myindex'
=>
array
(
'fields'
=>
array
(
'id'
,
'name'
)))
);
$this
->
export
->
createTable
(
'sometable'
,
$fields
,
$options
);
//this was the old line, but it looks like the table is created first
//and then the index so i replaced it with the ones below
//$this->assertEqual($var, 'CREATE TABLE sometable (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(4), INDEX myindex (id, name))');
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'CREATE TABLE `sometable` (`id` INT UNSIGNED AUTO_INCREMENT, `name` VARCHAR(4), INDEX `myindex_idx` (`id`, `name`), PRIMARY KEY(`id`)) ENGINE = INNODB'
);
$this
->
conn
->
setAttribute
(
Doctrine
::
ATTR_QUOTE_IDENTIFIER
,
false
);
}
public
function
testCreateTableDoesNotAutoAddIndexesWhenIndexForFkFieldAlreadyExists
()
{
$name
=
'mytable'
;
...
...
tests/Export/PgsqlTestCase.php
View file @
01a3e063
...
...
@@ -54,6 +54,52 @@ class Doctrine_Export_Pgsql_TestCase extends Doctrine_UnitTestCase
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'CREATE TABLE mytable (id SERIAL, PRIMARY KEY(id))'
);
}
public
function
testQuoteAutoincPks
()
{
$this
->
conn
->
setAttribute
(
Doctrine
::
ATTR_QUOTE_IDENTIFIER
,
true
);
$name
=
'mytable'
;
$fields
=
array
(
'id'
=>
array
(
'type'
=>
'integer'
,
'unsigned'
=>
1
,
'autoincrement'
=>
true
));
$options
=
array
(
'primary'
=>
array
(
'id'
));
$this
->
export
->
createTable
(
$name
,
$fields
,
$options
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'CREATE TABLE "mytable" ("id" SERIAL, PRIMARY KEY("id"))'
);
$name
=
'mytable'
;
$fields
=
array
(
'name'
=>
array
(
'type'
=>
'char'
,
'length'
=>
10
),
'type'
=>
array
(
'type'
=>
'integer'
,
'length'
=>
3
));
$options
=
array
(
'primary'
=>
array
(
'name'
,
'type'
));
$this
->
export
->
createTable
(
$name
,
$fields
,
$options
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'CREATE TABLE "mytable" ("name" CHAR(10), "type" INT, PRIMARY KEY("name", "type"))'
);
$this
->
conn
->
setAttribute
(
Doctrine
::
ATTR_QUOTE_IDENTIFIER
,
false
);
}
public
function
testForeignKeyIdentifierQuoting
()
{
$this
->
conn
->
setAttribute
(
Doctrine
::
ATTR_QUOTE_IDENTIFIER
,
true
);
$name
=
'mytable'
;
$fields
=
array
(
'id'
=>
array
(
'type'
=>
'boolean'
,
'primary'
=>
true
),
'foreignKey'
=>
array
(
'type'
=>
'integer'
)
);
$options
=
array
(
'foreignKeys'
=>
array
(
array
(
'local'
=>
'foreignKey'
,
'foreign'
=>
'id'
,
'foreignTable'
=>
'sometable'
))
);
$sql
=
$this
->
export
->
createTableSql
(
$name
,
$fields
,
$options
);
$this
->
assertEqual
(
$sql
[
0
],
'CREATE TABLE "mytable" ("id" BOOLEAN, "foreignKey" INT)'
);
$this
->
assertEqual
(
$sql
[
1
],
'ALTER TABLE "mytable" ADD FOREIGN KEY ("foreignKey") REFERENCES "sometable"("id") NOT DEFERRABLE INITIALLY IMMEDIATE'
);
$this
->
conn
->
setAttribute
(
Doctrine
::
ATTR_QUOTE_IDENTIFIER
,
false
);
}
public
function
testCreateTableSupportsDefaultAttribute
()
{
$name
=
'mytable'
;
...
...
tests/Export/SqliteTestCase.php
View file @
01a3e063
...
...
@@ -103,6 +103,45 @@ class Doctrine_Export_Sqlite_TestCase extends Doctrine_UnitTestCase
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'CREATE TABLE sometable (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(4))'
);
}
public
function
testIdentifierQuoting
()
{
$this
->
conn
->
setAttribute
(
Doctrine
::
ATTR_QUOTE_IDENTIFIER
,
true
);
$fields
=
array
(
'id'
=>
array
(
'type'
=>
'integer'
,
'unsigned'
=>
1
,
'autoincrement'
=>
true
,
'unique'
=>
true
),
'name'
=>
array
(
'type'
=>
'string'
,
'length'
=>
4
),
);
$options
=
array
(
'primary'
=>
array
(
'id'
),
'indexes'
=>
array
(
'myindex'
=>
array
(
'fields'
=>
array
(
'id'
,
'name'
)))
);
$this
->
export
->
createTable
(
'sometable'
,
$fields
,
$options
);
//this was the old line, but it looks like the table is created first
//and then the index so i replaced it with the ones below
//$this->assertEqual($var, 'CREATE TABLE sometable (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(4), INDEX myindex (id, name))');
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'CREATE INDEX "myindex_idx" ON "sometable" ("id", "name")'
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'CREATE TABLE "sometable" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(4))'
);
$this
->
conn
->
setAttribute
(
Doctrine
::
ATTR_QUOTE_IDENTIFIER
,
false
);
}
public
function
testQuoteMultiplePks
()
{
$this
->
conn
->
setAttribute
(
Doctrine
::
ATTR_QUOTE_IDENTIFIER
,
true
);
$name
=
'mytable'
;
$fields
=
array
(
'name'
=>
array
(
'type'
=>
'char'
,
'length'
=>
10
),
'type'
=>
array
(
'type'
=>
'integer'
,
'length'
=>
3
));
$options
=
array
(
'primary'
=>
array
(
'name'
,
'type'
));
$this
->
export
->
createTable
(
$name
,
$fields
,
$options
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'CREATE TABLE "mytable" ("name" CHAR(10), "type" INTEGER, PRIMARY KEY("name", "type"))'
);
$this
->
conn
->
setAttribute
(
Doctrine
::
ATTR_QUOTE_IDENTIFIER
,
false
);
}
public
function
testUnknownIndexSortingAttributeThrowsException
()
{
$fields
=
array
(
'id'
=>
array
(
'sorting'
=>
'ASC'
),
...
...
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