DDC-110: Oracle DateTime Type support mismatch of DateTime Format and Database value lets conversion fail #136

Closed
opened 2026-01-22 12:28:17 +01:00 by admin · 14 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 4, 2009).

Originally assigned to: @jwage on GitHub.

Jira issue originally created by user @beberlei:

I get a fatal error on the Oracle Testsuite:

Fatal error: Call to a member function format() on a non-object in /home/benny/code/php/wsnetbeans/Doctrine/trunk/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php on line 140
Originally created by @doctrinebot on GitHub (Nov 4, 2009). Originally assigned to: @jwage on GitHub. Jira issue originally created by user @beberlei: I get a fatal error on the Oracle Testsuite: ``` Fatal error: Call to a member function format() on a non-object in /home/benny/code/php/wsnetbeans/Doctrine/trunk/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php on line 140 ```
admin added the Bug label 2026-01-22 12:28:17 +01:00
admin closed this issue 2026-01-22 12:28:18 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 4, 2009):

@doctrinebot commented on GitHub (Nov 4, 2009): - relates to [DDC-294: Implement "postConnect" Event in Doctrine\DBAL\Connection](http://www.doctrine-project.org/jira/browse/DDC-294)
Author
Owner

@doctrinebot commented on GitHub (Nov 4, 2009):

Comment created by @beberlei:

Simple Fix would be:

$this->assertType('DateTime', $test->version, 'The Version field using optimistic timestamp strategy should be DateTime.');

However i think Oracle and Date fields doesn't work correctly, I'll investigate more.

@doctrinebot commented on GitHub (Nov 4, 2009): Comment created by @beberlei: Simple Fix would be: ``` $this->assertType('DateTime', $test->version, 'The Version field using optimistic timestamp strategy should be DateTime.'); ``` However i think Oracle and Date fields doesn't work correctly, I'll investigate more.
Author
Owner

@doctrinebot commented on GitHub (Nov 4, 2009):

Comment created by @beberlei:

Correct, DateTime Type support in Oracle is broken:

in convertToPHPValue i get as value: 04-NOV09 11.35.15 AM +01.00
as Platform DateTime Format I get: Y-m-d H:i:sP

This combination returns false in DateTime::createFromFormat()

@doctrinebot commented on GitHub (Nov 4, 2009): Comment created by @beberlei: Correct, DateTime Type support in Oracle is broken: in convertToPHPValue i get as value: 04-NOV09 11.35.15 AM +01.00 as Platform DateTime Format I get: Y-m-d H:i:sP This combination returns false in DateTime::createFromFormat()
Author
Owner

@doctrinebot commented on GitHub (Nov 4, 2009):

Comment created by @beberlei:

Renamed bug title

@doctrinebot commented on GitHub (Nov 4, 2009): Comment created by @beberlei: Renamed bug title
Author
Owner

@doctrinebot commented on GitHub (Nov 5, 2009):

Comment created by romanb:

This is actually a known issue and I dont think there is an easy solution for this. The point is, the format returned by oracle must match the format defined in the platform class.

For mysql or postgresql this is no problem because they accept a wide range of different formats as input. Oracle, however, only exactly the format that is configured.

Also, the default format of oracle can depend on the installation, locale/language, etc. So the only way to make datetime/date/time types work on oracle is to make the formats match. That means you either change the database format, or you change the format in the platform. The latter can happen through writing a custom platform class that inherits from oracle platform and overrides the respective methods. Alternatively we could provider setters on the platform classes for these formats (setTimeFormat... etc).

To change the format used by oracle to match the default format used by doctrine, put the following in your initXE.ora (assuming Oracle XE):

NLS*TIME*FORMAT="HH24:MI:SS"
NLS*DATE*FORMAT="YYYY-MM-DD"
NLS*TIMESTAMP*FORMAT="YYYY-MM-DD HH24:MI:SS"
NLS*TIMESTAMP_TZ*FORMAT="YYYY-MM-DD HH24:MI:SS TZH:TZM"

Hopefully, whoever uses oracle in production has a DBA at his side anyway ;)

@doctrinebot commented on GitHub (Nov 5, 2009): Comment created by romanb: This is actually a known issue and I dont think there is an easy solution for this. The point is, the format returned by oracle must match the format defined in the platform class. For mysql or postgresql this is no problem because they accept a wide range of different formats as input. Oracle, however, only exactly the format that is configured. Also, the default format of oracle can depend on the installation, locale/language, etc. So the only way to make datetime/date/time types work on oracle is to make the formats match. That means you either change the database format, or you change the format in the platform. The latter can happen through writing a custom platform class that inherits from oracle platform and overrides the respective methods. Alternatively we could provider setters on the platform classes for these formats (setTimeFormat... etc). To change the format used by oracle to match the default format used by doctrine, put the following in your initXE.ora (assuming Oracle XE): ``` NLS*TIME*FORMAT="HH24:MI:SS" NLS*DATE*FORMAT="YYYY-MM-DD" NLS*TIMESTAMP*FORMAT="YYYY-MM-DD HH24:MI:SS" NLS*TIMESTAMP_TZ*FORMAT="YYYY-MM-DD HH24:MI:SS TZH:TZM" ``` Hopefully, whoever uses oracle in production has a DBA at his side anyway ;)
Author
Owner

@doctrinebot commented on GitHub (Nov 7, 2009):

Comment created by @guilhermeblanco:

Isn't it possible to get the configuration format from Database during Config initialization?

@doctrinebot commented on GitHub (Nov 7, 2009): Comment created by @guilhermeblanco: Isn't it possible to get the configuration format from Database during Config initialization?
Author
Owner

