Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cast of default column value CURRENT_TIMESTAMP in MysqlAdatper throws exception #2

Closed
bladenkerst opened this issue Jun 20, 2009 · 1 comment

Comments

@bladenkerst
Copy link

When declaring a model for a table with a CURRENT_TIMESTAMP set as the default value, the MysqlAdapter throws an exception. Ideally one would not use CURRENT_TIMESTAMP on a database while using the ActiveRecord pattern but we all have the fun of working with legacy databases, especially since this is very new to PHP.

The Exception is thrown from DateTime::__construct =>
>> $a = new DateTime('CURRENT_TIMESTAMP');
Exception (code: 0) got thrown
exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (CURRENT_TIMESTAMP) at position 0 (C): The timezone could not be found in the database' in...

Possible Fix (mimics Rails which just returns nil on a bad time parse):

case self::DATETIME:
case self::DATE:
  try {
    return ($value instanceof \DateTime) ? $value : new \DateTime($value);
  } catch(\Exception $e) {
    return null;
  }
@kla
Copy link
Collaborator

kla commented Jun 24, 2009

I've applied this fix. thanks!

murayama referenced this issue in murayama/php-activerecord Feb 25, 2013
is_hashのネームエラーを解決
joshuan pushed a commit to Fabrica/php-activerecord that referenced this issue May 23, 2014
Shortened the false condition in PgsqlAdapter::boolean_to_string()
passthefist pushed a commit to passthefist/php-activerecord that referenced this issue Jun 30, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants