summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/database/DB_forge.php36
-rw-r--r--user_guide_src/source/changelog.rst6
2 files changed, 29 insertions, 13 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']);
}
// --------------------------------------------------------------------
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 9c3058ce5..692d06833 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -31,12 +31,16 @@ Release Date: Not Released
- Changed method ``clear()`` to also reset captions.
-- Database
+- :doc:`Database <database/index>`
- Changed method ``initialize()`` to return void and instead throw a ``RuntimeException`` in case of failure.
- Changed method ``db_connect()`` to always set the connection character set (if supported by the driver) and to fail if it can't.
- Removed method ``db_set_charset()`` and the ability to change a connection character set at runtime.
+ - :doc:`Database Forge <database/forge>`:
+
+ - Added support for declaring date/time type fields default values as ``CURRENT_TIMESTAMP`` and similar.
+
- Helpers
- Added new function :php:func:`ordinal_format()` to :doc:`Inflector Helper <helpers/inflector_helper>`.