summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/database/DB_cache.php32
-rw-r--r--system/database/DB_driver.php107
-rw-r--r--system/database/DB_utility.php8
-rw-r--r--system/helpers/date_helper.php38
-rw-r--r--system/language/english/db_lang.php2
-rw-r--r--user_guide/general/changelog.html4
-rw-r--r--user_guide/helpers/date_helper.html31
7 files changed, 208 insertions, 14 deletions
diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php
index 086958d3d..4721f32c3 100644
--- a/system/database/DB_cache.php
+++ b/system/database/DB_cache.php
@@ -39,6 +39,38 @@ class CI_DB_cache {
// --------------------------------------------------------------------
+
+ function cache_exists($sql)
+ {
+
+
+ }
+
+
+ function get_cache($sql)
+ {
+
+
+ }
+
+
+ function delete_cache()
+ {
+
+ }
+
+
+ function delete_all_caches()
+ {
+
+
+ }
+
+
+
+
+
+
}
?> \ No newline at end of file
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 81af466ef..73c723d96 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -41,11 +41,13 @@ class CI_DB_driver {
var $conn_id = FALSE;
var $result_id = FALSE;
var $db_debug = FALSE;
+ var $query_caching = FALSE;
+ var $cache_dir = '';
var $benchmark = 0;
var $query_count = 0;
var $bind_marker = '?';
var $queries = array();
- var $cache = array();
+ var $data_cache = array();
var $trans_enabled = TRUE;
var $_trans_depth = 0;
var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur
@@ -55,6 +57,7 @@ class CI_DB_driver {
var $curs_id;
var $limit_used;
+
/**
* Constructor. Accepts one parameter containing the database
@@ -214,6 +217,21 @@ class CI_DB_driver {
return FALSE;
}
+ // Is query caching enabled? If the query is a "read type" we'll
+ // grab the previously cached query if it exists and return it.
+ if ($this->query_caching == TRUE)
+ {
+ if (stristr($sql, 'SELECT'))
+ {
+ $CACHE =& _load_cache_class();
+
+ if (FALSE !== ($CACHE->cache_exists($sql)))
+ {
+ return $CACHE->get_cache($sql);
+ }
+ }
+ }
+
// Compile binds if needed
if ($binds !== FALSE)
{
@@ -257,7 +275,7 @@ class CI_DB_driver {
// Was the query a "write" type?
// If so we'll simply return true
if ($this->is_write_type($sql) === TRUE)
- {
+ {
return TRUE;
}
@@ -564,9 +582,9 @@ class CI_DB_driver {
function list_tables()
{
// Is there a cached result?
- if (isset($this->cache['table_names']))
+ if (isset($this->data_cache['table_names']))
{
- return $this->cache['table_names'];
+ return $this->data_cache['table_names'];
}
if (FALSE === ($sql = $this->_list_tables()))
@@ -596,7 +614,7 @@ class CI_DB_driver {
}
}
- return $this->cache['table_names'] =& $retval;
+ return $this->data_cache['table_names'] =& $retval;
}
// --------------------------------------------------------------------
@@ -623,9 +641,9 @@ class CI_DB_driver {
function list_fields($table = '')
{
// Is there a cached result?
- if (isset($this->cache['field_names'][$table]))
+ if (isset($this->data_cache['field_names'][$table]))
{
- return $this->cache['field_names'][$table];
+ return $this->data_cache['field_names'][$table];
}
if ($table == '')
@@ -661,7 +679,7 @@ class CI_DB_driver {
}
}
- return $this->cache['field_names'][$table] =& $retval;
+ return $this->data_cache['field_names'][$table] =& $retval;
}
// --------------------------------------------------------------------
@@ -820,6 +838,79 @@ class CI_DB_driver {
return call_user_func_array($function, $args);
}
}
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Set Cache Path
+ *
+ * @access public
+ * @param string the path to the cache directory
+ * @return void
+ */
+ function set_cache_path($path = '')
+ {
+ if ( ! is_dir($path) OR ! is_writable($path))
+ {
+ if ($this->db_debug)
+ {
+ return $this->display_error('db_invalid_cache_path');
+ }
+
+ $this->enable_caching(FALSE);
+ return FALSE;
+ }
+
+ $this->cache_dir = $path;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Enable Query Caching
+ *
+ * @access public
+ * @return void
+ */
+ function cache_on()
+ {
+ $this->query_caching = TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Disable Query Caching
+ *
+ * @access public
+ * @return void
+ */
+ function cache_off()
+ {
+ $this->query_caching = FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Load Caching Class
+ *
+ * @access private
+ * @return object
+ */
+ function _load_cache_class()
+ {
+ static $CACHE = NULL;
+
+ if (is_object($CACHE))
+ {
+ return $CACHE;
+ }
+
+ require_once BASEPATH.'database/DB_cache'.EXT;
+ $CACHE = new DB_cache();
+ return $CACHE;
+ }
// --------------------------------------------------------------------
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index 339baa8be..433056ff0 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -25,7 +25,7 @@
class CI_DB_utility {
var $db;
- var $cache = array();
+ var $data_cache = array();
/**
* Constructor
@@ -95,9 +95,9 @@ class CI_DB_utility {
function list_databases()
{
// Is there a cached result?
- if (isset($this->cache['db_names']))
+ if (isset($this->data_cache['db_names']))
{
- return $this->cache['db_names'];
+ return $this->data_cache['db_names'];
}
$query = $this->db->query($this->_list_database());
@@ -110,7 +110,7 @@ class CI_DB_utility {
}
}
- return $this->cache['db_names'] =& $dbs;
+ return $this->data_cache['db_names'] =& $dbs;
}
// --------------------------------------------------------------------
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php
index ab3a31867..987658c2e 100644
--- a/system/helpers/date_helper.php
+++ b/system/helpers/date_helper.php
@@ -92,7 +92,43 @@ function mdate($datestr = '', $time = '')
// ------------------------------------------------------------------------
/**
- * Convert MySQL Style Datecodes
+ * Standard Date
+ *
+ * Returns a date formatted according to the submitted standard.
+ *
+ * @access public
+ * @param string the chosen format
+ * @param integer Unix timestamp
+ * @return string
+ */
+function standard_date($fmt = 'DATE_RFC822', $time = '')
+{
+ $formats = array(
+ 'DATE_ATOM' => '%Y-%m-%dT%H:%i:%s%Q',
+ 'DATE_COOKIE' => '%l, %d-%M-%y %H:%i:%s UTC',
+ 'DATE_ISO8601' => '%Y-%m-%dT%H:%i:%s%O',
+ 'DATE_RFC822' => '%D, %d %M %y %H:%i:%s %O',
+ 'DATE_RFC850' => '%l, %d-%M-%y %H:%m:%i UTC',
+ 'DATE_RFC1036' => '%D, %d %M %y %H:%i:%s %O',
+ 'DATE_RFC1123' => '%D, %d %M %Y %H:%i:%s %O',
+ 'DATE_RFC2822' => '%D, %d %M %Y %H:%i:%s %O',
+ 'DATE_RSS' => '%D, %d %M %Y %H:%i:%s %O',
+ 'DATE_W3C' => '%Y-%m-%dT%H:%i:%s%Q'
+ );
+
+ if ( ! isset($formats[$fmt]))
+ {
+ return FALSE;
+ }
+
+ return mdate($formats[$fmt], $time);
+}
+
+
+// ------------------------------------------------------------------------
+
+/**
+ * Timespan
*
* Returns a span of seconds in this format:
* 10 days 14 hours 36 minutes 47 seconds
diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php
index 392990120..a17bb71ff 100644
--- a/system/language/english/db_lang.php
+++ b/system/language/english/db_lang.php
@@ -16,6 +16,8 @@ $lang['db_unable_to_drop'] = 'Unable to drop the specified database.';
$lang['db_unsuported_feature'] = 'Unsupported feature of the database platform you are using.';
$lang['db_unsuported_compression'] = 'The file compression format you chose is not supported by your server.';
$lang['db_filepath_error'] = 'Unable to write data to the file path you have submitted.';
+$lang['db_invalid_cache_path'] = 'The cache path you submitted is not valid or writable.';
+
diff --git a/user_guide/general/changelog.html b/user_guide/general/changelog.html
index 19366499d..1cac05dca 100644
--- a/user_guide/general/changelog.html
+++ b/user_guide/general/changelog.html
@@ -67,7 +67,7 @@ Change Log
<p>Release Date: Ocotber 15, 2006</p>
<ul>
-<li>Added <a href="../database/utilities.html">DB utility class</a>, permitting DB backups, generating CVS or XML files, and various other functions.</li>
+<li>Added <a href="../database/utilities.html">DB utility class</a>, permitting DB backups, CVS or XML files from DB results, and various other functions.</li>
<li>Added <a href="../database/caching.html">DB Caching class</a> permitting queries to be cached.</li>
<li>Added <a href="../database/transactions.html">transaction support</a> to the database classes.</li>
<li>Added relationship capability to the database active record class</li>
@@ -76,6 +76,8 @@ Change Log
<li>Added support for storing <a href="models.html">models within sub-folders</a>.</li>
<li>Added <a href="../helpers/download_helper.html">Download Helper</a>.</li>
<li>Added <a href="../database/queries.html">simple_query()</a> function to the database classes</li>
+<li>Added <a href="../helpers/date_helper.html">standard_date()</a> function to the Date Helper.</li>
+
<li>Added $query->free_result();</li>
<li>Added $query->field_names() function</li>
<li>Added $this->db->platform() function</li>
diff --git a/user_guide/helpers/date_helper.html b/user_guide/helpers/date_helper.html
index 44296dc84..420d891a6 100644
--- a/user_guide/helpers/date_helper.html
+++ b/user_guide/helpers/date_helper.html
@@ -100,6 +100,37 @@ echo mdate($datestring, $time);</code>
<p>If a timestamp is not included in the second parameter the current time will be used.</p>
+<h2>standard_date()</h2>
+
+<p>Lets you generate a date string in one of several standardized formats. Example:</p>
+
+<code>
+$format = 'DATE_RFC822';<br />
+$time = time();<br />
+<br />
+echo standard_date($format, $time);
+</code>
+
+<p>The first parameter must contain the format, the second parameter must contain the date as a Unix timestamp.</p>
+
+<p>Supported formats:</p>
+
+<ul>
+<li>DATE_ATOM</li>
+<li>DATE_COOKIE</li>
+<li>DATE_ISO8601</li>
+<li>DATE_RFC822</li>
+<li>DATE_RFC850</li>
+<li>DATE_RFC1036</li>
+<li>DATE_RFC1123</li>
+<li>DATE_RFC2822</li>
+<li>DATE_RSS</li>
+<li>DATE_W3C</li>
+</ul>
+
+
+
+
<h2>local_to_gmt()</h2>
<p>Takes a Unix timestamp as input and returns it as GMT. Example:</p>