diff options
author | Andrey Andreev <narf@devilix.net> | 2016-11-22 12:23:33 +0100 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2016-11-22 12:23:33 +0100 |
commit | 21b7a2a2d00bd5645b2ca1afcfa4098e207292a4 (patch) | |
tree | 2d53b72677b4890e843af0e9d92a9358295b141a /system | |
parent | 8d11232616fdf984ff8b9bb295693bdea91d7d8e (diff) |
Add support for CURRENT_TIMESTAMP (and similar) defaults to date/time fields in DB Forge
As requested in #4852
Diffstat (limited to 'system')
-rw-r--r-- | system/database/DB_forge.php | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index ed6f4b672..fe81d0510 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -894,21 +894,33 @@ abstract class CI_DB_forge { return; } - if (array_key_exists('DEFAULT', $attributes)) + if ( ! array_key_exists('DEFAULT', $attributes)) { - if ($attributes['DEFAULT'] === NULL) - { - $field['default'] = empty($this->_null) ? '' : $this->_default.$this->_null; + return; + } - // Override the NULL attribute if that's our default - $attributes['NULL'] = TRUE; - $field['null'] = empty($this->_null) ? '' : ' '.$this->_null; - } - else - { - $field['default'] = $this->_default.$this->db->escape($attributes['DEFAULT']); - } + if ($attributes['DEFAULT'] === NULL) + { + $field['default'] = empty($this->_null) ? '' : $this->_default.$this->_null; + + // Override the NULL attribute if that's our default + $attributes['NULL'] = TRUE; + $field['null'] = empty($this->_null) ? '' : ' '.$this->_null; + return; } + + // White-list CURRENT_TIMESTAMP & similar (e.g. Oracle has stuff like SYSTIMESTAMP) defaults for date/time fields + if ( + isset($attributes['TYPE']) + && (stripos($attributes['TYPE'], 'time') !== FALSE || stripos($attributes['TYPE'], 'date') !== FALSE) + && (stripos($attributes['DEFAULT'], 'time') !== FALSE || stripos($attributes['DEFAULT'], 'date') !== FALSE) + ) + { + $field['default'] = $this->_default.$attributes['DEFAULT']; + return; + } + + $field['default'] = $this->_default.$this->db->escape($attributes['DEFAULT']); } // -------------------------------------------------------------------- |