summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
Diffstat (limited to 'system')
-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
5 files changed, 174 insertions, 13 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.';
+