Issues

ZF2-484: Log\Writer\Db not able to handle timestamp colum as datetime can't be converted to string

Issue Type: Bug Created: 2012-08-20T23:49:32.000+0000 Last Updated: 2012-08-24T19:36:35.000+0000 Status: Resolved Fix version(s): Reporter: Thomas R. (thomas_r) Assignee: Benoît Durand (intiilapa) Tags: - Zend\Log

  • log
  • log\writer\db

Related issues: Attachments:

Description

The doWrite method of Log\Writer\Db currently doesn't handle the datetime object, so when the query is set to be manually built (something which should perhaps use the Sql insert class?) the datetime object cannot be converted to a string, and it errors out. Tested with sqlite, though perhaps not for mysql?

This poses an urgent problem of how the datetime is to be formatted for the user, should it be something like simply getTimestamp() on the datetime object, or formatted with date("r", ...) for example. The user should be able to choose.

See the two commented out lines below.

<pre class="highlight">
    protected function doWrite(array $event)
    {
        if (null === $this->db) {
            throw new Exception\RuntimeException('Database adapter is null');
        }

        // manually format timestamp
//        $event['timestamp'] = $event['timestamp']->getTimestamp();
//        $event['timestamp'] = date("r", $event['timestamp']->getTimestamp());

        // Transform the event array into fields
        if (null === $this->columnMap) {
            $dataToInsert = $this->eventIntoColumn($event);
        } else {
            $dataToInsert = $this->mapEventIntoColumn($event, $this->columnMap);
        }

        $statement = $this->db->query($this->prepareInsert($this->db, $this->tableName, $dataToInsert));
        $statement->execute($dataToInsert);

    }

Comments

Posted by Benoît Durand (intiilapa) on 2012-08-24T19:36:35.000+0000

Fixed on master

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts