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
ada2c5c5
Commit
ada2c5c5
authored
Jun 20, 2009
by
jwage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Work on datetime dbal type and date portability
parent
f2812766
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
196 additions
and
44 deletions
+196
-44
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+43
-0
MockPlatform.php
lib/Doctrine/DBAL/Platforms/MockPlatform.php
+0
-18
MsSqlPlatform.php
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
+8
-0
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+8
-0
OraclePlatform.php
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
+8
-0
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+8
-0
SqlitePlatform.php
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
+7
-1
BooleanType.php
lib/Doctrine/DBAL/Types/BooleanType.php
+1
-1
DateTimeType.php
lib/Doctrine/DBAL/Types/DateTimeType.php
+8
-4
DecimalType.php
lib/Doctrine/DBAL/Types/DecimalType.php
+1
-1
IntegerType.php
lib/Doctrine/DBAL/Types/IntegerType.php
+1
-1
SmallIntType.php
lib/Doctrine/DBAL/Types/SmallIntType.php
+1
-1
Type.php
lib/Doctrine/DBAL/Types/Type.php
+1
-1
AbstractHydrator.php
lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
+4
-3
StandardEntityPersister.php
lib/Doctrine/ORM/Persisters/StandardEntityPersister.php
+2
-1
CurrentDateFunction.php
lib/Doctrine/ORM/Query/AST/Functions/CurrentDateFunction.php
+4
-8
CurrentTimeFunction.php
lib/Doctrine/ORM/Query/AST/Functions/CurrentTimeFunction.php
+1
-2
AllTests.php
tests/Doctrine/Tests/DBAL/AllTests.php
+2
-0
MockPlatform.php
tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php
+18
-0
DateTimeTest.php
tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php
+37
-0
DateTimeModel.php
tests/Doctrine/Tests/Models/Generic/DateTimeModel.php
+20
-0
SelectSqlGenerationTest.php
tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
+6
-0
OrmFunctionalTestCase.php
tests/Doctrine/Tests/OrmFunctionalTestCase.php
+7
-2
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
ada2c5c5
...
...
@@ -1236,6 +1236,28 @@ abstract class AbstractPlatform
return
'SET NAMES '
.
$this
->
quote
(
$charset
);
}
/**
* Gets the SQL specific for the platform to get the current date.
*
* @return string
*/
public
function
getCurrentDateSql
()
{
return
'CURRENT_DATE'
;
}
/**
* Gets the SQL specific for the platform to get the current time.
*
* @return string
*/
public
function
getCurrentTimeSql
()
{
return
'CURRENT_TIME'
;
}
/**
* Get sql for transaction isolation level Connection constant
*
...
...
@@ -1360,6 +1382,18 @@ abstract class AbstractPlatform
throw
DoctrineException
::
updateMe
(
'Get charset field declaration not supported by this platform.'
);
}
/**
* Obtain DBMS specific SQL to be used to create datetime fields in
* statements like CREATE TABLE
*
* @param array $fieldDeclaration
* @return string
*/
public
function
getDateTimeTypeDeclarationSql
(
array
$fieldDeclaration
)
{
throw
DoctrineException
::
updateMe
(
'Get datetime type declaration not supported by this platform.'
);
}
/**
* Gets the default transaction isolation level of the platform.
*
...
...
@@ -1461,6 +1495,15 @@ abstract class AbstractPlatform
return
""
;
}
/**
* TODO: We need to get the specific format for each dbms and override this
* function for each platform
*/
public
function
getDateTimeFormatString
()
{
return
'Y-m-d H:i:s'
;
}
/**
* Gets the SQL snippet used to declare a VARCHAR column type.
*
...
...
lib/Doctrine/DBAL/Platforms/MockPlatform.php
deleted
100644 → 0
View file @
f2812766
<?php
namespace
Doctrine\DBAL\Platforms
;
class
MockPlatform
extends
AbstractPlatform
{
public
function
getNativeDeclaration
(
array
$field
)
{}
public
function
getPortableDeclaration
(
array
$field
)
{}
/**
* Get the platform name for this instance
*
* @return string
*/
public
function
getName
()
{
return
'mock'
;
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
View file @
ada2c5c5
...
...
@@ -400,6 +400,14 @@ class MsSqlPlatform extends AbstractPlatform
return
'CHARACTER SET '
.
$charset
;
}
/**
* @override
*/
public
function
getDateTimeTypeDeclarationSql
(
array
$fieldDeclaration
)
{
return
'CHAR('
.
strlen
(
'YYYY-MM-DD HH:MM:SS'
)
.
')'
;
}
/**
* Get the platform name for this instance
*
...
...
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
ada2c5c5
...
...
@@ -258,6 +258,14 @@ class MySqlPlatform extends AbstractPlatform
return
'CHARACTER SET '
.
$charset
;
}
/**
* @override
*/
public
function
getDateTimeTypeDeclarationSql
(
array
$fieldDeclaration
)
{
return
'DATETIME'
;
}
/**
* Obtain DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration to be used in statements like CREATE TABLE.
...
...
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
View file @
ada2c5c5
...
...
@@ -176,6 +176,14 @@ class OraclePlatform extends AbstractPlatform
return
'NUMBER(5)'
;
}
/**
* @override
*/
public
function
getDateTimeTypeDeclarationSql
(
array
$fieldDeclaration
)
{
return
'DATE'
;
}
/**
* @override
*/
...
...
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
ada2c5c5
...
...
@@ -690,6 +690,14 @@ class PostgreSqlPlatform extends AbstractPlatform
return
'SMALLINT'
;
}
/**
* @override
*/
public
function
getDateTimeTypeDeclarationSql
(
array
$fieldDeclaration
)
{
return
'TIMESTAMP without time zone'
;
}
/**
* @override
*/
...
...
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
View file @
ada2c5c5
...
...
@@ -229,13 +229,19 @@ class SqlitePlatform extends AbstractPlatform
return
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
public
function
getDateTimeTypeDeclarationSql
(
array
$fieldDeclaration
)
{
return
'DATETIME'
;
}
/** @override */
protected
function
_getCommonIntegerTypeDeclarationSql
(
array
$columnDef
)
{
$autoinc
=
!
empty
(
$columnDef
[
'autoincrement'
])
?
' AUTOINCREMENT'
:
''
;
$pk
=
!
empty
(
$columnDef
[
'primary'
])
&&
!
empty
(
$autoinc
)
?
' PRIMARY KEY'
:
''
;
return
"INTEGER"
.
$pk
.
$autoinc
;
return
'INTEGER'
.
$pk
.
$autoinc
;
}
/**
...
...
lib/Doctrine/DBAL/Types/BooleanType.php
View file @
ada2c5c5
...
...
@@ -24,7 +24,7 @@ class BooleanType extends Type
*
* @override
*/
public
function
convertToPHPValue
(
$value
)
public
function
convertToPHPValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
(
bool
)
$value
;
}
...
...
lib/Doctrine/DBAL/Types/DateTimeType.php
View file @
ada2c5c5
...
...
@@ -9,6 +9,11 @@ namespace Doctrine\DBAL\Types;
*/
class
DateTimeType
extends
Type
{
public
function
getName
()
{
return
'DateTime'
;
}
/**
* {@inheritdoc}
*/
...
...
@@ -24,8 +29,7 @@ class DateTimeType extends Type
*/
public
function
convertToDatabaseValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
//TODO: howto? dbms specific? delegate to platform?
return
$value
;
return
$value
->
format
(
$platform
->
getDateTimeFormatString
());
}
/**
...
...
@@ -33,8 +37,8 @@ class DateTimeType extends Type
*
* @override
*/
public
function
convertTo
ObjectValue
(
$value
)
public
function
convertTo
PHPValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
new
\DateTime
(
$value
);
return
\DateTime
::
createFromFormat
(
$platform
->
getDateTimeFormatString
(),
$value
);
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Types/DecimalType.php
View file @
ada2c5c5
...
...
@@ -19,7 +19,7 @@ class DecimalType extends Type
return
$platform
->
getDecimalTypeDeclarationSql
(
$fieldDeclaration
);
}
public
function
convertToPHPValue
(
$value
)
public
function
convertToPHPValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
(
double
)
$value
;
}
...
...
lib/Doctrine/DBAL/Types/IntegerType.php
View file @
ada2c5c5
...
...
@@ -18,7 +18,7 @@ class IntegerType extends Type
return
$platform
->
getIntegerTypeDeclarationSql
(
$fieldDeclaration
);
}
public
function
convertToPHPValue
(
$value
)
public
function
convertToPHPValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
(
int
)
$value
;
}
...
...
lib/Doctrine/DBAL/Types/SmallIntType.php
View file @
ada2c5c5
...
...
@@ -19,7 +19,7 @@ class SmallIntType
return
$platform
->
getSmallIntTypeDeclarationSql
(
$fieldDeclaration
);
}
public
function
convertToPHPValue
(
$value
)
public
function
convertToPHPValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
(
int
)
$value
;
}
...
...
lib/Doctrine/DBAL/Types/Type.php
View file @
ada2c5c5
...
...
@@ -45,7 +45,7 @@ abstract class Type
return
$value
;
}
public
function
convertToPHPValue
(
$value
)
public
function
convertToPHPValue
(
$value
,
\Doctrine\DBAL\Platforms\AbstractPlatform
$platform
)
{
return
$value
;
}
...
...
lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
View file @
ada2c5c5
...
...
@@ -61,6 +61,7 @@ abstract class AbstractHydrator
public
function
__construct
(
\Doctrine\ORM\EntityManager
$em
)
{
$this
->
_em
=
$em
;
$this
->
_platform
=
$em
->
getConnection
()
->
getDatabasePlatform
();
$this
->
_uow
=
$em
->
getUnitOfWork
();
}
...
...
@@ -213,7 +214,7 @@ abstract class AbstractHydrator
$id
[
$dqlAlias
]
.=
'|'
.
$value
;
}
$rowData
[
$dqlAlias
][
$cache
[
$key
][
'fieldName'
]]
=
$cache
[
$key
][
'type'
]
->
convertToPHPValue
(
$value
);
$rowData
[
$dqlAlias
][
$cache
[
$key
][
'fieldName'
]]
=
$cache
[
$key
][
'type'
]
->
convertToPHPValue
(
$value
,
$this
->
_platform
);
if
(
!
isset
(
$nonemptyComponents
[
$dqlAlias
])
&&
$value
!==
null
)
{
$nonemptyComponents
[
$dqlAlias
]
=
true
;
...
...
@@ -221,7 +222,7 @@ abstract class AbstractHydrator
/* TODO: Consider this instead of the above 4 lines. */
/*if ($value !== null) {
$rowData[$dqlAlias][$fieldName] = $cache[$key]['type']->convertToPHPValue($value);
$rowData[$dqlAlias][$fieldName] = $cache[$key]['type']->convertToPHPValue($value
, $this->_platform
);
}*/
}
...
...
@@ -268,7 +269,7 @@ abstract class AbstractHydrator
$rowData
[
/*$dqlAlias . '_' . */
$fieldName
]
=
$value
;
}
else
{
$dqlAlias
=
$cache
[
$key
][
'dqlAlias'
];
$rowData
[
$dqlAlias
.
'_'
.
$fieldName
]
=
$cache
[
$key
][
'type'
]
->
convertToPHPValue
(
$value
);
$rowData
[
$dqlAlias
.
'_'
.
$fieldName
]
=
$cache
[
$key
][
'type'
]
->
convertToPHPValue
(
$value
,
$this
->
_platform
);
}
}
...
...
lib/Doctrine/ORM/Persisters/StandardEntityPersister.php
View file @
ada2c5c5
...
...
@@ -90,6 +90,7 @@ class StandardEntityPersister
public
function
__construct
(
EntityManager
$em
,
ClassMetadata
$class
)
{
$this
->
_em
=
$em
;
$this
->
_platform
=
$em
->
getConnection
()
->
getDatabasePlatform
();
$this
->
_evm
=
$em
->
getEventManager
();
$this
->
_entityName
=
$class
->
name
;
$this
->
_conn
=
$em
->
getConnection
();
...
...
@@ -343,7 +344,7 @@ class StandardEntityPersister
foreach
(
$stmt
->
fetch
(
Connection
::
FETCH_ASSOC
)
as
$column
=>
$value
)
{
$fieldName
=
$this
->
_class
->
fieldNames
[
$column
];
$data
[
$fieldName
]
=
Type
::
getType
(
$this
->
_class
->
getTypeOfField
(
$fieldName
))
->
convertToPHPValue
(
$value
);
->
convertToPHPValue
(
$value
,
$this
->
_platform
);
}
$stmt
->
closeCursor
();
...
...
lib/Doctrine/ORM/Query/AST/Functions/CurrentDateFunction.php
View file @
ada2c5c5
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
namespace
Doctrine\ORM\Query\AST\Functions
;
...
...
@@ -18,8 +14,7 @@ class CurrentDateFunction extends FunctionNode
*/
public
function
getSql
(
\Doctrine\ORM\Query\SqlWalker
$sqlWalker
)
{
//TODO: Use platform to get SQL
return
'CURRENT_DATE'
;
return
$sqlWalker
->
getConnection
()
->
getDatabasePlatform
()
->
getCurrentDateSql
();
}
/**
...
...
@@ -29,6 +24,7 @@ class CurrentDateFunction extends FunctionNode
{
$lexer
=
$parser
->
getLexer
();
$parser
->
match
(
$lexer
->
lookahead
[
'value'
]);
$parser
->
match
(
'('
);
$parser
->
match
(
')'
);
}
}
}
\ No newline at end of file
lib/Doctrine/ORM/Query/AST/Functions/CurrentTimeFunction.php
View file @
ada2c5c5
...
...
@@ -18,8 +18,7 @@ class CurrentTimeFunction extends FunctionNode
*/
public
function
getSql
(
\Doctrine\ORM\Query\SqlWalker
$sqlWalker
)
{
//TODO: Use platform to get SQL
return
'CURRENT_TIME'
;
return
$sqlWalker
->
getConnection
()
->
getDatabasePlatform
()
->
getCurrentTimeSql
();
}
/**
...
...
tests/Doctrine/Tests/DBAL/AllTests.php
View file @
ada2c5c5
...
...
@@ -28,6 +28,8 @@ class AllTests
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Platforms\PostgreSqlPlatformTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Platforms\MsSqlPlatformTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\DateTimeTest'
);
$suite
->
addTest
(
Functional\AllTests
::
suite
());
return
$suite
;
...
...
tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php
0 → 100644
View file @
ada2c5c5
<?php
namespace
Doctrine\Tests\DBAL\Mocks
;
use
Doctrine\DBAL\Platforms
;
class
MockPlatform
extends
\Doctrine\DBAL\Platforms\AbstractPlatform
{
public
function
getIntegerTypeDeclarationSql
(
array
$columnDef
)
{}
public
function
getBigIntTypeDeclarationSql
(
array
$columnDef
)
{}
public
function
getSmallIntTypeDeclarationSql
(
array
$columnDef
)
{}
public
function
_getCommonIntegerTypeDeclarationSql
(
array
$columnDef
)
{}
public
function
getVarcharTypeDeclarationSql
(
array
$field
)
{}
public
function
getName
()
{
return
'mock'
;
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php
0 → 100644
View file @
ada2c5c5
<?php
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\DBAL\Mocks
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
DateTimeTest
extends
\Doctrine\Tests\DbalTestCase
{
protected
$_platform
,
$_type
;
protected
function
setUp
()
{
$this
->
_platform
=
new
\Doctrine\Tests\DBAL\Mocks\MockPlatform
();
$this
->
_type
=
Type
::
getType
(
'datetime'
);
}
public
function
testDateTimeConvertsToDatabaseValue
()
{
$this
->
assertTrue
(
is_string
(
$this
->
_type
->
convertToDatabaseValue
(
new
\DateTime
(),
$this
->
_platform
))
);
}
public
function
testDateTimeConvertsToPHPValue
()
{
// Birthday of jwage and also birthday of Doctrine. Send him a present ;)
$this
->
assertTrue
(
$this
->
_type
->
convertToPHPValue
(
'1985-09-01 00:00:00'
,
$this
->
_platform
)
instanceof
\DateTime
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/Models/Generic/DateTimeModel.php
0 → 100644
View file @
ada2c5c5
<?php
namespace
Doctrine\Tests\Models\Generic
;
/**
* @Entity
* @Table(name="date_time_model")
*/
class
DateTimeModel
{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
public
$id
;
/**
* @Column(type="datetime")
*/
public
$datetime
;
}
\ No newline at end of file
tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
View file @
ada2c5c5
...
...
@@ -281,6 +281,12 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
);
}
public
function
testCurrentDateFunction
()
{
$q
=
$this
->
_em
->
createQuery
(
'SELECT d.id FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.datetime > current_date()'
);
$this
->
assertEquals
(
'SELECT d0_.id AS id0 FROM date_time_model d0_ WHERE d0_.datetime > CURRENT_DATE'
,
$q
->
getSql
());
}
/*public function testExistsExpressionInWhereCorrelatedSubqueryAssocCondition()
{
$this->assertSqlGeneration(
...
...
tests/Doctrine/Tests/OrmFunctionalTestCase.php
View file @
ada2c5c5
...
...
@@ -44,7 +44,10 @@ class OrmFunctionalTestCase extends OrmTestCase
'Doctrine\Tests\Models\Company\CompanyEmployee'
,
'Doctrine\Tests\Models\Company\CompanyManager'
),
'ecommerce'
=>
array
()
'ecommerce'
=>
array
(),
'generic'
=>
array
(
'Doctrine\Tests\Models\Generic\DateTimeModel'
)
);
protected
function
useModelSet
(
$setName
)
...
...
@@ -72,7 +75,9 @@ class OrmFunctionalTestCase extends OrmTestCase
$conn
->
exec
(
'DELETE FROM company_employees'
);
$conn
->
exec
(
'DELETE FROM company_persons'
);
}
if
(
isset
(
$this
->
_usedModelSets
[
'generic'
]))
{
$conn
->
exec
(
'DELETE FROM date_time_model'
);
}
$this
->
_em
->
clear
();
}
...
...
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