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
16c4efcc
Commit
16c4efcc
authored
May 03, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] DBAL streamlining and starting to increase test coverage.
parent
80de5678
Changes
14
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
584 additions
and
397 deletions
+584
-397
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+87
-183
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+21
-60
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+40
-124
SqlitePlatform.php
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
+15
-10
VarcharType.php
lib/Doctrine/DBAL/Types/VarcharType.php
+1
-1
Configuration.php
lib/Doctrine/ORM/Configuration.php
+15
-5
PersistentCollection.php
lib/Doctrine/ORM/PersistentCollection.php
+3
-3
SqlWalker.php
lib/Doctrine/ORM/Query/SqlWalker.php
+6
-0
AllTests.php
tests/Doctrine/Tests/DBAL/AllTests.php
+2
-0
MySqlPlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
+170
-0
PostgreSqlPlatformTest.php
.../Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
+168
-0
SqlitePlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
+55
-8
DatabasePlatformMock.php
tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php
+1
-1
SingleTableInheritanceTest.php
...trine/Tests/ORM/Functional/SingleTableInheritanceTest.php
+0
-2
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
16c4efcc
This diff is collapsed.
Click to expand it.
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
16c4efcc
...
...
@@ -152,7 +152,7 @@ class MySqlPlatform extends AbstractPlatform
*
* @params array $field
*/
public
function
getVarcharDeclarationSql
(
array
$field
)
public
function
getVarchar
Type
DeclarationSql
(
array
$field
)
{
if
(
!
isset
(
$field
[
'length'
]))
{
if
(
array_key_exists
(
'default'
,
$field
))
{
...
...
@@ -215,8 +215,8 @@ class MySqlPlatform extends AbstractPlatform
*/
public
function
getNativeDeclaration
(
array
$field
)
{
if
(
!
isset
(
$field
[
'type'
]))
{
throw
\Doctrine\Common\
DoctrineException
::
updateMe
(
'Missing column type.'
);
/*
if ( ! isset($field['type'])) {
throw DoctrineException::updateMe('Missing column type.');
}
switch ($field['type']) {
...
...
@@ -229,7 +229,7 @@ class MySqlPlatform extends AbstractPlatform
case 'object':
case 'string':
case 'gzip':
return
$this
->
getVarcharDeclarationSql
(
$field
);
return $this->getVarchar
Type
DeclarationSql($field);
case 'clob':
return $this->getClobDeclarationSql($field);
case 'blob':
...
...
@@ -285,8 +285,8 @@ class MySqlPlatform extends AbstractPlatform
$length = !empty($field['length']) ? $field['length'] : 18;
$scale = !empty($field['scale']) ? $field['scale'] : $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
return 'DECIMAL('.$length.','.$scale.')';
}
throw
\Doctrine\Common\
DoctrineException
::
updateMe
(
'Unknown field type \''
.
$field
[
'type'
]
.
'\'.'
);
}
*/
throw
DoctrineException
::
updateMe
(
'Unknown field type \''
.
$field
[
'type'
]
.
'\'.'
);
}
/**
...
...
@@ -298,7 +298,7 @@ class MySqlPlatform extends AbstractPlatform
*/
public
function
getPortableDeclaration
(
array
$field
)
{
$dbType
=
strtolower
(
$field
[
'type'
]);
/*
$dbType = strtolower($field['type']);
$dbType = strtok($dbType, '(), ');
if ($dbType == 'national') {
$dbType = strtok('(), ');
...
...
@@ -448,7 +448,7 @@ class MySqlPlatform extends AbstractPlatform
return array('type' => $type, 'length' => $length, 'unsigned' => $unsigned, 'fixed' => $fixed);
} else {
return array('type' => $type, 'length' => $length, 'unsigned' => $unsigned, 'fixed' => $fixed, 'values' => $values);
}
}
*/
}
/**
...
...
@@ -602,7 +602,7 @@ class MySqlPlatform extends AbstractPlatform
if
(
empty
(
$fields
))
{
throw
DoctrineException
::
updateMe
(
'no fields specified for table "'
.
$name
.
'"'
);
}
$queryFields
=
$this
->
get
Field
DeclarationListSql
(
$fields
);
$queryFields
=
$this
->
get
Column
DeclarationListSql
(
$fields
);
// build indexes for all foreign key fields (needed in MySQL!!)
if
(
isset
(
$options
[
'foreignKeys'
]))
{
...
...
@@ -694,10 +694,10 @@ class MySqlPlatform extends AbstractPlatform
}
/**
*
alter an existing table
*
Gets the SQL to alter an existing table.
*
* @param string $name
name of the table that is intended to be changed.
* @param array $changes
a
ssociative array that contains the details of each type
* @param string $name
The
name of the table that is intended to be changed.
* @param array $changes
A
ssociative array that contains the details of each type
* of change that is intended to be performed. The types of
* changes that are currently supported are defined as follows:
*
...
...
@@ -815,7 +815,7 @@ class MySqlPlatform extends AbstractPlatform
if
(
$query
)
{
$query
.=
', '
;
}
$query
.=
'ADD '
.
$this
->
getDeclarationSql
(
$fieldName
,
$field
);
$query
.=
'ADD '
.
$this
->
get
Column
DeclarationSql
(
$fieldName
,
$field
);
}
}
...
...
@@ -849,7 +849,7 @@ class MySqlPlatform extends AbstractPlatform
}
$oldFieldName
=
$this
->
quoteIdentifier
(
$oldFieldName
,
true
);
$query
.=
'CHANGE '
.
$oldFieldName
.
' '
.
$this
->
getDeclarationSql
(
$fieldName
,
$field
[
'definition'
]);
.
$this
->
get
Column
DeclarationSql
(
$fieldName
,
$field
[
'definition'
]);
}
}
...
...
@@ -861,7 +861,7 @@ class MySqlPlatform extends AbstractPlatform
$field
=
$changes
[
'rename'
][
$renamedField
];
$renamedField
=
$this
->
quoteIdentifier
(
$renamedField
,
true
);
$query
.=
'CHANGE '
.
$renamedField
.
' '
.
$this
->
getDeclarationSql
(
$field
[
'name'
],
$field
[
'definition'
]);
.
$this
->
get
Column
DeclarationSql
(
$field
[
'name'
],
$field
[
'definition'
]);
}
}
...
...
@@ -912,7 +912,6 @@ class MySqlPlatform extends AbstractPlatform
public
function
getCreateIndexSql
(
$table
,
$name
,
array
$definition
)
{
$table
=
$table
;
$name
=
$this
->
formatter
->
getIndexName
(
$name
);
$name
=
$this
->
quoteIdentifier
(
$name
);
$type
=
''
;
if
(
isset
(
$definition
[
'type'
]))
{
...
...
@@ -968,24 +967,12 @@ class MySqlPlatform extends AbstractPlatform
return
'BIGINT'
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
/*public function getTinyIntTypeDeclarationSql(array $field)
{
return 'TINYINT' . $this->_getCommonIntegerTypeDeclarationSql($field);
}*/
/** @override */
public
function
getSmallIntTypeDeclarationSql
(
array
$field
)
{
return
'SMALLINT'
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
/*public function getMediumIntTypeDeclarationSql(array $field)
{
return 'MEDIUMINT' . $this->_getCommonIntegerTypeDeclarationSql($field);
}*/
/** @override */
protected
function
_getCommonIntegerTypeDeclarationSql
(
array
$columnDef
)
{
...
...
@@ -998,27 +985,6 @@ class MySqlPlatform extends AbstractPlatform
return
$unsigned
.
$autoinc
;
}
/**
* Obtain DBMS specific SQL code portion needed to set a default value
* declaration to be used in statements like CREATE TABLE.
*
* @param array $field field definition array
* @return string DBMS specific SQL code portion needed to set a default value
* @override
*/
public
function
getDefaultFieldDeclarationSql
(
$field
)
{
$default
=
empty
(
$field
[
'notnull'
])
?
' DEFAULT NULL'
:
''
;
if
(
isset
(
$field
[
'default'
])
&&
(
!
isset
(
$field
[
'length'
])
||
$field
[
'length'
]
<=
255
))
{
if
(
$field
[
'default'
]
===
''
)
{
$field
[
'default'
]
=
null
;
}
$default
=
' DEFAULT '
.
$this
->
quote
(
$field
[
'default'
],
$field
[
'type'
]);
}
return
$default
;
}
/**
* Obtain DBMS specific SQL code portion needed to set an index
* declaration to be used in statements like CREATE TABLE.
...
...
@@ -1097,7 +1063,6 @@ class MySqlPlatform extends AbstractPlatform
}
/**
* getAdvancedForeignKeyOptions
* Return the FOREIGN KEY query section dealing with non-standard options
* as MATCH, INITIALLY DEFERRED, ON UPDATE, ...
*
...
...
@@ -1121,32 +1086,28 @@ class MySqlPlatform extends AbstractPlatform
}
/**
*
drop existing index
*
Gets the SQL to drop an index of a table.
*
* @param string $table name of table that should be used in method
* @param string $name name of the index to be dropped
* @return void
* @override
*/
public
function
getDropIndexSql
(
$table
,
$name
)
{
$table
=
$this
->
quoteIdentifier
(
$table
,
tru
e
);
$name
=
$this
->
quoteIdentifier
(
$this
->
formatter
->
getIndexName
(
$name
),
tru
e
);
$table
=
$this
->
quoteIdentifier
(
$tabl
e
);
$name
=
$this
->
quoteIdentifier
(
$nam
e
);
return
'DROP INDEX '
.
$name
.
' ON '
.
$table
;
}
/**
*
dropTable
*
Gets the SQL to drop a table.
*
* @param string $table name of table that should be dropped from the database
* @throws PDOException
* @return void
* @param string $table The name of table to drop.
* @override
*/
public
function
getDropTableSql
(
$table
)
{
$table
=
$this
->
quoteIdentifier
(
$table
,
true
);
return
'DROP TABLE '
.
$table
;
return
'DROP TABLE '
.
$this
->
quoteIdentifier
(
$table
);
}
/**
...
...
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
16c4efcc
This diff is collapsed.
Click to expand it.
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
View file @
16c4efcc
...
...
@@ -26,6 +26,7 @@ namespace Doctrine\DBAL\Platforms;
* database platform.
*
* @since 2.0
* @author Roman Borschel <roman@code-factory.org>
*/
class
SqlitePlatform
extends
AbstractPlatform
{
...
...
@@ -73,18 +74,22 @@ class SqlitePlatform extends AbstractPlatform
{
return
strpos
(
$str
,
$substr
);
}
public
static
function
sha1Impl
(
$str
)
{
return
sha1
(
$str
);
}
public
static
function
ltrimImpl
(
$str
)
{
return
ltrim
(
$str
);
}
public
static
function
rtrimImpl
(
$str
)
{
return
rtrim
(
$str
);
}
public
static
function
trimImpl
(
$str
)
{
return
trim
(
$str
);
...
...
@@ -193,7 +198,7 @@ class SqlitePlatform extends AbstractPlatform
*/
public
function
getNativeDeclaration
(
array
$field
)
{
if
(
!
isset
(
$field
[
'type'
]))
{
/*
if ( ! isset($field['type'])) {
throw DoctrineException::updateMe('Missing column type.');
}
switch ($field['type']) {
...
...
@@ -253,7 +258,7 @@ class SqlitePlatform extends AbstractPlatform
$length = !empty($field['length']) ? $field['length'] : 18;
$scale = !empty($field['scale']) ? $field['scale'] : $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
return 'DECIMAL('.$length.','.$scale.')';
}
}
*/
throw
DoctrineException
::
updateMe
(
'Unknown field type \''
.
$field
[
'type'
]
.
'\'.'
);
}
...
...
@@ -266,7 +271,7 @@ class SqlitePlatform extends AbstractPlatform
*/
public
function
getPortableDeclaration
(
array
$field
)
{
$dbType
=
strtolower
(
$field
[
'type'
]);
/*
$dbType = strtolower($field['type']);
$length = (isset($field['length'])) ? $field['length'] : null;
$unsigned = (isset($field['unsigned'])) ? $field['unsigned'] : null;
$fixed = null;
...
...
@@ -377,7 +382,7 @@ class SqlitePlatform extends AbstractPlatform
return array('type' => $type,
'length' => $length,
'unsigned' => $unsigned,
'fixed'
=>
$fixed
);
'fixed' => $fixed);
*/
}
/**
...
...
@@ -389,11 +394,11 @@ class SqlitePlatform extends AbstractPlatform
protected
function
_getTransactionIsolationLevelSql
(
$level
)
{
switch
(
$level
)
{
case
Doctrine_DBAL_
Connection
::
TRANSACTION_READ_UNCOMMITTED
:
case
\Doctrine\DBAL\
Connection
::
TRANSACTION_READ_UNCOMMITTED
:
return
0
;
case
Doctrine_DBAL_
Connection
::
TRANSACTION_READ_COMMITTED
:
case
Doctrine_DBAL_
Connection
::
TRANSACTION_REPEATABLE_READ
:
case
Doctrine_DBAL_
Connection
::
TRANSACTION_SERIALIZABLE
:
case
\Doctrine\DBAL\
Connection
::
TRANSACTION_READ_COMMITTED
:
case
\Doctrine\DBAL\
Connection
::
TRANSACTION_REPEATABLE_READ
:
case
\Doctrine\DBAL\
Connection
::
TRANSACTION_SERIALIZABLE
:
return
1
;
default
:
return
parent
::
_getTransactionIsolationLevelSql
(
$level
);
...
...
@@ -493,7 +498,7 @@ class SqlitePlatform extends AbstractPlatform
if
(
empty
(
$fields
))
{
throw
ConnectionException
::
noFieldsSpecifiedForTable
(
$name
);
}
$queryFields
=
$this
->
get
Field
DeclarationListSql
(
$fields
);
$queryFields
=
$this
->
get
Column
DeclarationListSql
(
$fields
);
$autoinc
=
false
;
foreach
(
$fields
as
$field
)
{
...
...
@@ -535,7 +540,7 @@ class SqlitePlatform extends AbstractPlatform
/**
* {@inheritdoc}
*/
public
function
getVarcharDeclarationSql
(
array
$field
)
public
function
getVarchar
Type
DeclarationSql
(
array
$field
)
{
if
(
!
isset
(
$field
[
'length'
]))
{
if
(
array_key_exists
(
'default'
,
$field
))
{
...
...
lib/Doctrine/DBAL/Types/VarcharType.php
View file @
16c4efcc
...
...
@@ -12,7 +12,7 @@ class VarcharType extends Type
/** @override */
public
function
getSqlDeclaration
(
array
$fieldDeclaration
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
$platform
->
getVarcharDeclarationSql
(
$fieldDeclaration
);
return
$platform
->
getVarchar
Type
DeclarationSql
(
$fieldDeclaration
);
}
/** @override */
...
...
lib/Doctrine/ORM/Configuration.php
View file @
16c4efcc
...
...
@@ -16,7 +16,7 @@
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.
phpdoctrine
.org>.
* <http://www.
doctrine-project
.org>.
*/
namespace
Doctrine\ORM
;
...
...
@@ -27,11 +27,10 @@ use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
* Configuration container for all configuration options of Doctrine.
* It combines all configuration options from DBAL & ORM.
*
* INTERNAL: When adding a new configuration option just write a getter/setter
* pair and add the option to the _attributes array with a proper default value.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
* @internal When adding a new configuration option just write a getter/setter
* pair and add the option to the _attributes array with a proper default value.
*/
class
Configuration
extends
\Doctrine\DBAL\Configuration
{
...
...
@@ -44,10 +43,21 @@ class Configuration extends \Doctrine\DBAL\Configuration
'resultCacheImpl'
=>
null
,
'queryCacheImpl'
=>
null
,
'metadataCacheImpl'
=>
null
,
'metadataDriverImpl'
=>
new
AnnotationDriver
()
'metadataDriverImpl'
=>
new
AnnotationDriver
(),
'dqlClassAliasMap'
=>
array
()
));
}
public
function
getDqlClassAliasMap
()
{
return
$this
->
_attributes
[
'dqlClassAliasMap'
];
}
public
function
setDqlClassAliasMap
(
array
$map
)
{
$this
->
_attributes
[
'dqlClassAliasMap'
]
=
$map
;
}
public
function
setMetadataDriverImpl
(
$driverImpl
)
{
$this
->
_attributes
[
'metadataDriverImpl'
]
=
$driverImpl
;
...
...
lib/Doctrine/ORM/PersistentCollection.php
View file @
16c4efcc
...
...
@@ -75,7 +75,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
private
$_association
;
/**
* The name of the field that is used for collection
key mapp
ing.
* The name of the field that is used for collection
index
ing.
*
* @var string
*/
...
...
@@ -90,7 +90,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
/**
* The name of the field on the target entities that points to the owner
* of the collection. This is only set if the association is bidirectional.
* of the collection. This is only set if the association is bi
-
directional.
*
* @var string
*/
...
...
@@ -102,7 +102,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
* @var boolean
* @see setHydrationFlag()
*/
private
$_hydrationFlag
;
private
$_hydrationFlag
=
false
;
/**
* The class descriptor of the owning entity.
...
...
lib/Doctrine/ORM/Query/SqlWalker.php
View file @
16c4efcc
...
...
@@ -661,6 +661,12 @@ class SqlWalker
return
$sql
;
}
/**
* Generates a discriminator column SQL condition for the class with the given DQL alias.
*
* @param string $dqlAlias
* @return string
*/
private
function
_generateDiscriminatorColumnConditionSql
(
$dqlAlias
)
{
$sql
=
''
;
...
...
tests/Doctrine/Tests/DBAL/AllTests.php
View file @
16c4efcc
...
...
@@ -23,6 +23,8 @@ class AllTests
$suite
=
new
\Doctrine\Tests\DbalTestSuite
(
'Doctrine DBAL'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Platforms\SqlitePlatformTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Platforms\MySqlPlatformTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Platforms\PostgreSqlPlatformTest'
);
return
$suite
;
}
...
...
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
0 → 100644
View file @
16c4efcc
<?php
namespace
Doctrine\Tests\DBAL\Platforms
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Types\Type
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
MySqlPlatformTest
extends
\Doctrine\Tests\DbalTestCase
{
private
$_platform
;
public
function
setUp
()
{
$this
->
_platform
=
new
MySqlPlatform
;
}
public
function
testCreateTableSql
()
{
$columns
=
array
(
'id'
=>
array
(
'type'
=>
Type
::
getType
(
'integer'
),
'autoincrement'
=>
true
,
'primary'
=>
true
,
'notnull'
=>
true
),
'test'
=>
array
(
'type'
=>
Type
::
getType
(
'varchar'
),
'length'
=>
255
,
'notnull'
=>
true
)
);
$options
=
array
(
'primary'
=>
array
(
'id'
)
);
$sql
=
$this
->
_platform
->
getCreateTableSql
(
'test'
,
$columns
,
$options
);
$this
->
assertEquals
(
'CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) NOT NULL, PRIMARY KEY(id))'
,
$sql
[
0
]);
}
public
function
testAlterTableSql
()
{
$changes
=
array
(
'name'
=>
'userlist'
,
'add'
=>
array
(
'quota'
=>
array
(
'type'
=>
Type
::
getType
(
'integer'
),
'unsigned'
=>
1
)
));
$this
->
assertEquals
(
'ALTER TABLE mytable RENAME TO userlist, ADD quota INT UNSIGNED DEFAULT NULL'
,
$this
->
_platform
->
getAlterTableSql
(
'mytable'
,
$changes
)
);
}
public
function
testCreateIndexSql
()
{
$indexDef
=
array
(
'fields'
=>
array
(
'user_name'
=>
array
(
'sorting'
=>
'ASC'
,
'length'
=>
10
),
'last_login'
=>
array
()
)
);
$this
->
assertEquals
(
'CREATE INDEX my_idx ON mytable (user_name(10) ASC, last_login)'
,
$this
->
_platform
->
getCreateIndexSql
(
'mytable'
,
'my_idx'
,
$indexDef
)
);
}
public
function
testSqlSnippets
()
{
$this
->
assertEquals
(
'RLIKE'
,
$this
->
_platform
->
getRegexpExpression
());
$this
->
assertEquals
(
'`'
,
$this
->
_platform
->
getIdentifierQuoteCharacter
());
$this
->
assertEquals
(
'RAND()'
,
$this
->
_platform
->
getRandomExpression
());
$this
->
assertEquals
(
'CONCAT(column1, column2, column3)'
,
$this
->
_platform
->
getConcatExpression
(
'column1'
,
'column2'
,
'column3'
));
$this
->
assertEquals
(
'CHARACTER SET utf8'
,
$this
->
_platform
->
getCharsetFieldDeclaration
(
'utf8'
));
$this
->
assertEquals
(
'SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED'
,
$this
->
_platform
->
getSetTransactionIsolationSql
(
\Doctrine\DBAL\Connection
::
TRANSACTION_READ_UNCOMMITTED
)
);
$this
->
assertEquals
(
'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED'
,
$this
->
_platform
->
getSetTransactionIsolationSql
(
\Doctrine\DBAL\Connection
::
TRANSACTION_READ_COMMITTED
)
);
$this
->
assertEquals
(
'SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ'
,
$this
->
_platform
->
getSetTransactionIsolationSql
(
\Doctrine\DBAL\Connection
::
TRANSACTION_REPEATABLE_READ
)
);
$this
->
assertEquals
(
'SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE'
,
$this
->
_platform
->
getSetTransactionIsolationSql
(
\Doctrine\DBAL\Connection
::
TRANSACTION_SERIALIZABLE
)
);
}
public
function
testDDLSnippets
()
{
$this
->
assertEquals
(
'SHOW DATABASES'
,
$this
->
_platform
->
getShowDatabasesSql
());
$this
->
assertEquals
(
'CREATE DATABASE foobar'
,
$this
->
_platform
->
getCreateDatabaseSql
(
'foobar'
));
$this
->
assertEquals
(
'DROP DATABASE foobar'
,
$this
->
_platform
->
getDropDatabaseSql
(
'foobar'
));
$this
->
assertEquals
(
'DROP TABLE foobar'
,
$this
->
_platform
->
getDropTableSql
(
'foobar'
));
}
public
function
testTypeDeclarationSql
()
{
$this
->
assertEquals
(
'INT'
,
$this
->
_platform
->
getIntegerTypeDeclarationSql
(
array
())
);
$this
->
assertEquals
(
'INT AUTO_INCREMENT'
,
$this
->
_platform
->
getIntegerTypeDeclarationSql
(
array
(
'autoincrement'
=>
true
)
));
$this
->
assertEquals
(
'INT AUTO_INCREMENT'
,
$this
->
_platform
->
getIntegerTypeDeclarationSql
(
array
(
'autoincrement'
=>
true
,
'primary'
=>
true
)
));
$this
->
assertEquals
(
'CHAR(10)'
,
$this
->
_platform
->
getVarcharTypeDeclarationSql
(
array
(
'length'
=>
10
,
'fixed'
=>
true
)
));
$this
->
assertEquals
(
'VARCHAR(50)'
,
$this
->
_platform
->
getVarcharTypeDeclarationSql
(
array
(
'length'
=>
50
))
);
$this
->
assertEquals
(
'TEXT'
,
$this
->
_platform
->
getVarcharTypeDeclarationSql
(
array
())
);
}
public
function
testPreferences
()
{
$this
->
assertTrue
(
$this
->
_platform
->
prefersIdentityColumns
());
$this
->
assertTrue
(
$this
->
_platform
->
supportsIdentityColumns
());
$this
->
assertFalse
(
$this
->
_platform
->
supportsSavepoints
());
}
/*
public function testGetCreateConstraintSql()
{
$sql = $this->_platform->getCreateConstraintSql('test', 'constraint_name', array('fields' => array('test' => array())));
$this->assertEquals($sql, 'ALTER TABLE test ADD CONSTRAINT constraint_name (test)');
}
public function testGetCreateIndexSql()
{
$sql = $this->_platform->getCreateIndexSql('test', 'index_name', array('type' => 'unique', 'fields' => array('test', 'test2')));
$this->assertEquals($sql, 'CREATE UNIQUE INDEX index_name ON test (test, test2)');
}
public function testGetCreateForeignKeySql()
{
$sql = $this->_platform->getCreateForeignKeySql('test', array('foreignTable' => 'other_table', 'local' => 'fk_name_id', 'foreign' => 'id'));
$this->assertEquals($sql, 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table(id)');
}
*/
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
0 → 100644
View file @
16c4efcc
<?php
namespace
Doctrine\Tests\DBAL\Platforms
;
use
Doctrine\DBAL\Platforms\PostgreSqlPlatform
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Connection
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
PostgreSqlPlatformTest
extends
\Doctrine\Tests\DbalTestCase
{
private
$_platform
;
public
function
setUp
()
{
$this
->
_platform
=
new
PostgreSqlPlatform
;
}
public
function
testCreateTableSql
()
{
$columns
=
array
(
'id'
=>
array
(
'type'
=>
Type
::
getType
(
'integer'
),
'primary'
=>
true
,
'notnull'
=>
true
),
'test'
=>
array
(
'type'
=>
Type
::
getType
(
'varchar'
),
'length'
=>
255
,
'notnull'
=>
true
)
);
$options
=
array
(
'primary'
=>
array
(
'id'
)
);
$sql
=
$this
->
_platform
->
getCreateTableSql
(
'test'
,
$columns
,
$options
);
$this
->
assertEquals
(
'CREATE TABLE test (id INT NOT NULL, test VARCHAR(255) NOT NULL, PRIMARY KEY(id))'
,
$sql
[
0
]);
}
public
function
testAlterTableSql
()
{
$changes
=
array
(
'name'
=>
'userlist'
,
'add'
=>
array
(
'quota'
=>
array
(
'type'
=>
Type
::
getType
(
'integer'
)
)
));
$sql
=
$this
->
_platform
->
getAlterTableSql
(
'mytable'
,
$changes
);
$this
->
assertEquals
(
'ALTER TABLE mytable ADD quota INT DEFAULT NULL'
,
$sql
[
0
]
);
$this
->
assertEquals
(
'ALTER TABLE mytable RENAME TO userlist'
,
$sql
[
1
]
);
}
public
function
testCreateIndexSql
()
{
$indexDef
=
array
(
'fields'
=>
array
(
'user_name'
,
'last_login'
)
);
$sql
=
$this
->
_platform
->
getCreateIndexSql
(
'mytable'
,
'my_idx'
,
$indexDef
);
$this
->
assertEquals
(
'CREATE INDEX my_idx ON mytable (user_name, last_login)'
,
$sql
);
}
public
function
testSqlSnippets
()
{
$this
->
assertEquals
(
'SIMILAR TO'
,
$this
->
_platform
->
getRegexpExpression
());
$this
->
assertEquals
(
'"'
,
$this
->
_platform
->
getIdentifierQuoteCharacter
());
$this
->
assertEquals
(
'RANDOM()'
,
$this
->
_platform
->
getRandomExpression
());
$this
->
assertEquals
(
'column1 || column2 || column3'
,
$this
->
_platform
->
getConcatExpression
(
'column1'
,
'column2'
,
'column3'
));
$this
->
assertEquals
(
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ UNCOMMITTED'
,
$this
->
_platform
->
getSetTransactionIsolationSql
(
Connection
::
TRANSACTION_READ_UNCOMMITTED
)
);
$this
->
assertEquals
(
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED'
,
$this
->
_platform
->
getSetTransactionIsolationSql
(
Connection
::
TRANSACTION_READ_COMMITTED
)
);
$this
->
assertEquals
(
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL REPEATABLE READ'
,
$this
->
_platform
->
getSetTransactionIsolationSql
(
Connection
::
TRANSACTION_REPEATABLE_READ
)
);
$this
->
assertEquals
(
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE'
,
$this
->
_platform
->
getSetTransactionIsolationSql
(
Connection
::
TRANSACTION_SERIALIZABLE
)
);
}
public
function
testDDLSnippets
()
{
$this
->
assertEquals
(
'CREATE DATABASE foobar'
,
$this
->
_platform
->
getCreateDatabaseSql
(
'foobar'
));
$this
->
assertEquals
(
'DROP DATABASE foobar'
,
$this
->
_platform
->
getDropDatabaseSql
(
'foobar'
));
$this
->
assertEquals
(
'DROP TABLE foobar'
,
$this
->
_platform
->
getDropTableSql
(
'foobar'
));
}
public
function
testTypeDeclarationSql
()
{
$this
->
assertEquals
(
'INT'
,
$this
->
_platform
->
getIntegerTypeDeclarationSql
(
array
())
);
$this
->
assertEquals
(
'SERIAL'
,
$this
->
_platform
->
getIntegerTypeDeclarationSql
(
array
(
'autoincrement'
=>
true
)
));
$this
->
assertEquals
(
'SERIAL'
,
$this
->
_platform
->
getIntegerTypeDeclarationSql
(
array
(
'autoincrement'
=>
true
,
'primary'
=>
true
)
));
$this
->
assertEquals
(
'CHAR(10)'
,
$this
->
_platform
->
getVarcharTypeDeclarationSql
(
array
(
'length'
=>
10
,
'fixed'
=>
true
)
));
$this
->
assertEquals
(
'VARCHAR(50)'
,
$this
->
_platform
->
getVarcharTypeDeclarationSql
(
array
(
'length'
=>
50
))
);
$this
->
assertEquals
(
'TEXT'
,
$this
->
_platform
->
getVarcharTypeDeclarationSql
(
array
())
);
}
public
function
testSequenceSQL
()
{
$this
->
assertEquals
(
'CREATE SEQUENCE myseq INCREMENT BY 20 START 1'
,
$this
->
_platform
->
getCreateSequenceSql
(
'myseq'
,
1
,
20
)
);
$this
->
assertEquals
(
'DROP SEQUENCE myseq'
,
$this
->
_platform
->
getDropSequenceSql
(
'myseq'
)
);
$this
->
assertEquals
(
"SELECT NEXTVAL('myseq')"
,
$this
->
_platform
->
getSequenceNextValSql
(
'myseq'
)
);
}
public
function
testPreferences
()
{
$this
->
assertFalse
(
$this
->
_platform
->
prefersIdentityColumns
());
$this
->
assertTrue
(
$this
->
_platform
->
prefersSequences
());
$this
->
assertTrue
(
$this
->
_platform
->
supportsIdentityColumns
());
$this
->
assertTrue
(
$this
->
_platform
->
supportsSavepoints
());
$this
->
assertTrue
(
$this
->
_platform
->
supportsSequences
());
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
View file @
16c4efcc
...
...
@@ -20,7 +20,9 @@ class SqlitePlatformTest extends \Doctrine\Tests\DbalTestCase
$columns
=
array
(
'id'
=>
array
(
'type'
=>
new
\Doctrine\DBAL\Types\IntegerType
,
'autoincrement'
=>
true
'autoincrement'
=>
true
,
'primary'
=>
true
,
'notnull'
=>
true
),
'test'
=>
array
(
'type'
=>
new
\Doctrine\DBAL\Types\VarcharType
,
...
...
@@ -28,29 +30,74 @@ class SqlitePlatformTest extends \Doctrine\Tests\DbalTestCase
)
);
$options
=
array
(
'primary'
=>
array
(
'id'
)
);
$options
=
array
();
$sql
=
$this
->
_platform
->
getCreateTableSql
(
'test'
,
$columns
,
$options
);
$this
->
assertEquals
(
$sql
[
0
],
'CREATE TABLE test (id INTEGER AUTOINCREMENT, test VARCHAR(255))'
);
$this
->
assertEquals
(
'CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL)'
,
$sql
[
0
]
);
}
public
function
testGetCreateConstraintSql
()
{
$sql
=
$this
->
_platform
->
getCreateConstraintSql
(
'test'
,
'constraint_name'
,
array
(
'fields'
=>
array
(
'test'
=>
array
())));
$this
->
assertEquals
(
$sql
,
'ALTER TABLE test ADD CONSTRAINT constraint_name (test)'
);
$this
->
assertEquals
(
'ALTER TABLE test ADD CONSTRAINT constraint_name (test)'
,
$sql
);
}
public
function
testGetCreateIndexSql
()
{
$sql
=
$this
->
_platform
->
getCreateIndexSql
(
'test'
,
'index_name'
,
array
(
'type'
=>
'unique'
,
'fields'
=>
array
(
'test'
,
'test2'
)));
$this
->
assertEquals
(
$sql
,
'CREATE UNIQUE INDEX index_name ON test (test, test2)'
);
$this
->
assertEquals
(
'CREATE UNIQUE INDEX index_name ON test (test, test2)'
,
$sql
);
}
public
function
testGetCreateForeignKeySql
()
{
$sql
=
$this
->
_platform
->
getCreateForeignKeySql
(
'test'
,
array
(
'foreignTable'
=>
'other_table'
,
'local'
=>
'fk_name_id'
,
'foreign'
=>
'id'
));
$this
->
assertEquals
(
$sql
,
'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table(id)'
);
$this
->
assertEquals
(
'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table(id)'
,
$sql
);
}
public
function
testExpressionsSql
()
{
$this
->
assertEquals
(
'RLIKE'
,
$this
->
_platform
->
getRegexpExpression
());
$this
->
assertEquals
(
'SUBSTR(column, 5, LENGTH(column))'
,
$this
->
_platform
->
getSubstringExpression
(
'column'
,
5
));
$this
->
assertEquals
(
'SUBSTR(column, 0, 5)'
,
$this
->
_platform
->
getSubstringExpression
(
'column'
,
0
,
5
));
$this
->
assertEquals
(
'PRAGMA read_uncommitted = 0'
,
$this
->
_platform
->
getSetTransactionIsolationSql
(
\Doctrine\DBAL\Connection
::
TRANSACTION_READ_UNCOMMITTED
));
$this
->
assertEquals
(
'PRAGMA read_uncommitted = 1'
,
$this
->
_platform
->
getSetTransactionIsolationSql
(
\Doctrine\DBAL\Connection
::
TRANSACTION_READ_COMMITTED
));
$this
->
assertEquals
(
'PRAGMA read_uncommitted = 1'
,
$this
->
_platform
->
getSetTransactionIsolationSql
(
\Doctrine\DBAL\Connection
::
TRANSACTION_REPEATABLE_READ
));
$this
->
assertEquals
(
'PRAGMA read_uncommitted = 1'
,
$this
->
_platform
->
getSetTransactionIsolationSql
(
\Doctrine\DBAL\Connection
::
TRANSACTION_SERIALIZABLE
));
}
public
function
testPreferences
()
{
$this
->
assertTrue
(
$this
->
_platform
->
prefersIdentityColumns
());
}
public
function
testTypeDeclarationSql
()
{
$this
->
assertEquals
(
'INTEGER'
,
$this
->
_platform
->
getIntegerTypeDeclarationSql
(
array
())
);
$this
->
assertEquals
(
'INTEGER AUTOINCREMENT'
,
$this
->
_platform
->
getIntegerTypeDeclarationSql
(
array
(
'autoincrement'
=>
true
)
));
$this
->
assertEquals
(
'INTEGER PRIMARY KEY AUTOINCREMENT'
,
$this
->
_platform
->
getIntegerTypeDeclarationSql
(
array
(
'autoincrement'
=>
true
,
'primary'
=>
true
)
));
$this
->
assertEquals
(
'CHAR(10)'
,
$this
->
_platform
->
getVarcharTypeDeclarationSql
(
array
(
'length'
=>
10
,
'fixed'
=>
true
)
));
$this
->
assertEquals
(
'VARCHAR(50)'
,
$this
->
_platform
->
getVarcharTypeDeclarationSql
(
array
(
'length'
=>
50
))
);
$this
->
assertEquals
(
'TEXT'
,
$this
->
_platform
->
getVarcharTypeDeclarationSql
(
array
())
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php
View file @
16c4efcc
...
...
@@ -53,7 +53,7 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform
protected
function
_getCommonIntegerTypeDeclarationSql
(
array
$columnDef
)
{}
/** @override */
public
function
getVarcharDeclarationSql
(
array
$field
)
{}
public
function
getVarchar
Type
DeclarationSql
(
array
$field
)
{}
/* MOCK API */
...
...
tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php
View file @
16c4efcc
...
...
@@ -22,7 +22,6 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
public
function
testCRUD
()
{
$parent
=
new
ParentEntity
;
$parent
->
setData
(
'foobar'
);
...
...
@@ -31,7 +30,6 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$child
=
new
ChildEntity
;
$child
->
setData
(
'thedata'
);
$child
->
setNumber
(
1234
);
//$child->setRelatedEntity($relatedEntity);
$this
->
_em
->
save
(
$child
);
...
...
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