@doctrinebot commented on GitHub (Nov 11, 2009):

Comment created by @jwage:

We need to just document this. The default format Oracle has configured cannot be parsed by strtotime() so they will always need to configure it.

@doctrinebot commented on GitHub (Nov 11, 2009): Comment created by @jwage: We need to just document this. The default format Oracle has configured cannot be parsed by strtotime() so they will always need to configure it.
Author
Owner

@doctrinebot commented on GitHub (Nov 11, 2009):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Nov 11, 2009): Issue was closed with resolution "Invalid"
Author
Owner

@doctrinebot commented on GitHub (Jan 31, 2010):

Comment created by @beberlei:

lsmith made a statement in IRC that MDB2 has a configuration option for this, there should be an event in "Doctrine\DBAL\Connection::connect()" where you get passed the driver and can execute driver specific code.

Additionally I'll start an appendix section "Platform Quirks" - where we can document specifics of using a platform.

@doctrinebot commented on GitHub (Jan 31, 2010): Comment created by @beberlei: lsmith made a statement in IRC that MDB2 has a configuration option for this, there should be an event in "Doctrine\DBAL\Connection::connect()" where you get passed the driver and can execute driver specific code. Additionally I'll start an appendix section "Platform Quirks" - where we can document specifics of using a platform.
Author
Owner

@doctrinebot commented on GitHub (Jan 31, 2010):

Comment created by @beberlei:

Patch attached that adds a new event "postDriverConnect". Arguments to this event is the Connection with convenience methods to retrieve driver, platform and schema manager.

Added a new namespace/package Doctrine\DBAL\Event\Listeners which for now holds a OracleSessionInit class which sets all the 4 enviroment variables required for Doctrine to run and allows to set even more if that would be necessary.

An enhancement to Doctrine\Tests\TestUtil now allows to register "event subscribers" by setting a "db_event_subscribers" option in the phpunit configuration with a comma-separated list of class-names.

@doctrinebot commented on GitHub (Jan 31, 2010): Comment created by @beberlei: Patch attached that adds a new event "postDriverConnect". Arguments to this event is the Connection with convenience methods to retrieve driver, platform and schema manager. Added a new namespace/package Doctrine\DBAL\Event\Listeners which for now holds a OracleSessionInit class which sets all the 4 enviroment variables required for Doctrine to run and allows to set even more if that would be necessary. An enhancement to Doctrine\Tests\TestUtil now allows to register "event subscribers" by setting a "db_event_subscribers" option in the phpunit configuration with a comma-separated list of class-names.
Author
Owner

@doctrinebot commented on GitHub (Jan 31, 2010):

Comment created by romanb:

The idea looks ok, just a couple of small changes from my side:

  1. "postConnect" instead of "postDriverConnect"
  2. Before dispatching an event, always check for listeners, so that you can avoid creating unnecessary eventargs objects. (if ($evm->hasListeners(Events::postConnect))) { ... construct event args and dispatch event }
  3. I think you should name the eventargs just ConnectionEventArgs, since there is nothing specific to the postConnect event in there, just common Connection event information. So you can reuse and/or inherit from that eventargs class later if needed.
@doctrinebot commented on GitHub (Jan 31, 2010): Comment created by romanb: The idea looks ok, just a couple of small changes from my side: 1) "postConnect" instead of "postDriverConnect" 2) Before dispatching an event, always check for listeners, so that you can avoid creating unnecessary eventargs objects. (if ($evm->hasListeners(Events::postConnect))) { ... construct event args and dispatch event } 3) I think you should name the eventargs just ConnectionEventArgs, since there is nothing specific to the postConnect event in there, just common Connection event information. So you can reuse and/or inherit from that eventargs class later if needed.
Author
Owner

@doctrinebot commented on GitHub (Jan 13, 2012):

Comment created by marc.campeau@gmail.com:

I'm curious as to what happened with this issue. I don't see the contents of the patch in the latest releases. Has this been left off main release and should be patched by anyone using Oracle or has this been refactored into some other code in latter releases. I'm running into this situation using Oracle and Doctrine 2.1 and would like to know how to fix this. Thanks

@doctrinebot commented on GitHub (Jan 13, 2012): Comment created by marc.campeau@gmail.com: I'm curious as to what happened with this issue. I don't see the contents of the patch in the latest releases. Has this been left off main release and should be patched by anyone using Oracle or has this been refactored into some other code in latter releases. I'm running into this situation using Oracle and Doctrine 2.1 and would like to know how to fix this. Thanks
Author
Owner

@doctrinebot commented on GitHub (Jan 13, 2012):

Comment created by marc.campeau@gmail.com:

Sorry found what I was looking for.

For the record: Patch Code was refactored as suggested by Roman S. Borschel above:

See DBAL Documentation about Events for an example on how to integrate: [http://www.doctrine-project.org/docs/dbal/2.1/en/reference/events.html]

@doctrinebot commented on GitHub (Jan 13, 2012): Comment created by marc.campeau@gmail.com: Sorry found what I was looking for. For the record: Patch Code was refactored as suggested by Roman S. Borschel [above](#action_11560): See DBAL Documentation about Events for an example on how to integrate: [http://www.doctrine-project.org/docs/dbal/2.1/en/reference/events.html]
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 1 attachments from Jira into https://gist.github.com/ec44c2d663922db160a7

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 1 attachments from Jira into https://gist.github.com/ec44c2d663922db160a7 - [10333_ddc110.patch](https://gist.github.com/ec44c2d663922db160a7#file-10333_ddc110-patch)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#136