From 4921fed6c17a54efd4fac0bed4d058463bd9b601 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Sat, 7 Jan 2012 01:28:07 +0200
Subject: Improve the smiley, string & text helpers
---
system/helpers/smiley_helper.php | 97 ++++++++++++----------------
system/helpers/string_helper.php | 81 +++++++++---------------
system/helpers/text_helper.php | 133 +++++++++++++++++++--------------------
3 files changed, 134 insertions(+), 177 deletions(-)
diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php
index 700f4486c..bc265e552 100644
--- a/system/helpers/smiley_helper.php
+++ b/system/helpers/smiley_helper.php
@@ -1,13 +1,13 @@
- $id)
{
- foreach ($alias as $name => $id)
- {
- $m[] = '"'.$name.'" : "'.$id.'"';
- }
+ $m[] = '"'.$name.'" : "'.$id.'"';
}
+ }
- $m = '{'.implode(',', $m).'}';
+ $m = '{'.implode(',', $m).'}';
- $r .= <</*';
- }
- else
- {
- return $r;
- }
+ return ($inline) ? '' : $r;
}
}
@@ -154,12 +145,9 @@ if ( ! function_exists('get_clickable_smileys'))
$smileys = $alias;
}
- if ( ! is_array($smileys))
+ if ( ! is_array($smileys) && FALSE === ($smileys = _get_smiley_array()))
{
- if (FALSE === ($smileys = _get_smiley_array()))
- {
- return $smileys;
- }
+ return $smileys;
}
// Add a trailing slash to the file path if needed
@@ -178,7 +166,6 @@ if ( ! function_exists('get_clickable_smileys'))
}
$link[] = "";
-
$used[$smileys[$key][0]] = TRUE;
}
@@ -207,16 +194,13 @@ if ( ! function_exists('parse_smileys'))
return $str;
}
- if ( ! is_array($smileys))
+ if ( ! is_array($smileys) && FALSE === ($smileys = _get_smiley_array()))
{
- if (FALSE === ($smileys = _get_smiley_array()))
- {
- return $str;
- }
+ return $str;
}
// Add a trailing slash to the file path if needed
- $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url);
+ $image_url = rtrim($image_url, '/').'/';
foreach ($smileys as $key => $val)
{
@@ -249,7 +233,7 @@ if ( ! function_exists('_get_smiley_array'))
{
include(APPPATH.'config/smileys.php');
}
-
+
if (isset($smileys) AND is_array($smileys))
{
return $smileys;
@@ -288,6 +272,5 @@ EOF;
}
}
-
/* End of file smiley_helper.php */
-/* Location: ./system/helpers/smiley_helper.php */
\ No newline at end of file
+/* Location: ./system/helpers/smiley_helper.php */
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php
index 04d51c2f9..654f721b0 100644
--- a/system/helpers/string_helper.php
+++ b/system/helpers/string_helper.php
@@ -1,13 +1,13 @@
-load->helper('security');
-
- return do_hash(uniqid(mt_rand(), TRUE), 'sha1');
- break;
+ case 'basic': return mt_rand();
+ case 'alnum':
+ case 'numeric':
+ case 'nozero':
+ case 'alpha':
+ switch ($type)
+ {
+ case 'alpha': $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ break;
+ case 'alnum': $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ break;
+ case 'numeric': $pool = '0123456789';
+ break;
+ case 'nozero': $pool = '123456789';
+ break;
+ }
+ return substr(str_shuffle(str_repeat($pool, ceil($len/strlen($pool)))),0,$len);
+ case 'unique':
+ case 'md5': return md5(uniqid(mt_rand()));
+ case 'encrypt':
+ case 'sha1':
+ $CI =& get_instance();
+ $CI->load->helper('security');
+ return do_hash(uniqid(mt_rand(), TRUE), 'sha1');
}
}
}
@@ -262,7 +245,6 @@ if ( ! function_exists('random_string'))
function increment_string($str, $separator = '_', $first = 1)
{
preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match);
-
return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first;
}
@@ -311,6 +293,5 @@ if ( ! function_exists('repeater'))
}
}
-
/* End of file string_helper.php */
-/* Location: ./system/helpers/string_helper.php */
\ No newline at end of file
+/* Location: ./system/helpers/string_helper.php */
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 842a31d75..562270f96 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -1,13 +1,13 @@
-","\"", "'", "-"),
- $str);
+ return str_replace(array('&', '<', '>', '"', ''', '-'),
+ array('&', '<', '>', '"', "'", '-'),
+ $str);
}
return $str;
@@ -294,42 +294,38 @@ if ( ! function_exists('highlight_code'))
{
function highlight_code($str)
{
- // The highlight string function encodes and highlights
- // brackets so we need them to start raw
- $str = str_replace(array('<', '>'), array('<', '>'), $str);
-
- // Replace any existing PHP tags to temporary markers so they don't accidentally
- // break the string out of PHP, and thus, thwart the highlighting.
-
- $str = str_replace(array('', '?>', '<%', '%>', '\\', ''),
- array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str);
+ /* The highlight string function encodes and highlights
+ * brackets so we need them to start raw.
+ *
+ * Also replace any existing PHP tags to temporary markers
+ * so they don't accidentally break the string out of PHP,
+ * and thus, thwart the highlighting.
+ */
+ $str = str_replace(array('<', '>', '', '?>', '<%', '%>', '\\', ''),
+ array('<', '>', 'phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
+ $str);
// The highlight_string function requires that the text be surrounded
// by PHP tags, which we will remove later
- $str = ''; //
-
- // All the magic happens here, baby!
- $str = highlight_string($str, TRUE);
-
- // Prior to PHP 5, the highligh function used icky tags
- // so we'll replace them with tags.
-
- if (abs(PHP_VERSION) < 5)
- {
- $str = str_replace(array(''), array(''), $str);
- $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str);
- }
+ $str = highlight_string('', TRUE);
// Remove our artificially added PHP, and the syntax highlighting that came with it
- $str = preg_replace('/<\?php( | )/i', '', $str);
- $str = preg_replace('/(.*?)\?><\/span>\n<\/span>\n<\/code>/is', "$1\n\n", $str);
- $str = preg_replace('/<\/span>/i', '', $str);
+ $str = preg_replace(array(
+ '/<\?php( | )/i',
+ '/(.*?)\?><\/span>\n<\/span>\n<\/code>/is',
+ '/<\/span>/i'
+ ),
+ array(
+ '',
+ "$1\n\n",
+ ''
+ ),
+ $str);
// Replace our markers back to PHP tags.
- $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
- array('<?', '?>', '<%', '%>', '\\', '</script>'), $str);
-
- return $str;
+ return str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
+ array('<?', '?>', '<%', '%>', '\\', '</script>'),
+ $str);
}
}
@@ -414,12 +410,14 @@ if ( ! function_exists('word_wrap'))
{
function word_wrap($str, $charlim = '76')
{
- // Se the character limit
+ // Set the character limit
if ( ! is_numeric($charlim))
+ {
$charlim = 76;
+ }
// Reduce multiple spaces
- $str = preg_replace("| +|", " ", $str);
+ $str = preg_replace('| +|', ' ', $str);
// Standardize newlines
if (strpos($str, "\r") !== FALSE)
@@ -430,22 +428,22 @@ if ( ! function_exists('word_wrap'))
// If the current word is surrounded by {unwrap} tags we'll
// strip the entire chunk and replace it with a marker.
$unwrap = array();
- if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches))
+ if (preg_match_all('|(\{unwrap\}.+?\{/unwrap\})|s', $str, $matches))
{
- for ($i = 0; $i < count($matches['0']); $i++)
+ for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
{
- $unwrap[] = $matches['1'][$i];
- $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str);
+ $unwrap[] = $matches[1][$i];
+ $str = str_replace($matches[1][$i], '{{unwrapped'.$i.'}}', $str);
}
}
// Use PHP's native function to do the initial wordwrap.
// We set the cut flag to FALSE so that any individual words that are
- // too long get left alone. In the next step we'll deal with them.
+ // too long get left alone. In the next step we'll deal with them.
$str = wordwrap($str, $charlim, "\n", FALSE);
// Split the string into individual lines of text and cycle through them
- $output = "";
+ $output = '';
foreach (explode("\n", $str) as $line)
{
// Is the line within the allowed character count?
@@ -460,7 +458,7 @@ if ( ! function_exists('word_wrap'))
while ((strlen($line)) > $charlim)
{
// If the over-length word is a URL we won't wrap it
- if (preg_match("!\[url.+\]|://|wwww.!", $line))
+ if (preg_match('!\[url.+\]|://|wwww.!', $line))
{
break;
}
@@ -474,14 +472,12 @@ if ( ! function_exists('word_wrap'))
// word into smaller chunks so we'll add it back to our current line
if ($temp != '')
{
- $output .= $temp."\n".$line;
+ $output .= $temp."\n".$line."\n";
}
else
{
- $output .= $line;
+ $output .= $line."\n";
}
-
- $output .= "\n";
}
// Put our markers back
@@ -489,14 +485,12 @@ if ( ! function_exists('word_wrap'))
{
foreach ($unwrap as $key => $val)
{
- $output = str_replace("{{unwrapped".$key."}}", $val, $output);
+ $output = str_replace('{{unwrapped'.$key.'}}', $val, $output);
}
}
- // Remove the unwrap tags
- $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output);
-
- return $output;
+ // Remove the unwrap tags and return
+ return str_replace(array('{unwrap}', '{/unwrap}'), '', $output);
}
}
@@ -527,7 +521,6 @@ if ( ! function_exists('ellipsize'))
}
$beg = substr($str, 0, floor($max_length * $position));
-
$position = ($position > 1) ? 1 : $position;
if ($position === 1)
@@ -544,4 +537,4 @@ if ( ! function_exists('ellipsize'))
}
/* End of file text_helper.php */
-/* Location: ./system/helpers/text_helper.php */
\ No newline at end of file
+/* Location: ./system/helpers/text_helper.php */
--
cgit v1.2.3-24-g4f1b
From fc443553248af8ac0c1cbb635fe9cbb70fdf7b82 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Sat, 7 Jan 2012 02:14:55 +0200
Subject: Remove quotes around an integer value
---
system/helpers/text_helper.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 562270f96..3a847f29b 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -408,7 +408,7 @@ if ( ! function_exists('convert_accented_characters'))
*/
if ( ! function_exists('word_wrap'))
{
- function word_wrap($str, $charlim = '76')
+ function word_wrap($str, $charlim = 76)
{
// Set the character limit
if ( ! is_numeric($charlim))
--
cgit v1.2.3-24-g4f1b
From cb324bd9268fc6b0c93fd22545bd989771d68b04 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Sun, 8 Jan 2012 07:06:35 +0200
Subject: Some more misc. stuff
---
system/helpers/smiley_helper.php | 2 --
system/helpers/string_helper.php | 17 +++++++++--------
system/helpers/text_helper.php | 8 +++-----
3 files changed, 12 insertions(+), 15 deletions(-)
diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php
index bc265e552..03f3ee287 100644
--- a/system/helpers/smiley_helper.php
+++ b/system/helpers/smiley_helper.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Smiley Helpers
*
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php
index 654f721b0..fcdb0aa84 100644
--- a/system/helpers/string_helper.php
+++ b/system/helpers/string_helper.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter String Helpers
*
@@ -153,7 +151,7 @@ if ( ! function_exists('reduce_double_slashes'))
{
function reduce_double_slashes($str)
{
- return preg_replace("#(^|[^:])//+#", "\\1/", $str);
+ return preg_replace('#(^|[^:])//+#', '\\1/', $str);
}
}
@@ -181,7 +179,6 @@ if ( ! function_exists('reduce_multiples'))
function reduce_multiples($str, $character = ',', $trim = FALSE)
{
$str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str);
-
return ($trim === TRUE) ? trim($str, $character) : $str;
}
}
@@ -211,13 +208,17 @@ if ( ! function_exists('random_string'))
case 'alpha':
switch ($type)
{
- case 'alpha': $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ case 'alpha':
+ $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
- case 'alnum': $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ case 'alnum':
+ $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
- case 'numeric': $pool = '0123456789';
+ case 'numeric':
+ $pool = '0123456789';
break;
- case 'nozero': $pool = '123456789';
+ case 'nozero':
+ $pool = '123456789';
break;
}
return substr(str_shuffle(str_repeat($pool, ceil($len/strlen($pool)))),0,$len);
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 3a847f29b..cef32847d 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Text Helpers
*
@@ -93,7 +91,7 @@ if ( ! function_exists('character_limiter'))
return $str;
}
- $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str));
+ $str = preg_replace('/\s+/', ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str));
if (strlen($str) <= $n)
{
@@ -108,7 +106,7 @@ if ( ! function_exists('character_limiter'))
if (strlen($out) >= $n)
{
$out = trim($out);
- return (strlen($out) == strlen($str)) ? $out : $out.$end_char;
+ return (strlen($out) === strlen($str)) ? $out : $out.$end_char;
}
}
}
@@ -354,7 +352,7 @@ if ( ! function_exists('highlight_phrase'))
if ($phrase != '')
{
- return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open."\\1".$tag_close, $str);
+ return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open.'\\1'.$tag_close, $str);
}
return $str;
--
cgit v1.2.3-24-g4f1b
From 0f2ec5bde259b67f66cc353692d71d8a47f71b01 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Mon, 16 Jan 2012 14:02:24 +0200
Subject: convert_accented_characters() to include foreign_chars.php only when
needed
---
application/config/foreign_chars.php | 6 +++---
system/helpers/text_helper.php | 25 +++++++++++++++----------
2 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/application/config/foreign_chars.php b/application/config/foreign_chars.php
index 1ae0cef5f..f2f981c27 100644
--- a/application/config/foreign_chars.php
+++ b/application/config/foreign_chars.php
@@ -5,9 +5,9 @@
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Academic Free License version 3.0
- *
+ *
* This source file is subject to the Academic Free License (AFL 3.0) that is
* bundled with this package in the files license_afl.txt / license_afl.rst.
* It is also available through the world wide web at this URL:
@@ -87,4 +87,4 @@ $foreign_characters = array(
);
/* End of file foreign_chars.php */
-/* Location: ./application/config/foreign_chars.php */
\ No newline at end of file
+/* Location: ./application/config/foreign_chars.php */
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index cef32847d..8e308b722 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -372,18 +372,23 @@ if ( ! function_exists('convert_accented_characters'))
{
function convert_accented_characters($str)
{
- if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'))
- {
- include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php');
- }
- elseif (is_file(APPPATH.'config/foreign_chars.php'))
- {
- include(APPPATH.'config/foreign_chars.php');
- }
+ global $foreign_characters;
- if ( ! isset($foreign_characters))
+ if ( ! isset($foreign_characters) OR ! is_array($foreign_characters))
{
- return $str;
+ if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'))
+ {
+ include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php');
+ }
+ elseif (is_file(APPPATH.'config/foreign_chars.php'))
+ {
+ include(APPPATH.'config/foreign_chars.php');
+ }
+
+ if ( ! isset($foreign_characters) OR ! is_array($foreign_chars))
+ {
+ return $str;
+ }
}
return preg_replace(array_keys($foreign_characters), array_values($foreign_characters), $str);
--
cgit v1.2.3-24-g4f1b
From 2a97c7db940e94a115dea863708f587e58d26be4 Mon Sep 17 00:00:00 2001
From: John Wright
Date: Mon, 16 Jan 2012 15:09:19 -0800
Subject: It appears the Security class has been added to the system/core
folder and is loaded automatically as well. Using
$this->load->library('security'); in controllers currently returns FALSE, yet
you might not notice because the Security class is already loaded. I
discovered this because of a custom Loader class I was using returned an
error when loading the Security class.
---
user_guide_src/source/general/core_classes.rst | 1 +
1 file changed, 1 insertion(+)
diff --git a/user_guide_src/source/general/core_classes.rst b/user_guide_src/source/general/core_classes.rst
index ac41407f7..4aa6693f7 100644
--- a/user_guide_src/source/general/core_classes.rst
+++ b/user_guide_src/source/general/core_classes.rst
@@ -31,6 +31,7 @@ time CodeIgniter runs:
- Log
- Output
- Router
+- Security
- URI
- Utf8
--
cgit v1.2.3-24-g4f1b
From 09375d71aa933ac6ba3665f7ccc6949840177ade Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 19 Jan 2012 14:57:46 +0200
Subject: Some more cleaning
---
system/helpers/smiley_helper.php | 39 ++++++++++++---------------------------
system/helpers/string_helper.php | 32 +++++++++++++++-----------------
system/helpers/text_helper.php | 8 ++++----
3 files changed, 31 insertions(+), 48 deletions(-)
diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php
index 03f3ee287..d2b8936ae 100644
--- a/system/helpers/smiley_helper.php
+++ b/system/helpers/smiley_helper.php
@@ -9,7 +9,7 @@
* Licensed under the Open Software License version 3.0
*
* This source file is subject to the Open Software License (OSL 3.0) that is
- * bundled with this package in the files license.txt / license.rst. It is
+ * bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
* http://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to obtain it
@@ -40,7 +40,7 @@
/**
* Smiley Javascript
*
- * Returns the javascript required for the smiley insertion. Optionally takes
+ * Returns the javascript required for the smiley insertion. Optionally takes
* an array of aliases to loosely couple the smiley array to the view.
*
* @access public
@@ -105,14 +105,11 @@ if ( ! function_exists('smiley_js'))
}
EOF;
}
- else
+ elseif (is_array($alias))
{
- if (is_array($alias))
+ foreach ($alias as $name => $id)
{
- foreach ($alias as $name => $id)
- {
- $r .= 'smiley_map["'.$name.'"] = "'.$id.'";'."\n";
- }
+ $r .= 'smiley_map["'.$name.'"] = "'.$id."\";\n";
}
}
@@ -137,13 +134,11 @@ if ( ! function_exists('get_clickable_smileys'))
function get_clickable_smileys($image_url, $alias = '', $smileys = NULL)
{
// For backward compatibility with js_insert_smiley
-
if (is_array($alias))
{
$smileys = $alias;
}
-
- if ( ! is_array($smileys) && FALSE === ($smileys = _get_smiley_array()))
+ elseif (FALSE === ($smileys = _get_smiley_array()))
{
return $smileys;
}
@@ -155,7 +150,7 @@ if ( ! function_exists('get_clickable_smileys'))
foreach ($smileys as $key => $val)
{
// Keep duplicates from being used, which can happen if the
- // mapping array contains multiple identical replacements. For example:
+ // mapping array contains multiple identical replacements. For example:
// :-) and :) might be replaced with the same image so both smileys
// will be in the array.
if (isset($used[$smileys[$key][0]]))
@@ -163,7 +158,7 @@ if ( ! function_exists('get_clickable_smileys'))
continue;
}
- $link[] = "";
+ $link[] = '';
$used[$smileys[$key][0]] = TRUE;
}
@@ -187,12 +182,7 @@ if ( ! function_exists('parse_smileys'))
{
function parse_smileys($str = '', $image_url = '', $smileys = NULL)
{
- if ($image_url == '')
- {
- return $str;
- }
-
- if ( ! is_array($smileys) && FALSE === ($smileys = _get_smiley_array()))
+ if ($image_url == '' OR ( ! is_array($smileys) && FALSE === ($smileys = _get_smiley_array())))
{
return $str;
}
@@ -202,7 +192,7 @@ if ( ! function_exists('parse_smileys'))
foreach ($smileys as $key => $val)
{
- $str = str_replace($key, "", $str);
+ $str = str_replace($key, '', $str);
}
return $str;
@@ -223,7 +213,7 @@ if ( ! function_exists('_get_smiley_array'))
{
function _get_smiley_array()
{
- if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'))
+ if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php');
}
@@ -232,12 +222,7 @@ if ( ! function_exists('_get_smiley_array'))
include(APPPATH.'config/smileys.php');
}
- if (isset($smileys) AND is_array($smileys))
- {
- return $smileys;
- }
-
- return FALSE;
+ return (isset($smileys) && is_array($smileys)) ? $smileys : FALSE;
}
}
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php
index fcdb0aa84..d0948800b 100644
--- a/system/helpers/string_helper.php
+++ b/system/helpers/string_helper.php
@@ -9,7 +9,7 @@
* Licensed under the Open Software License version 3.0
*
* This source file is subject to the Open Software License (OSL 3.0) that is
- * bundled with this package in the files license.txt / license.rst. It is
+ * bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
* http://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to obtain it
@@ -75,16 +75,14 @@ if ( ! function_exists('strip_slashes'))
{
function strip_slashes($str)
{
- if (is_array($str))
+ if ( ! is_array($str))
{
- foreach ($str as $key => $val)
- {
- $str[$key] = strip_slashes($val);
- }
+ return stripslashes($str);
}
- else
+
+ foreach ($str as $key => $val)
{
- return stripslashes($str);
+ $str[$key] = strip_slashes($val);
}
return $str;
@@ -192,7 +190,7 @@ if ( ! function_exists('reduce_multiples'))
*
* @access public
* @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1
- * @param integer number of characters
+ * @param int number of characters
* @return string
*/
if ( ! function_exists('random_string'))
@@ -238,10 +236,10 @@ if ( ! function_exists('random_string'))
/**
* Add's _1 to a string or increment the ending number to allow _2, _3, etc
*
- * @param string $str required
- * @param string $separator What should the duplicate number be appended with
- * @param string $first Which number should be used for the first dupe increment
- * @return string
+ * @param string $str required
+ * @param string $separator What should the duplicate number be appended with
+ * @param string $first Which number should be used for the first dupe increment
+ * @return string
*/
function increment_string($str, $separator = '_', $first = 1)
{
@@ -254,10 +252,10 @@ function increment_string($str, $separator = '_', $first = 1)
/**
* Alternator
*
- * Allows strings to be alternated. See docs...
+ * Allows strings to be alternated. See docs...
*
* @access public
- * @param string (as many parameters as needed)
+ * @param string (as many parameters as needed)
* @return string
*/
if ( ! function_exists('alternator'))
@@ -283,14 +281,14 @@ if ( ! function_exists('alternator'))
*
* @access public
* @param string
- * @param integer number of repeats
+ * @param int number of repeats
* @return string
*/
if ( ! function_exists('repeater'))
{
function repeater($data, $num = 1)
{
- return (($num > 0) ? str_repeat($data, $num) : '');
+ return ($num > 0) ? str_repeat($data, $num) : '';
}
}
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 8e308b722..2d6da73ac 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -9,7 +9,7 @@
* Licensed under the Open Software License version 3.0
*
* This source file is subject to the Open Software License (OSL 3.0) that is
- * bundled with this package in the files license.txt / license.rst. It is
+ * bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
* http://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to obtain it
@@ -73,7 +73,7 @@ if ( ! function_exists('word_limiter'))
/**
* Character Limiter
*
- * Limits the string based on the character count. Preserves complete words
+ * Limits the string based on the character count. Preserves complete words
* so the character count may not be exactly as specified.
*
* @access public
@@ -376,7 +376,7 @@ if ( ! function_exists('convert_accented_characters'))
if ( ! isset($foreign_characters) OR ! is_array($foreign_characters))
{
- if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'))
+ if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php');
}
@@ -400,7 +400,7 @@ if ( ! function_exists('convert_accented_characters'))
/**
* Word Wrap
*
- * Wraps text at the specified character. Maintains the integrity of words.
+ * Wraps text at the specified character. Maintains the integrity of words.
* Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor
* will URLs.
*
--
cgit v1.2.3-24-g4f1b
From c5a1f93ef25c99df4035ef7182a6200b91afabab Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Tue, 24 Jan 2012 15:29:02 +0200
Subject: Revert a space in the license agreement :)
---
system/helpers/smiley_helper.php | 2 +-
system/helpers/string_helper.php | 2 +-
system/helpers/text_helper.php | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php
index d2b8936ae..cb902114e 100644
--- a/system/helpers/smiley_helper.php
+++ b/system/helpers/smiley_helper.php
@@ -9,7 +9,7 @@
* Licensed under the Open Software License version 3.0
*
* This source file is subject to the Open Software License (OSL 3.0) that is
- * bundled with this package in the files license.txt / license.rst. It is
+ * bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
* http://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to obtain it
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php
index d0948800b..0d1018f53 100644
--- a/system/helpers/string_helper.php
+++ b/system/helpers/string_helper.php
@@ -9,7 +9,7 @@
* Licensed under the Open Software License version 3.0
*
* This source file is subject to the Open Software License (OSL 3.0) that is
- * bundled with this package in the files license.txt / license.rst. It is
+ * bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
* http://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to obtain it
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 2d6da73ac..37b5d3178 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -9,7 +9,7 @@
* Licensed under the Open Software License version 3.0
*
* This source file is subject to the Open Software License (OSL 3.0) that is
- * bundled with this package in the files license.txt / license.rst. It is
+ * bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
* http://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to obtain it
--
cgit v1.2.3-24-g4f1b
From 4da24f8f1137afbaa2ec51d9c9fb635df1481472 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Wed, 25 Jan 2012 21:54:23 +0200
Subject: Improve the MSSQL database driver
---
system/database/drivers/mssql/mssql_driver.php | 242 +++++++++---------------
system/database/drivers/mssql/mssql_forge.php | 134 ++++---------
system/database/drivers/mssql/mssql_result.php | 50 ++---
system/database/drivers/mssql/mssql_utility.php | 38 ++--
4 files changed, 164 insertions(+), 300 deletions(-)
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 2a1098932..9cabe87be 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -1,13 +1,13 @@
-port != '')
{
@@ -80,10 +77,9 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_pconnect()
+ public function db_pconnect()
{
if ($this->port != '')
{
@@ -101,12 +97,11 @@ class CI_DB_mssql_driver extends CI_DB {
* Keep / reestablish the db connection if no queries have been
* sent for a length of time exceeding the server's idle timeout
*
- * @access public
* @return void
*/
- function reconnect()
+ public function reconnect()
{
- // not implemented in MSSQL
+ // Not supported in MSSQL
}
// --------------------------------------------------------------------
@@ -114,10 +109,9 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
- * @return resource
+ * @return bool
*/
- function db_select()
+ public function db_select()
{
// Note: The brackets are required in the event that the DB name
// contains reserved characters
@@ -129,14 +123,13 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Set client character set
*
- * @access public
* @param string
* @param string
- * @return resource
+ * @return bool
*/
- function db_set_charset($charset, $collation)
+ public function db_set_charset($charset, $collation)
{
- // @todo - add support if needed
+ // Not supported in MSSQL
return TRUE;
}
@@ -145,14 +138,12 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
- * @return resource
+ * @return mixed resource if rows are returned, bool otherwise
*/
- function _execute($sql)
+ protected function _execute($sql)
{
- $sql = $this->_prep_query($sql);
- return @mssql_query($sql, $this->conn_id);
+ return @mssql_query($this->_prep_query($sql), $this->conn_id);
}
// --------------------------------------------------------------------
@@ -162,11 +153,10 @@ class CI_DB_mssql_driver extends CI_DB {
*
* If needed, each database adapter can prep the query string
*
- * @access private called by execute()
* @param string an SQL query
* @return string
*/
- function _prep_query($sql)
+ protected function _prep_query($sql)
{
return $sql;
}
@@ -176,18 +166,12 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -195,10 +179,9 @@ class CI_DB_mssql_driver extends CI_DB {
// Reset the transaction failure flag.
// If the $test_mode flag is set to TRUE transactions will be rolled back
// even if the queries produce a successful result.
- $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
+ $this->_trans_failure = ($test_mode === TRUE);
- $this->simple_query('BEGIN TRAN');
- return TRUE;
+ return $this->simple_query('BEGIN TRAN');
}
// --------------------------------------------------------------------
@@ -206,24 +189,17 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
- $this->simple_query('COMMIT TRAN');
- return TRUE;
+ return $this->simple_query('COMMIT TRAN');
}
// --------------------------------------------------------------------
@@ -231,24 +207,17 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
- $this->simple_query('ROLLBACK TRAN');
- return TRUE;
+ return $this->simple_query('ROLLBACK TRAN');
}
// --------------------------------------------------------------------
@@ -256,12 +225,11 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Escape String
*
- * @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
+ public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -279,7 +247,7 @@ class CI_DB_mssql_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace(
+ return str_replace(
array($this->_like_escape_chr, '%', '_'),
array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
$str
@@ -294,10 +262,9 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
return @mssql_rows_affected($this->conn_id);
}
@@ -309,13 +276,14 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Returns the last id created in the Identity column.
*
- * @access public
- * @return integer
+ * @return int
*/
- function insert_id()
+ public function insert_id()
{
- $ver = self::_parse_major_version($this->version());
- $sql = ($ver >= 8 ? "SELECT SCOPE_IDENTITY() AS last_id" : "SELECT @@IDENTITY AS last_id");
+ $sql = (self::_parse_major_version($this->version()) > 7)
+ ? 'SELECT SCOPE_IDENTITY() AS last_id'
+ : 'SELECT @@IDENTITY AS last_id';
+
$query = $this->query($sql);
$row = $query->row();
return $row->last_id;
@@ -329,11 +297,10 @@ class CI_DB_mssql_driver extends CI_DB {
* Grabs the major version number from the
* database server version string passed in.
*
- * @access private
- * @param string $version
- * @return int16 major version number
+ * @param string $version
+ * @return int major version number
*/
- function _parse_major_version($version)
+ private function _parse_major_version($version)
{
preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $version, $ver_info);
return $ver_info[1]; // return the major version b/c that's all we're interested in.
@@ -344,12 +311,11 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Version number query string
*
- * @access public
- * @return string
+ * @return string
*/
- function _version()
+ protected function _version()
{
- return "SELECT @@VERSION AS ver";
+ return 'SELECT @@VERSION AS ver';
}
// --------------------------------------------------------------------
@@ -360,19 +326,17 @@ class CI_DB_mssql_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
* @param string
* @return string
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
return 0;
}
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
-
+ $query = $this->query($this->_count_string.$this->_protect_identifiers('numrows').' FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
{
return 0;
@@ -390,11 +354,10 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access private
- * @param boolean
+ * @param bool
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
$sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
@@ -415,11 +378,10 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access private
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'";
}
@@ -431,13 +393,12 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
- * @return object
+ * @return string
*/
- function _field_data($table)
+ protected function _field_data($table)
{
- return "SELECT TOP 1 * FROM ".$table;
+ return 'SELECT TOP 1 * FROM '.$table;
}
// --------------------------------------------------------------------
@@ -445,10 +406,9 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* The error message string
*
- * @access private
* @return string
*/
- function _error_message()
+ protected function _error_message()
{
return mssql_get_last_message();
}
@@ -458,12 +418,11 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* The error message number
*
- * @access private
- * @return integer
+ * @return string
*/
- function _error_number()
+ protected function _error_number()
{
- // Are error numbers supported?
+ // Not supported in MSSQL
return '';
}
@@ -474,11 +433,10 @@ class CI_DB_mssql_driver extends CI_DB {
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ protected function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -489,24 +447,20 @@ class CI_DB_mssql_driver extends CI_DB {
{
if (strpos($item, '.'.$id) !== FALSE)
{
- $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
+ $item = str_replace('.', $this->_escape_char.'.', $item);
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item);
}
}
if (strpos($item, '.') !== FALSE)
{
- $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
- }
- else
- {
- $str = $this->_escape_char.$item.$this->_escape_char;
+ $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
}
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char);
}
// --------------------------------------------------------------------
@@ -517,11 +471,10 @@ class CI_DB_mssql_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access public
- * @param type
- * @return type
+ * @param array
+ * @return string
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -538,15 +491,14 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert($table, $keys, $values)
+ protected function _insert($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -556,7 +508,6 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -564,24 +515,17 @@ class CI_DB_mssql_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
- $valstr[] = $key." = ".$val;
+ $valstr[] = $key.' = '.$val;
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
-
- $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
-
- $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
-
- $sql .= $orderby.$limit;
-
- return $sql;
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
+ .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '')
+ .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '')
+ .( ! $limit ? '' : ' LIMIT '.$limit);
}
@@ -594,13 +538,12 @@ class CI_DB_mssql_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access public
* @param string the table name
* @return string
*/
- function _truncate($table)
+ protected function _truncate($table)
{
- return "TRUNCATE ".$table;
+ return 'TRUNCATE '.$table;
}
// --------------------------------------------------------------------
@@ -610,31 +553,26 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
- function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
-
if (count($where) > 0 OR count($like) > 0)
{
- $conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions .= "\nWHERE ".implode("\n", $this->ar_where);
if (count($where) > 0 && count($like) > 0)
{
- $conditions .= " AND ";
+ $conditions .= ' AND ';
}
$conditions .= implode("\n", $like);
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- return "DELETE FROM ".$table.$conditions.$limit;
+ return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit);
}
// --------------------------------------------------------------------
@@ -644,17 +582,14 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access public
* @param string the sql query string
* @param integer the number of rows to limit the query to
* @param integer the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
- $i = $limit + $offset;
-
- return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql);
+ return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.($limit + $offset).' ', $sql);
}
// --------------------------------------------------------------------
@@ -662,18 +597,15 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
* @param resource
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
@mssql_close($conn_id);
}
}
-
-
/* End of file mssql_driver.php */
-/* Location: ./system/database/drivers/mssql/mssql_driver.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/mssql/mssql_driver.php */
diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php
index dd8aa3448..65513f437 100644
--- a/system/database/drivers/mssql/mssql_forge.php
+++ b/system/database/drivers/mssql/mssql_forge.php
@@ -1,13 +1,13 @@
-db->_escape_identifiers($table);
+ return 'DROP TABLE '.$this->db->_escape_identifiers($table);
}
// --------------------------------------------------------------------
@@ -80,15 +76,14 @@ class CI_DB_mssql_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param array the fields
* @param mixed primary key(s)
* @param mixed key(s)
* @param boolean should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @return string
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
@@ -97,7 +92,7 @@ class CI_DB_mssql_forge extends CI_DB_forge {
$sql .= 'IF NOT EXISTS ';
}
- $sql .= $this->db->_escape_identifiers($table)." (";
+ $sql .= $this->db->_escape_identifiers($table).'(';
$current_field_count = 0;
foreach ($fields as $field=>$attributes)
@@ -107,44 +102,19 @@ class CI_DB_mssql_forge extends CI_DB_forge {
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
- $sql .= "\n\t$attributes";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
-
- $sql .= ' '.$attributes['TYPE'];
-
- if (array_key_exists('CONSTRAINT', $attributes))
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
-
- if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (array_key_exists('DEFAULT', $attributes))
- {
- $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
- }
-
- if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
+ $sql .= "\n\t".$this->db->protect_identifiers($field)
+ .' '.$attributes['TYPE']
+ .(array_key_exists('CONSTRAINT', $attributes) ? '('.$attributes['CONSTRAINT'].')' : '')
+ .((array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
+ .(array_key_exists('DEFAULT', $attributes) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '')
+ .((array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .((array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
}
// don't add a comma on the end of the last field
@@ -156,8 +126,8 @@ class CI_DB_mssql_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
+ $primary_keys = $this->db->protect_identifiers($primary_keys);
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -166,20 +136,18 @@ class CI_DB_mssql_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key = $this->db->_protect_identifiers($key);
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key = array($this->db->_protect_identifiers($key));
+ $key = array($this->db->protect_identifiers($key));
}
- $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
}
}
- $sql .= "\n)";
-
- return $sql;
+ return $sql."\n)";
}
// --------------------------------------------------------------------
@@ -190,7 +158,6 @@ class CI_DB_mssql_forge extends CI_DB_forge {
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
- * @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param string the table name
@@ -200,39 +167,20 @@ class CI_DB_mssql_forge extends CI_DB_forge {
* @param string the field after which we should add the new field
* @return object
*/
- function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
+ $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name);
// DROP has everything it needs now.
- if ($alter_type == 'DROP')
+ if ($alter_type === 'DROP')
{
return $sql;
}
- $sql .= " $column_definition";
-
- if ($default_value != '')
- {
- $sql .= " DEFAULT \"$default_value\"";
- }
-
- if ($null === NULL)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if ($after_field != '')
- {
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
- }
-
- return $sql;
-
+ return $sql.' '.$column_definition
+ .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '')
+ .($null === NULL ? ' NULL' : ' NOT NULL')
+ .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : '');
}
// --------------------------------------------------------------------
@@ -242,19 +190,17 @@ class CI_DB_mssql_forge extends CI_DB_forge {
*
* Generates a platform-specific query so that a table can be renamed
*
- * @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
- function _rename_table($table_name, $new_table_name)
+ public function _rename_table($table_name, $new_table_name)
{
// I think this syntax will work, but can find little documentation on renaming tables in MSSQL
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
}
}
/* End of file mssql_forge.php */
-/* Location: ./system/database/drivers/mssql/mssql_forge.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/mssql/mssql_forge.php */
diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php
index bba2e6243..579cd3de7 100644
--- a/system/database/drivers/mssql/mssql_result.php
+++ b/system/database/drivers/mssql/mssql_result.php
@@ -1,13 +1,13 @@
-result_id);
}
@@ -54,10 +51,9 @@ class CI_DB_mssql_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @mssql_num_fields($this->result_id);
}
@@ -69,10 +65,9 @@ class CI_DB_mssql_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
while ($field = mssql_fetch_field($this->result_id))
@@ -90,20 +85,19 @@ class CI_DB_mssql_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
while ($field = mssql_fetch_field($this->result_id))
{
- $F = new stdClass();
- $F->name = $field->name;
- $F->type = $field->type;
+ $F = new stdClass();
+ $F->name = $field->name;
+ $F->type = $field->type;
$F->max_length = $field->max_length;
$F->primary_key = 0;
- $F->default = '';
+ $F->default = '';
$retval[] = $F;
}
@@ -116,9 +110,9 @@ class CI_DB_mssql_result extends CI_DB_result {
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
if (is_resource($this->result_id))
{
@@ -132,14 +126,13 @@ class CI_DB_mssql_result extends CI_DB_result {
/**
* Data Seek
*
- * Moves the internal pointer to the desired offset. We call
+ * Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
* @return array
*/
- function _data_seek($n = 0)
+ public function _data_seek($n = 0)
{
return mssql_data_seek($this->result_id, $n);
}
@@ -151,10 +144,9 @@ class CI_DB_mssql_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return mssql_fetch_assoc($this->result_id);
}
@@ -166,16 +158,14 @@ class CI_DB_mssql_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
return mssql_fetch_object($this->result_id);
}
}
-
/* End of file mssql_result.php */
-/* Location: ./system/database/drivers/mssql/mssql_result.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/mssql/mssql_result.php */
diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php
index be6ed5bb0..11a1b3ad0 100644
--- a/system/database/drivers/mssql/mssql_utility.php
+++ b/system/database/drivers/mssql/mssql_utility.php
@@ -1,13 +1,13 @@
-db->protect_identifiers($table).' REORGANIZE';
}
// --------------------------------------------------------------------
@@ -70,13 +67,13 @@ class CI_DB_mssql_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be repaired
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
- return FALSE; // Is this supported in MS SQL?
+ // Not supported in MSSQL
+ return FALSE;
}
// --------------------------------------------------------------------
@@ -84,11 +81,10 @@ class CI_DB_mssql_utility extends CI_DB_utility {
/**
* MSSQL Export
*
- * @access private
* @param array Preferences
- * @return mixed
+ * @return bool
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');
@@ -97,4 +93,4 @@ class CI_DB_mssql_utility extends CI_DB_utility {
}
/* End of file mssql_utility.php */
-/* Location: ./system/database/drivers/mssql/mssql_utility.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/mssql/mssql_utility.php */
--
cgit v1.2.3-24-g4f1b
From 8c1b269b1a53f4ace1e7e549fa2c7781cc9f09e9 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Wed, 25 Jan 2012 22:05:49 +0200
Subject: Update the changelog
---
user_guide_src/source/changelog.rst | 1 +
1 file changed, 1 insertion(+)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 48011f208..a1b1ccbf2 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -47,6 +47,7 @@ Release Date: Not Released
get_compiled_insert(), get_compiled_update(), get_compiled_delete().
- Taking care of LIKE condition when used with MySQL UPDATE statement.
- Adding $escape parameter to the order_by function, this enables ordering by custom fields.
+ - Added random ordering support to the MSSQL driver.
- Libraries
--
cgit v1.2.3-24-g4f1b
From dd7242b9e78f5ca9e56ffe239c14918903d34cd8 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 26 Jan 2012 00:43:38 +0200
Subject: Switch a few properties from public to protected
---
system/database/drivers/mssql/mssql_driver.php | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 9cabe87be..267c16171 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -43,19 +43,19 @@ class CI_DB_mssql_driver extends CI_DB {
public $dbdriver = 'mssql';
// The character used for escaping
- public $_escape_char = '';
+ protected $_escape_char = '';
// clause and character used for LIKE escape sequences
- public $_like_escape_str = ' ESCAPE \'%s\' ';
- public $_like_escape_chr = '!';
+ protected $_like_escape_str = ' ESCAPE \'%s\' ';
+ protected $_like_escape_chr = '!';
/**
* The syntax to count rows is slightly different across different
* database engines, so this string appears in each driver and is
* used for the count_all() and count_all_results() methods.
*/
- public $_count_string = 'SELECT COUNT(*) AS ';
- public $_random_keyword = ' NEWID()';
+ protected $_count_string = 'SELECT COUNT(*) AS ';
+ protected $_random_keyword = ' NEWID()';
/**
* Non-persistent database connection
--
cgit v1.2.3-24-g4f1b
From 3318ab87718775289264c5f42edfd9f912632dd8 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 26 Jan 2012 01:59:08 +0200
Subject: Make _escape_identifiers() public, so DB_forge can use it
---
system/database/drivers/mssql/mssql_driver.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 267c16171..22ed0478e 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -436,7 +436,7 @@ class CI_DB_mssql_driver extends CI_DB {
* @param string
* @return string
*/
- protected function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
--
cgit v1.2.3-24-g4f1b
From 0e8968ab7c309d17cd61079f7554ced1411a8792 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 26 Jan 2012 02:04:37 +0200
Subject: Improve the SQLSRV (MSSQL) database driver
---
system/database/DB_driver.php | 2 +-
system/database/drivers/sqlsrv/sqlsrv_driver.php | 285 +++++++++-------------
system/database/drivers/sqlsrv/sqlsrv_forge.php | 138 ++++-------
system/database/drivers/sqlsrv/sqlsrv_result.php | 62 ++---
system/database/drivers/sqlsrv/sqlsrv_utility.php | 39 ++-
5 files changed, 207 insertions(+), 319 deletions(-)
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 661b42ced..82e5d0486 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -257,7 +257,7 @@ class CI_DB_driver {
// Some DBs have functions that return the version, and don't run special
// SQL queries per se. In these instances, just return the result.
- $driver_version_exceptions = array('oci8', 'sqlite', 'cubrid', 'pdo');
+ $driver_version_exceptions = array('oci8', 'sqlite', 'cubrid', 'pdo', 'sqlsrv');
if (in_array($this->dbdriver, $driver_version_exceptions))
{
diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php
index 6fd52ef70..cdd178261 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_driver.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -1,13 +1,13 @@
-char_set)) ? 'UTF-8' : $this->char_set;
$connection = array(
- 'UID' => empty($this->username) ? '' : $this->username,
- 'PWD' => empty($this->password) ? '' : $this->password,
- 'Database' => $this->database,
- 'ConnectionPooling' => $pooling ? 1 : 0,
+ 'UID' => empty($this->username) ? '' : $this->username,
+ 'PWD' => empty($this->password) ? '' : $this->password,
+ 'Database' => $this->database,
+ 'ConnectionPooling' => $pooling ? 1 : 0,
'CharacterSet' => $character_set,
- 'ReturnDatesAsStrings' => 1
+ 'ReturnDatesAsStrings' => 1
);
-
- // If the username and password are both empty, assume this is a
+
+ // If the username and password are both empty, assume this is a
// 'Windows Authentication Mode' connection.
- if(empty($connection['UID']) && empty($connection['PWD'])) {
+ if (empty($connection['UID']) && empty($connection['PWD']))
+ {
unset($connection['UID'], $connection['PWD']);
}
@@ -93,10 +91,9 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_pconnect()
+ public function db_pconnect()
{
return $this->db_connect(TRUE);
}
@@ -109,12 +106,11 @@ class CI_DB_sqlsrv_driver extends CI_DB {
* Keep / reestablish the db connection if no queries have been
* sent for a length of time exceeding the server's idle timeout
*
- * @access public
* @return void
*/
- function reconnect()
+ public function reconnect()
{
- // not implemented in MSSQL
+ // Not supported in MSSQL
}
// --------------------------------------------------------------------
@@ -122,10 +118,9 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
* @return resource
*/
- function db_select()
+ public function db_select()
{
return $this->_execute('USE ' . $this->database);
}
@@ -135,14 +130,13 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Set client character set
*
- * @access public
* @param string
* @param string
- * @return resource
+ * @return bool
*/
- function db_set_charset($charset, $collation)
+ public function db_set_charset($charset, $collation)
{
- // @todo - add support if needed
+ // This is done upon connect
return TRUE;
}
@@ -151,17 +145,13 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
* @return resource
*/
- function _execute($sql)
+ protected function _execute($sql)
{
- $sql = $this->_prep_query($sql);
- return sqlsrv_query($this->conn_id, $sql, null, array(
- 'Scrollable' => SQLSRV_CURSOR_STATIC,
- 'SendStreamParamsAtExec' => true
- ));
+ return sqlsrv_query($this->conn_id, $this->_prep_query($sql), NULL,
+ array('Scrollable' => SQLSRV_CURSOR_STATIC, 'SendStreamParamsAtExec' => TRUE));
}
// --------------------------------------------------------------------
@@ -171,11 +161,10 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* If needed, each database adapter can prep the query string
*
- * @access private called by execute()
* @param string an SQL query
* @return string
*/
- function _prep_query($sql)
+ protected function _prep_query($sql)
{
return $sql;
}
@@ -185,18 +174,12 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -204,7 +187,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
// Reset the transaction failure flag.
// If the $test_mode flag is set to TRUE transactions will be rolled back
// even if the queries produce a successful result.
- $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
+ $this->_trans_failure = ($test_mode === TRUE);
return sqlsrv_begin_transaction($this->conn_id);
}
@@ -214,18 +197,12 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -238,18 +215,12 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -262,12 +233,11 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Escape String
*
- * @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
+ public function escape_str($str, $like = FALSE)
{
// Escape single quotes
return str_replace("'", "''", $str);
@@ -278,10 +248,9 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
return @sqlrv_rows_affected($this->conn_id);
}
@@ -293,30 +262,13 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Returns the last id created in the Identity column.
*
- * @access public
- * @return integer
- */
- function insert_id()
- {
- return $this->query('select @@IDENTITY as insert_id')->row('insert_id');
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Parse major version
- *
- * Grabs the major version number from the
- * database server version string passed in.
- *
- * @access private
- * @param string $version
- * @return int16 major version number
+ * @return int
*/
- function _parse_major_version($version)
+ public function insert_id()
{
- preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $version, $ver_info);
- return $ver_info[1]; // return the major version b/c that's all we're interested in.
+ $query = $this->query('SELECT @@IDENTITY AS insert_id');
+ $query = $query->row();
+ return $query->insert_id;
}
// --------------------------------------------------------------------
@@ -324,13 +276,12 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Version number query string
*
- * @access public
- * @return string
+ * @return string
*/
- function _version()
+ protected function _version()
{
$info = sqlsrv_server_info($this->conn_id);
- return sprintf("select '%s' as ver", $info['SQLServerVersion']);
+ return $info['SQLServerVersion'];
}
// --------------------------------------------------------------------
@@ -341,23 +292,25 @@ class CI_DB_sqlsrv_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
* @param string
- * @return string
+ * @return int
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
- return '0';
-
- $query = $this->query("SELECT COUNT(*) AS numrows FROM " . $this->dbprefix . $table);
-
- if ($query->num_rows() == 0)
- return '0';
-
- $row = $query->row();
+ {
+ return 0;
+ }
+
+ $query = $this->query('SELECT COUNT(*) AS numrows FROM '.$this->dbprefix.$table);
+ if ($query->num_rows() === 0)
+ {
+ return 0;
+ }
+
+ $query = $query->row();
$this->_reset_select();
- return $row->numrows;
+ return (int) $query->numrows;
}
// --------------------------------------------------------------------
@@ -367,11 +320,10 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access private
- * @param boolean
+ * @param bool
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
}
@@ -383,11 +335,10 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access private
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->_escape_table($table)."'";
}
@@ -399,13 +350,12 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
* @return object
*/
- function _field_data($table)
+ protected function _field_data($table)
{
- return "SELECT TOP 1 * FROM " . $this->_escape_table($table);
+ return 'SELECT TOP 1 * FROM '.$this->_escape_table($table);
}
// --------------------------------------------------------------------
@@ -413,13 +363,18 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* The error message string
*
- * @access private
* @return string
*/
- function _error_message()
+ protected function _error_message()
{
- $error = array_shift(sqlsrv_errors());
- return !empty($error['message']) ? $error['message'] : null;
+ $error = sqlsrv_errors();
+ if ( ! is_array($error))
+ {
+ return '';
+ }
+
+ $error = array_shift($error);
+ return isset($error['message']) ? $error['message'] : '';
}
// --------------------------------------------------------------------
@@ -427,13 +382,29 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* The error message number
*
- * @access private
- * @return integer
+ * @return string
*/
- function _error_number()
+ protected function _error_number()
{
- $error = array_shift(sqlsrv_errors());
- return isset($error['SQLSTATE']) ? $error['SQLSTATE'] : null;
+ $error = sqlsrv_errors();
+ if ( ! is_array($error))
+ {
+ return '';
+ }
+ elseif (isset($error['SQLSTATE'], $error['code']))
+ {
+ return $error['SQLSTATE'].'/'.$error['code'];
+ }
+ elseif (isset($error['SQLSTATE']))
+ {
+ return $error['SQLSTATE'];
+ }
+ elseif (isset($error['code']))
+ {
+ return $error['code'];
+ }
+
+ return '';
}
// --------------------------------------------------------------------
@@ -444,26 +415,23 @@ class CI_DB_sqlsrv_driver extends CI_DB {
* This function adds backticks if the table name has a period
* in it. Some DBs will get cranky unless periods are escaped
*
- * @access private
* @param string the table name
* @return string
*/
- function _escape_table($table)
+ protected function _escape_table($table)
{
return $table;
- }
-
+ }
/**
* Escape the SQL Identifiers
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
return $item;
}
@@ -476,11 +444,10 @@ class CI_DB_sqlsrv_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access public
- * @param type
- * @return type
+ * @param array
+ * @return string
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -497,15 +464,14 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert($table, $keys, $values)
- {
- return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ protected function _insert($table, $keys, $values)
+ {
+ return 'INSERT INTO '.$this->_escape_table($table).' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -515,7 +481,6 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -523,16 +488,16 @@ class CI_DB_sqlsrv_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where)
+ protected function _update($table, $values, $where)
{
- foreach($values as $key => $val)
+ foreach ($values as $key => $val)
{
- $valstr[] = $key." = ".$val;
+ $valstr[] = $key.' = '.$val;
}
-
- return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where);
+
+ return 'UPDATE '.$this->_escape_table($table).' SET '.implode(', ', $valstr).' WHERE '.implode(' ', $where);
}
-
+
// --------------------------------------------------------------------
/**
@@ -542,13 +507,12 @@ class CI_DB_sqlsrv_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access public
* @param string the table name
* @return string
*/
- function _truncate($table)
+ protected function _truncate($table)
{
- return "TRUNCATE ".$table;
+ return 'TRUNCATE '.$table;
}
// --------------------------------------------------------------------
@@ -558,15 +522,14 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
- function _delete($table, $where)
+ protected function _delete($table, $where)
{
- return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where);
+ return 'DELETE FROM '.$this->_escape_table($table).' WHERE '.implode(' ', $where);
}
// --------------------------------------------------------------------
@@ -576,17 +539,14 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access public
* @param string the sql query string
* @param integer the number of rows to limit the query to
* @param integer the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
- $i = $limit + $offset;
-
- return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql);
+ return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.($limit + $offset).' ', $sql);
}
// --------------------------------------------------------------------
@@ -594,18 +554,15 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
* @param resource
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
@sqlsrv_close($conn_id);
}
}
-
-
-/* End of file mssql_driver.php */
-/* Location: ./system/database/drivers/mssql/mssql_driver.php */
\ No newline at end of file
+/* End of file sqlsrv_driver.php */
+/* Location: ./system/database/drivers/sqlsrv/sqlsrv_driver.php */
diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php
index 2a7766927..1367ddc77 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_forge.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php
@@ -1,13 +1,13 @@
-db->_escape_identifiers($table);
+ return 'DROP TABLE '.$this->db->_escape_identifiers($table);
}
// --------------------------------------------------------------------
@@ -80,15 +76,14 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param array the fields
* @param mixed primary key(s)
* @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @param bool should 'IF NOT EXISTS' be added to the SQL
+ * @return string
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
@@ -97,54 +92,29 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
$sql .= 'IF NOT EXISTS ';
}
- $sql .= $this->db->_escape_identifiers($table)." (";
+ $sql .= $this->db->_escape_identifiers($table).' (';
$current_field_count = 0;
- foreach ($fields as $field=>$attributes)
+ foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
// numeric, we know it was assigned by PHP and the developer manually
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
- $sql .= "\n\t$attributes";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
-
- $sql .= ' '.$attributes['TYPE'];
-
- if (array_key_exists('CONSTRAINT', $attributes))
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
-
- if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (array_key_exists('DEFAULT', $attributes))
- {
- $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
- }
-
- if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
+ $sql .= "\n\t".$this->db->protect_identifiers($field)
+ .' '.$attributes['TYPE']
+ .(array_key_exists('CONSTRAINT', $attributes) ? '('.$attributes['CONSTRAINT'].')' : '')
+ .((array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
+ .(array_key_exists('DEFAULT', $attributes) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '')
+ .((array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .((array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
}
// don't add a comma on the end of the last field
@@ -156,8 +126,8 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
+ $primary_keys = $this->db->protect_identifiers($primary_keys);
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -166,20 +136,18 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key = $this->db->_protect_identifiers($key);
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key = array($this->db->_protect_identifiers($key));
+ $key = array($this->db->protect_identifiers($key));
}
- $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
}
}
- $sql .= "\n)";
-
- return $sql;
+ return $sql."\n)";
}
// --------------------------------------------------------------------
@@ -190,7 +158,6 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
- * @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param string the table name
@@ -200,9 +167,9 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
* @param string the field after which we should add the new field
* @return object
*/
- function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
+ $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table).' '.$alter_type.' '.$this->db->_protect_identifiers($column_name);
// DROP has everything it needs now.
if ($alter_type == 'DROP')
@@ -210,29 +177,10 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
return $sql;
}
- $sql .= " $column_definition";
-
- if ($default_value != '')
- {
- $sql .= " DEFAULT \"$default_value\"";
- }
-
- if ($null === NULL)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if ($after_field != '')
- {
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
- }
-
- return $sql;
-
+ return $sql.' '.$column_definition
+ .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '')
+ .($null === NULL ? ' NULL' : ' NOT NULL')
+ .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : '');
}
// --------------------------------------------------------------------
@@ -242,19 +190,17 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
*
* Generates a platform-specific query so that a table can be renamed
*
- * @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
- function _rename_table($table_name, $new_table_name)
+ public function _rename_table($table_name, $new_table_name)
{
// I think this syntax will work, but can find little documentation on renaming tables in MSSQL
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
}
}
-/* End of file mssql_forge.php */
-/* Location: ./system/database/drivers/mssql/mssql_forge.php */
\ No newline at end of file
+/* End of file sqlsrv_forge.php */
+/* Location: ./system/database/drivers/sqlsrv/sqlsrv_forge.php */
diff --git a/system/database/drivers/sqlsrv/sqlsrv_result.php b/system/database/drivers/sqlsrv/sqlsrv_result.php
index 1ee19c2d1..c5f9093db 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_result.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_result.php
@@ -1,13 +1,13 @@
-result_id);
}
@@ -54,10 +51,9 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @sqlsrv_num_fields($this->result_id);
}
@@ -69,17 +65,16 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
- foreach(sqlsrv_field_metadata($this->result_id) as $offset => $field)
+ foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field)
{
$field_names[] = $field['Name'];
}
-
+
return $field_names;
}
@@ -90,24 +85,23 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
- foreach(sqlsrv_field_metadata($this->result_id) as $offset => $field)
+ foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field)
{
- $F = new stdClass();
- $F->name = $field['Name'];
- $F->type = $field['Type'];
+ $F = new stdClass();
+ $F->name = $field['Name'];
+ $F->type = $field['Type'];
$F->max_length = $field['Size'];
$F->primary_key = 0;
- $F->default = '';
-
+ $F->default = '';
+
$retval[] = $F;
}
-
+
return $retval;
}
@@ -116,9 +110,9 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
if (is_resource($this->result_id))
{
@@ -136,10 +130,9 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
- * @return array
+ * @return void
*/
- function _data_seek($n = 0)
+ protected function _data_seek($n = 0)
{
// Not implemented
}
@@ -151,10 +144,9 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return sqlsrv_fetch_array($this->result_id, SQLSRV_FETCH_ASSOC);
}
@@ -166,16 +158,14 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
return sqlsrv_fetch_object($this->result_id);
}
}
-
-/* End of file mssql_result.php */
-/* Location: ./system/database/drivers/mssql/mssql_result.php */
\ No newline at end of file
+/* End of file sqlsrv_result.php */
+/* Location: ./system/database/drivers/sqlsrv/sqlsrv_result.php */
diff --git a/system/database/drivers/sqlsrv/sqlsrv_utility.php b/system/database/drivers/sqlsrv/sqlsrv_utility.php
index e96df96f9..d2a421208 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_utility.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_utility.php
@@ -1,13 +1,13 @@
-db->protect_identifiers($table).' REORGANIZE';
}
// --------------------------------------------------------------------
@@ -70,13 +66,13 @@ class CI_DB_sqlsrv_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be repaired
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
- return FALSE; // Is this supported in MS SQL?
+ // Not supported in MSSQL
+ return FALSE;
}
// --------------------------------------------------------------------
@@ -84,11 +80,10 @@ class CI_DB_sqlsrv_utility extends CI_DB_utility {
/**
* MSSQL Export
*
- * @access private
* @param array Preferences
- * @return mixed
+ * @return bool
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');
@@ -96,5 +91,5 @@ class CI_DB_sqlsrv_utility extends CI_DB_utility {
}
-/* End of file mssql_utility.php */
-/* Location: ./system/database/drivers/mssql/mssql_utility.php */
\ No newline at end of file
+/* End of file sqlsrv_utility.php */
+/* Location: ./system/database/drivers/sqlsrv/sqlsrv_utility.php */
--
cgit v1.2.3-24-g4f1b
From b7a47a7b934b2771561c1cefcfc74aeada90e352 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 26 Jan 2012 02:13:33 +0200
Subject: A minor improvement to insert_id()
---
system/database/drivers/mssql/mssql_driver.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 22ed0478e..4d29920d6 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -280,13 +280,13 @@ class CI_DB_mssql_driver extends CI_DB {
*/
public function insert_id()
{
- $sql = (self::_parse_major_version($this->version()) > 7)
+ $query = (self::_parse_major_version($this->version()) > 7)
? 'SELECT SCOPE_IDENTITY() AS last_id'
: 'SELECT @@IDENTITY AS last_id';
- $query = $this->query($sql);
- $row = $query->row();
- return $row->last_id;
+ $query = $this->query($query);
+ $query = $query->row();
+ return $query->last_id;
}
// --------------------------------------------------------------------
--
cgit v1.2.3-24-g4f1b
From d90387867fbc8e1d10058cf65805a7ae5c8cbaeb Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 26 Jan 2012 12:38:49 +0200
Subject: Improve the SQLite database driver
---
system/database/drivers/sqlite/sqlite_driver.php | 238 ++++++++--------------
system/database/drivers/sqlite/sqlite_forge.php | 151 ++++----------
system/database/drivers/sqlite/sqlite_result.php | 76 +++----
system/database/drivers/sqlite/sqlite_utility.php | 37 ++--
4 files changed, 171 insertions(+), 331 deletions(-)
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index 28c3caecd..96458e032 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -1,13 +1,13 @@
-database, FILE_WRITE_MODE, $error))
{
@@ -89,10 +84,9 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_pconnect()
+ public function db_pconnect()
{
if ( ! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error))
{
@@ -117,12 +111,11 @@ class CI_DB_sqlite_driver extends CI_DB {
* Keep / reestablish the db connection if no queries have been
* sent for a length of time exceeding the server's idle timeout
*
- * @access public
* @return void
*/
- function reconnect()
+ public function reconnect()
{
- // not implemented in SQLite
+ // Not supported in SQLite
}
// --------------------------------------------------------------------
@@ -130,11 +123,11 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
- * @return resource
+ * @return bool
*/
- function db_select()
+ public function db_select()
{
+ // Not needed, in SQLite every pseudo-connection is a database
return TRUE;
}
@@ -143,14 +136,13 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Set client character set
*
- * @access public
* @param string
* @param string
- * @return resource
+ * @return bool
*/
- function db_set_charset($charset, $collation)
+ public function db_set_charset($charset, $collation)
{
- // @todo - add support if needed
+ // Not supported
return TRUE;
}
@@ -159,10 +151,9 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Version number query string
*
- * @access public
* @return string
*/
- function _version()
+ public function _version()
{
return sqlite_libversion();
}
@@ -172,13 +163,18 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
* @return resource
*/
- function _execute($sql)
+ protected function _execute($sql)
{
$sql = $this->_prep_query($sql);
+
+ if ( ! preg_match('/^(SELECT|EXPLAIN).+$/i', ltrim($sql)))
+ {
+ return @sqlite_exec($this->conn_id, $sql);
+ }
+
return @sqlite_query($this->conn_id, $sql);
}
@@ -189,11 +185,10 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* If needed, each database adapter can prep the query string
*
- * @access private called by execute()
* @param string an SQL query
* @return string
*/
- function _prep_query($sql)
+ protected function _prep_query($sql)
{
return $sql;
}
@@ -203,18 +198,12 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -222,7 +211,7 @@ class CI_DB_sqlite_driver extends CI_DB {
// Reset the transaction failure flag.
// If the $test_mode flag is set to TRUE transactions will be rolled back
// even if the queries produce a successful result.
- $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
+ $this->_trans_failure = ($test_mode === TRUE);
$this->simple_query('BEGIN TRANSACTION');
return TRUE;
@@ -233,18 +222,12 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -258,18 +241,12 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -283,12 +260,11 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Escape String
*
- * @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
+ public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -305,9 +281,9 @@ class CI_DB_sqlite_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace( array('%', '_', $this->_like_escape_chr),
- array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
- $str);
+ return str_replace(array('%', '_', $this->_like_escape_chr),
+ array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
+ $str);
}
return $str;
@@ -318,10 +294,9 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
return sqlite_changes($this->conn_id);
}
@@ -331,10 +306,9 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Insert ID
*
- * @access public
- * @return integer
+ * @return int
*/
- function insert_id()
+ public function insert_id()
{
return @sqlite_last_insert_rowid($this->conn_id);
}
@@ -347,27 +321,25 @@ class CI_DB_sqlite_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
* @param string
- * @return string
+ * @return int
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
return 0;
}
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
-
+ $query = $this->query($this->_count_string.$this->_protect_identifiers('numrows').' FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
{
return 0;
}
- $row = $query->row();
+ $query = $query->row();
$this->_reset_select();
- return (int) $row->numrows;
+ return (int) $query->numrows;
}
// --------------------------------------------------------------------
@@ -377,18 +349,18 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access private
- * @param boolean
+ * @param bool
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
- $sql = "SELECT name from sqlite_master WHERE type='table'";
+ $sql = "SELECT name FROM sqlite_master WHERE type='table'";
- if ($prefix_limit !== FALSE AND $this->dbprefix != '')
+ if ($prefix_limit !== FALSE && $this->dbprefix != '')
{
- $sql .= " AND 'name' LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
+ return $sql." AND 'name' LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
}
+
return $sql;
}
@@ -399,11 +371,10 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access public
* @param string the table name
- * @return string
+ * @return bool
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
// Not supported
return FALSE;
@@ -416,13 +387,12 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
- * @return object
+ * @return string
*/
- function _field_data($table)
+ protected function _field_data($table)
{
- return "SELECT * FROM ".$table." LIMIT 1";
+ return 'SELECT * FROM '.$table.' LIMIT 1';
}
// --------------------------------------------------------------------
@@ -430,10 +400,9 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* The error message string
*
- * @access private
* @return string
*/
- function _error_message()
+ protected function _error_message()
{
return sqlite_error_string(sqlite_last_error($this->conn_id));
}
@@ -443,10 +412,9 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* The error message number
*
- * @access private
- * @return integer
+ * @return int
*/
- function _error_number()
+ protected function _error_number()
{
return sqlite_last_error($this->conn_id);
}
@@ -458,11 +426,10 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -473,24 +440,20 @@ class CI_DB_sqlite_driver extends CI_DB {
{
if (strpos($item, '.'.$id) !== FALSE)
{
- $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
+ $item = str_replace('.', $this->_escape_char.'.', $item);
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item);
}
}
if (strpos($item, '.') !== FALSE)
{
- $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
- }
- else
- {
- $str = $this->_escape_char.$item.$this->_escape_char;
+ $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
}
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char);
}
// --------------------------------------------------------------------
@@ -501,11 +464,10 @@ class CI_DB_sqlite_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access public
* @param type
* @return type
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -522,15 +484,14 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert($table, $keys, $values)
+ protected function _insert($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -540,7 +501,6 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -548,24 +508,17 @@ class CI_DB_sqlite_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
- $valstr[] = $key." = ".$val;
+ $valstr[] = $key.' = '.$val;
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
-
- $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
-
- $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
-
- $sql .= $orderby.$limit;
-
- return $sql;
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
+ .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '')
+ .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '')
+ .( ! $limit ? '' : ' LIMIT '.$limit);
}
@@ -578,11 +531,10 @@ class CI_DB_sqlite_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access public
* @param string the table name
* @return string
*/
- function _truncate($table)
+ protected function _truncate($table)
{
return $this->_delete($table);
}
@@ -594,31 +546,27 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
- function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
if (count($where) > 0 OR count($like) > 0)
{
- $conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions = "\nWHERE ".implode("\n", $this->ar_where);
if (count($where) > 0 && count($like) > 0)
{
- $conditions .= " AND ";
+ $conditions .= ' AND ';
}
$conditions .= implode("\n", $like);
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- return "DELETE FROM ".$table.$conditions.$limit;
+ return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit);
}
// --------------------------------------------------------------------
@@ -628,24 +576,14 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access public
* @param string the sql query string
- * @param integer the number of rows to limit the query to
- * @param integer the offset value
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
- if ($offset == 0)
- {
- $offset = '';
- }
- else
- {
- $offset .= ", ";
- }
-
- return $sql."LIMIT ".$offset.$limit;
+ return $sql.'LIMIT '.($offset == 0 ? '' : ', ').$limit;
}
// --------------------------------------------------------------------
@@ -653,11 +591,10 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
* @param resource
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
@sqlite_close($conn_id);
}
@@ -665,6 +602,5 @@ class CI_DB_sqlite_driver extends CI_DB {
}
-
/* End of file sqlite_driver.php */
-/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */
diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php
index 2b723be0b..8bf1f2595 100644
--- a/system/database/drivers/sqlite/sqlite_forge.php
+++ b/system/database/drivers/sqlite/sqlite_forge.php
@@ -1,13 +1,13 @@
-db->database) OR ! @unlink($this->db->database))
{
- if ($this->db->db_debug)
- {
- return $this->db->display_error('db_unable_to_drop');
- }
- return FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
}
+
return TRUE;
}
// --------------------------------------------------------------------
@@ -76,15 +69,14 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param array the fields
* @param mixed primary key(s)
* @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @param bool should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
@@ -94,54 +86,29 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
$sql .= 'IF NOT EXISTS ';
}
- $sql .= $this->db->_escape_identifiers($table)."(";
+ $sql .= $this->db->_escape_identifiers($table).'(';
$current_field_count = 0;
- foreach ($fields as $field=>$attributes)
+ foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
// numeric, we know it was assigned by PHP and the developer manually
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
- $sql .= "\n\t$attributes";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
-
- $sql .= ' '.$attributes['TYPE'];
-
- if (array_key_exists('CONSTRAINT', $attributes))
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
-
- if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (array_key_exists('DEFAULT', $attributes))
- {
- $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
- }
-
- if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
+ $sql .= "\n\t".$this->db->protect_identifiers($field)
+ .' '.$attributes['TYPE']
+ .(array_key_exists('CONSTRAINT', $attributes) ? '('.$attributes['CONSTRAINT'].')' : '')
+ .((array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
+ .(array_key_exists('DEFAULT', $attributes) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '')
+ .((array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .((array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
}
// don't add a comma on the end of the last field
@@ -153,8 +120,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->protect_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -163,20 +129,18 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key = $this->db->_protect_identifiers($key);
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key = array($this->db->_protect_identifiers($key));
+ $key = array($this->db->protect_identifiers($key));
}
- $sql .= ",\n\tUNIQUE (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tUNIQUE (".implode(', ', $key).')';
}
}
- $sql .= "\n)";
-
- return $sql;
+ return $sql."\n)";
}
// --------------------------------------------------------------------
@@ -184,18 +148,11 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
/**
* Drop Table
*
- * Unsupported feature in SQLite
- *
- * @access private
- * @return bool
+ * @return string
*/
- function _drop_table($table)
+ public function _drop_table($table)
{
- if ($this->db->db_debug)
- {
- return $this->db->display_error('db_unsuported_feature');
- }
- return array();
+ return 'DROP TABLE '.$table.' IF EXISTS';
}
// --------------------------------------------------------------------
@@ -206,7 +163,6 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
- * @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param string the table name
@@ -214,44 +170,25 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
* @param string the default value
* @param boolean should 'NOT NULL' be added
* @param string the field after which we should add the new field
- * @return object
+ * @return string
*/
- function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
-
- // DROP has everything it needs now.
- if ($alter_type == 'DROP')
+ /* SQLite only supports adding new columns and it does
+ * NOT support the AFTER statement. Each new column will
+ * be added as the last one in the table.
+ */
+ if ($alter_type !== 'ADD COLUMN')
{
- // SQLite does not support dropping columns
- // http://www.sqlite.org/omitted.html
- // http://www.sqlite.org/faq.html#q11
+ // Not supported
return FALSE;
}
- $sql .= " $column_definition";
-
- if ($default_value != '')
- {
- $sql .= " DEFAULT \"$default_value\"";
- }
-
- if ($null === NULL)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if ($after_field != '')
- {
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
- }
-
- return $sql;
-
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name)
+ .' '.$column_definition
+ .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '')
+ // If NOT NULL is specified, the field must have a DEFAULT value other than NULL
+ .(($null !== NULL && $default_value !== 'NULL') ? ' NOT NULL' : ' NULL');
}
// --------------------------------------------------------------------
@@ -261,17 +198,15 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
*
* Generates a platform-specific query so that a table can be renamed
*
- * @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
- function _rename_table($table_name, $new_table_name)
+ public function _rename_table($table_name, $new_table_name)
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
}
}
/* End of file sqlite_forge.php */
-/* Location: ./system/database/drivers/sqlite/sqlite_forge.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/sqlite/sqlite_forge.php */
diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php
index 74c0dc549..91fe57ae1 100644
--- a/system/database/drivers/sqlite/sqlite_result.php
+++ b/system/database/drivers/sqlite/sqlite_result.php
@@ -1,13 +1,13 @@
-result_id);
}
@@ -54,10 +51,9 @@ class CI_DB_sqlite_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @sqlite_num_fields($this->result_id);
}
@@ -69,13 +65,12 @@ class CI_DB_sqlite_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
- for ($i = 0; $i < $this->num_fields(); $i++)
+ for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
{
$field_names[] = sqlite_field_name($this->result_id, $i);
}
@@ -90,22 +85,19 @@ class CI_DB_sqlite_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
- for ($i = 0; $i < $this->num_fields(); $i++)
+ for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
{
- $F = new stdClass();
- $F->name = sqlite_field_name($this->result_id, $i);
- $F->type = 'varchar';
- $F->max_length = 0;
- $F->primary_key = 0;
- $F->default = '';
-
- $retval[] = $F;
+ $retval[$i] = new stdClass();
+ $retval[$i]->name = sqlite_field_name($this->result_id, $i);
+ $retval[$i]->type = 'varchar';
+ $retval[$i]->max_length = 0;
+ $retval[$i]->primary_key = 0;
+ $retval[$i]->default = '';
}
return $retval;
@@ -116,11 +108,11 @@ class CI_DB_sqlite_result extends CI_DB_result {
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
- // Not implemented in SQLite
+ // Not supported in SQLite
}
// --------------------------------------------------------------------
@@ -128,14 +120,13 @@ class CI_DB_sqlite_result extends CI_DB_result {
/**
* Data Seek
*
- * Moves the internal pointer to the desired offset. We call
+ * Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
* @return array
*/
- function _data_seek($n = 0)
+ protected function _data_seek($n = 0)
{
return sqlite_seek($this->result_id, $n);
}
@@ -147,10 +138,9 @@ class CI_DB_sqlite_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return sqlite_fetch_array($this->result_id);
}
@@ -162,30 +152,20 @@ class CI_DB_sqlite_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
if (function_exists('sqlite_fetch_object'))
{
return sqlite_fetch_object($this->result_id);
}
- else
- {
- $arr = sqlite_fetch_array($this->result_id, SQLITE_ASSOC);
- if (is_array($arr))
- {
- $obj = (object) $arr;
- return $obj;
- } else {
- return NULL;
- }
- }
+
+ $arr = sqlite_fetch_array($this->result_id, SQLITE_ASSOC);
+ return is_array($arr) ? (object) $arr : FALSE;
}
}
-
/* End of file sqlite_result.php */
-/* Location: ./system/database/drivers/sqlite/sqlite_result.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/sqlite/sqlite_result.php */
diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php
index f00687e38..358fe747f 100644
--- a/system/database/drivers/sqlite/sqlite_utility.php
+++ b/system/database/drivers/sqlite/sqlite_utility.php
@@ -1,13 +1,13 @@
-db_debug)
- {
- return $this->db->display_error('db_unsuported_feature');
- }
- return array();
+ return ($this->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
// --------------------------------------------------------------------
@@ -61,14 +54,12 @@ class CI_DB_sqlite_utility extends CI_DB_utility {
/**
* Optimize table query
*
- * Is optimization even supported in SQLite?
- *
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _optimize_table($table)
+ public function _optimize_table($table)
{
+ // Not supported
return FALSE;
}
@@ -77,14 +68,13 @@ class CI_DB_sqlite_utility extends CI_DB_utility {
/**
* Repair table query
*
- * Are table repairs even supported in SQLite?
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
+ // Not supported
return FALSE;
}
@@ -93,11 +83,10 @@ class CI_DB_sqlite_utility extends CI_DB_utility {
/**
* SQLite Export
*
- * @access private
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');
@@ -105,4 +94,4 @@ class CI_DB_sqlite_utility extends CI_DB_utility {
}
/* End of file sqlite_utility.php */
-/* Location: ./system/database/drivers/sqlite/sqlite_utility.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/sqlite/sqlite_utility.php */
--
cgit v1.2.3-24-g4f1b
From 7f55d6133b70346a428ae481d1fe57bf4d4d2320 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 26 Jan 2012 13:44:28 +0200
Subject: Improve the CUBRID database driver
---
system/database/drivers/cubrid/cubrid_driver.php | 284 ++++++++--------------
system/database/drivers/cubrid/cubrid_forge.php | 136 ++++-------
system/database/drivers/cubrid/cubrid_result.php | 68 ++----
system/database/drivers/cubrid/cubrid_utility.php | 35 +--
4 files changed, 183 insertions(+), 340 deletions(-)
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index cde719eae..1cfaf3e42 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -1,13 +1,13 @@
-port == '')
{
- $this->port = self::DEFAULT_PORT;
+ // Default CUBRID broker port
+ $this->port = 33000;
}
+ }
+ /**
+ * Non-persistent database connection
+ *
+ * @return resource
+ */
+ public function db_connect()
+ {
$conn = cubrid_connect($this->hostname, $this->port, $this->database, $this->username, $this->password);
if ($conn)
@@ -112,7 +109,7 @@ class CI_DB_cubrid_driver extends CI_DB {
* @access private called by the base class
* @return resource
*/
- function db_pconnect()
+ public function db_pconnect()
{
return $this->db_connect();
}
@@ -125,10 +122,9 @@ class CI_DB_cubrid_driver extends CI_DB {
* Keep / reestablish the db connection if no queries have been
* sent for a length of time exceeding the server's idle timeout
*
- * @access public
* @return void
*/
- function reconnect()
+ public function reconnect()
{
if (cubrid_ping($this->conn_id) === FALSE)
{
@@ -141,10 +137,9 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
* @return resource
*/
- function db_select()
+ public function db_select()
{
// In CUBRID there is no need to select a database as the database
// is chosen at the connection time.
@@ -158,12 +153,11 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Set client character set
*
- * @access public
* @param string
* @param string
- * @return resource
+ * @return bool
*/
- function db_set_charset($charset, $collation)
+ public function db_set_charset($charset, $collation)
{
// In CUBRID, there is no need to set charset or collation.
// This is why returning true will allow the application continue
@@ -176,16 +170,10 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Version number query string
*
- * @access public
* @return string
*/
- function _version()
+ protected function _version()
{
- // To obtain the CUBRID Server version, no need to run the SQL query.
- // CUBRID PHP API provides a function to determin this value.
- // This is why we also need to add 'cubrid' value to the list of
- // $driver_version_exceptions array in DB_driver class in
- // version() function.
return cubrid_get_server_info($this->conn_id);
}
@@ -194,11 +182,10 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
* @return resource
*/
- function _execute($sql)
+ protected function _execute($sql)
{
$sql = $this->_prep_query($sql);
return @cubrid_query($sql, $this->conn_id);
@@ -211,11 +198,10 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* If needed, each database adapter can prep the query string
*
- * @access private called by execute()
* @param string an SQL query
* @return string
*/
- function _prep_query($sql)
+ protected function _prep_query($sql)
{
// No need to prepare
return $sql;
@@ -226,18 +212,12 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -245,7 +225,7 @@ class CI_DB_cubrid_driver extends CI_DB {
// Reset the transaction failure flag.
// If the $test_mode flag is set to TRUE transactions will be rolled back
// even if the queries produce a successful result.
- $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
+ $this->_trans_failure = ($test_mode === TRUE);
if (cubrid_get_autocommit($this->conn_id))
{
@@ -260,18 +240,12 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -291,18 +265,12 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -322,12 +290,11 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Escape String
*
- * @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
+ public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -339,7 +306,7 @@ class CI_DB_cubrid_driver extends CI_DB {
return $str;
}
- if (function_exists('cubrid_real_escape_string') AND is_resource($this->conn_id))
+ if (function_exists('cubrid_real_escape_string') && is_resource($this->conn_id))
{
$str = cubrid_real_escape_string($str, $this->conn_id);
}
@@ -351,7 +318,7 @@ class CI_DB_cubrid_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str);
+ return str_replace(array('%', '_'), array('\\%', '\\_'), $str);
}
return $str;
@@ -362,10 +329,9 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
return @cubrid_affected_rows($this->conn_id);
}
@@ -375,10 +341,9 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Insert ID
*
- * @access public
- * @return integer
+ * @return int
*/
- function insert_id()
+ public function insert_id()
{
return @cubrid_insert_id($this->conn_id);
}
@@ -391,27 +356,24 @@ class CI_DB_cubrid_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified table
*
- * @access public
* @param string
- * @return string
+ * @return int
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
return 0;
}
-
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
-
+ $query = $this->query($this->_count_string.$this->_protect_identifiers('numrows').' FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
{
return 0;
}
- $row = $query->row();
+ $query = $query->row();
$this->_reset_select();
- return (int) $row->numrows;
+ return (int) $query->numrows;
}
// --------------------------------------------------------------------
@@ -421,17 +383,16 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access private
* @param boolean
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
- $sql = "SHOW TABLES";
+ $sql = 'SHOW TABLES';
- if ($prefix_limit !== FALSE AND $this->dbprefix != '')
+ if ($prefix_limit !== FALSE && $this->dbprefix != '')
{
- $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'";
+ return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
}
return $sql;
@@ -444,13 +405,12 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access public
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
- return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ return 'SHOW COLUMNS FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE);
}
// --------------------------------------------------------------------
@@ -460,13 +420,12 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
- * @return object
+ * @return string
*/
- function _field_data($table)
+ protected function _field_data($table)
{
- return "SELECT * FROM ".$table." LIMIT 1";
+ return 'SELECT * FROM '.$table.' LIMIT 1';
}
// --------------------------------------------------------------------
@@ -474,10 +433,9 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* The error message string
*
- * @access private
* @return string
*/
- function _error_message()
+ protected function _error_message()
{
return cubrid_error($this->conn_id);
}
@@ -487,10 +445,9 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* The error message number
*
- * @access private
- * @return integer
+ * @return int
*/
- function _error_number()
+ protected function _error_number()
{
return cubrid_errno($this->conn_id);
}
@@ -502,11 +459,10 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -517,24 +473,20 @@ class CI_DB_cubrid_driver extends CI_DB {
{
if (strpos($item, '.'.$id) !== FALSE)
{
- $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
+ $item = str_replace('.', $this->_escape_char.'.', $item);
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item);
}
}
if (strpos($item, '.') !== FALSE)
{
- $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
- }
- else
- {
- $str = $this->_escape_char.$item.$this->_escape_char;
+ $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
}
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char);
}
// --------------------------------------------------------------------
@@ -545,11 +497,10 @@ class CI_DB_cubrid_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access public
- * @param type
- * @return type
+ * @param string the table name
+ * @return string
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -566,15 +517,14 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert($table, $keys, $values)
+ protected function _insert($table, $keys, $values)
{
- return "INSERT INTO ".$table." (\"".implode('", "', $keys)."\") VALUES (".implode(', ', $values).")";
+ return 'INSERT INTO '.$table.' ("'.implode('", "', $keys).'") VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -585,15 +535,14 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific replace string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _replace($table, $keys, $values)
+ protected function _replace($table, $keys, $values)
{
- return "REPLACE INTO ".$table." (\"".implode('", "', $keys)."\") VALUES (".implode(', ', $values).")";
+ return 'REPLACE INTO '.$table.' ("'.implode('", "', $keys).'") VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -603,26 +552,23 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert_batch($table, $keys, $values)
+ protected function _insert_batch($table, $keys, $values)
{
- return "INSERT INTO ".$table." (\"".implode('", "', $keys)."\") VALUES ".implode(', ', $values);
+ return 'INSERT INTO '.$table.' ("'.implode('", "', $keys).'") VALUES '.implode(', ', $values);
}
// --------------------------------------------------------------------
-
/**
* Update statement
*
* Generates a platform-specific update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -630,24 +576,17 @@ class CI_DB_cubrid_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
$valstr[] = sprintf('"%s" = %s', $key, $val);
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
-
- $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
-
- $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
-
- $sql .= $orderby.$limit;
-
- return $sql;
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
+ .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '')
+ .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '')
+ .( ! $limit ? '' : ' LIMIT '.$limit);
}
// --------------------------------------------------------------------
@@ -658,16 +597,15 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
* @return string
*/
- function _update_batch($table, $values, $index, $where = NULL)
+ protected function _update_batch($table, $values, $index, $where = NULL)
{
$ids = array();
- $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';
+ $where = ($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '';
foreach ($values as $key => $val)
{
@@ -682,30 +620,23 @@ class CI_DB_cubrid_driver extends CI_DB {
}
}
- $sql = "UPDATE ".$table." SET ";
+ $sql = 'UPDATE '.$table.' SET ';
$cases = '';
foreach ($final as $k => $v)
{
- $cases .= $k.' = CASE '."\n";
- foreach ($v as $row)
- {
- $cases .= $row."\n";
- }
-
- $cases .= 'ELSE '.$k.' END, ';
+ $cases .= $k." = CASE \n"
+ .implode("\n", $v)
+ .'ELSE '.$k.' END, ';
}
- $sql .= substr($cases, 0, -2);
-
- $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')';
-
- return $sql;
+ return $sql.substr($cases, 0, -2)
+ .' WHERE '.(($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
+ .$index.' IN ('.implode(',', $ids).')';
}
// --------------------------------------------------------------------
-
/**
* Truncate statement
*
@@ -713,13 +644,12 @@ class CI_DB_cubrid_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access public
* @param string the table name
* @return string
*/
- function _truncate($table)
+ protected function _truncate($table)
{
- return "TRUNCATE ".$table;
+ return 'TRUNCATE '.$table;
}
// --------------------------------------------------------------------
@@ -729,31 +659,27 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
- function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
if (count($where) > 0 OR count($like) > 0)
{
- $conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions = "\nWHERE ".implode("\n", $this->ar_where);
if (count($where) > 0 && count($like) > 0)
{
- $conditions .= " AND ";
+ $conditions .= ' AND ';
}
$conditions .= implode("\n", $like);
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- return "DELETE FROM ".$table.$conditions.$limit;
+ return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit);
}
// --------------------------------------------------------------------
@@ -763,24 +689,14 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access public
* @param string the sql query string
- * @param integer the number of rows to limit the query to
- * @param integer the offset value
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
- if ($offset == 0)
- {
- $offset = '';
- }
- else
- {
- $offset .= ", ";
- }
-
- return $sql."LIMIT ".$offset.$limit;
+ return $sql.'LIMIT '.($offset == 0 ? '' : ', ').$limit;
}
// --------------------------------------------------------------------
@@ -788,17 +704,15 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
* @param resource
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
@cubrid_close($conn_id);
}
}
-
/* End of file cubrid_driver.php */
-/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */
diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php
index 85e740057..ce5aa2098 100644
--- a/system/database/drivers/cubrid/cubrid_forge.php
+++ b/system/database/drivers/cubrid/cubrid_forge.php
@@ -1,13 +1,13 @@
-$attributes)
+ foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
// numeric, we know it was assigned by PHP and the developer manually
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
- $sql .= "\n\t$attributes";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t\"" . $this->db->_protect_identifiers($field) . "\"";
-
- if (array_key_exists('NAME', $attributes))
- {
- $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' ';
- }
+ $sql .= "\n\t\"".$this->db->protect_identifiers($field).'"'
+ .(array_key_exists('NAME', $attributes) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : '');
if (array_key_exists('TYPE', $attributes))
{
@@ -113,9 +104,8 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
case 'numeric':
$sql .= '('.implode(',', $attributes['CONSTRAINT']).')';
break;
- case 'enum': // As of version 8.4.0 CUBRID does not support
- // enum data type.
- break;
+ case 'enum': // As of version 8.4.0 CUBRID does not support enum data type
+ break;
case 'set':
$sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")';
break;
@@ -125,36 +115,19 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
}
}
+ /* As of version 8.4.0 CUBRID does not support UNSIGNED INTEGER data type.
+ * Will be supported in the next release as a part of MySQL Compatibility.
+ *
if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
{
- //$sql .= ' UNSIGNED';
- // As of version 8.4.0 CUBRID does not support UNSIGNED INTEGER data type.
- // Will be supported in the next release as a part of MySQL Compatibility.
- }
-
- if (array_key_exists('DEFAULT', $attributes))
- {
- $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
- }
-
- if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
+ $sql .= ' UNSIGNED';
}
+ */
- if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
-
- if (array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE)
- {
- $sql .= ' UNIQUE';
- }
+ $sql .= (array_key_exists('DEFAULT', $attributes) ? " DEFAULT '".$attributes['DEFAULT']."'" : '')
+ .((array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .((array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '')
+ .((array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE) ? ' UNIQUE' : '');
}
// don't add a comma on the end of the last field
@@ -172,7 +145,6 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param mixed the fields
* @param mixed primary key(s)
@@ -180,28 +152,24 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
* @param boolean should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
+ /* As of version 8.4.0 CUBRID does not support this SQL syntax.
if ($if_not_exists === TRUE)
{
- //$sql .= 'IF NOT EXISTS ';
- // As of version 8.4.0 CUBRID does not support this SQL syntax.
+ $sql .= 'IF NOT EXISTS ';
}
+ */
- $sql .= $this->db->_escape_identifiers($table)." (";
-
- $sql .= $this->_process_fields($fields);
+ $sql .= $this->db->_escape_identifiers($table).' ('.$this->_process_fields($fields);
// If there is a PK defined
if (count($primary_keys) > 0)
{
- $key_name = "pk_" . $table . "_" .
- $this->db->_protect_identifiers(implode('_', $primary_keys));
-
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
- $sql .= ",\n\tCONSTRAINT " . $key_name . " PRIMARY KEY(" . implode(', ', $primary_keys) . ")";
+ $key_name = 'pk_'.$table.'_'.$this->db->protect_identifiers(implode('_', $primary_keys));
+ $sql .= ",\n\tCONSTRAINT ".$key_name.' PRIMARY KEY('.implode(', ', $this->db->protect_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -210,22 +178,20 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key_name = $this->db->_protect_identifiers(implode('_', $key));
- $key = $this->db->_protect_identifiers($key);
+ $key_name = $this->db->protect_identifiers(implode('_', $key));
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key_name = $this->db->_protect_identifiers($key);
+ $key_name = $this->db->protect_identifiers($key);
$key = array($key_name);
}
-
- $sql .= ",\n\tKEY \"{$key_name}\" (" . implode(', ', $key) . ")";
+
+ $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')';
}
}
- $sql .= "\n);";
-
- return $sql;
+ return $sql."\n);";
}
// --------------------------------------------------------------------
@@ -233,12 +199,11 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
/**
* Drop Table
*
- * @access private
* @return string
*/
- function _drop_table($table)
+ public function _drop_table($table)
{
- return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table);
+ return 'DROP TABLE IF EXISTS '.$this->db->_escape_identifiers($table);
}
// --------------------------------------------------------------------
@@ -249,31 +214,24 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
- * @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param array fields
* @param string the field after which we should add the new field
- * @return object
+ * @return string
*/
- function _alter_table($alter_type, $table, $fields, $after_field = '')
+ public function _alter_table($alter_type, $table, $fields, $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ";
+ $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' ';
// DROP has everything it needs now.
- if ($alter_type == 'DROP')
- {
- return $sql.$this->db->_protect_identifiers($fields);
- }
-
- $sql .= $this->_process_fields($fields);
-
- if ($after_field != '')
+ if ($alter_type === 'DROP')
{
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
+ return $sql.$this->db->protect_identifiers($fields);
}
- return $sql;
+ return $sql.$this->_process_fields($fields)
+ .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : '');
}
// --------------------------------------------------------------------
@@ -283,18 +241,16 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
*
* Generates a platform-specific query so that a table can be renamed
*
- * @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
- function _rename_table($table_name, $new_table_name)
+ public function _rename_table($table_name, $new_table_name)
{
- $sql = 'RENAME TABLE '.$this->db->_protect_identifiers($table_name)." AS ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'RENAME TABLE '.$this->db->protect_identifiers($table_name).' AS '.$this->db->protect_identifiers($new_table_name);
}
}
/* End of file cubrid_forge.php */
-/* Location: ./system/database/drivers/cubrid/cubrid_forge.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/cubrid/cubrid_forge.php */
diff --git a/system/database/drivers/cubrid/cubrid_result.php b/system/database/drivers/cubrid/cubrid_result.php
index 4c0fede10..7a72cdde4 100644
--- a/system/database/drivers/cubrid/cubrid_result.php
+++ b/system/database/drivers/cubrid/cubrid_result.php
@@ -1,13 +1,13 @@
-result_id);
}
@@ -54,10 +51,9 @@ class CI_DB_cubrid_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @cubrid_num_fields($this->result_id);
}
@@ -69,10 +65,9 @@ class CI_DB_cubrid_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
return cubrid_column_names($this->result_id);
}
@@ -84,21 +79,18 @@ class CI_DB_cubrid_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
- $retval = array();
-
- $tablePrimaryKeys = array();
+ $retval = $tablePrimaryKeys = array();
while ($field = cubrid_fetch_field($this->result_id))
{
- $F = new stdClass();
- $F->name = $field->name;
- $F->type = $field->type;
- $F->default = $field->def;
+ $F = new stdClass();
+ $F->name = $field->name;
+ $F->type = $field->type;
+ $F->default = $field->def;
$F->max_length = $field->max_length;
// At this moment primary_key property is not returned when
@@ -115,19 +107,18 @@ class CI_DB_cubrid_result extends CI_DB_result {
// The query will search for exact single columns, thus
// compound PK is not supported.
$res = cubrid_query($this->conn_id,
- "SELECT COUNT(*) FROM db_index WHERE class_name = '" . $field->table .
- "' AND is_primary_key = 'YES' AND index_name = 'pk_" .
- $field->table . "_" . $field->name . "'"
- );
+ "SELECT COUNT(*) FROM db_index WHERE class_name = '".$field->table
+ ."' AND is_primary_key = 'YES' AND index_name = 'pk_".$field->table.'_'.$field->name."'"
+ );
if ($res)
{
$row = cubrid_fetch_array($res, CUBRID_NUM);
- $F->primary_key = ($row[0] > 0 ? 1 : null);
+ $F->primary_key = ($row[0] > 0 ? 1 : NULL);
}
else
{
- $F->primary_key = null;
+ $F->primary_key = NULL;
}
if (is_resource($res))
@@ -147,13 +138,12 @@ class CI_DB_cubrid_result extends CI_DB_result {
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
- if(is_resource($this->result_id) ||
- get_resource_type($this->result_id) == "Unknown" &&
- preg_match('/Resource id #/', strval($this->result_id)))
+ if (is_resource($this->result_id) OR
+ (get_resource_type($this->result_id) === 'Unknown' && preg_match('/Resource id #/', strval($this->result_id))))
{
cubrid_close_request($this->result_id);
$this->result_id = FALSE;
@@ -169,10 +159,9 @@ class CI_DB_cubrid_result extends CI_DB_result {
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
* @return array
*/
- function _data_seek($n = 0)
+ protected function _data_seek($n = 0)
{
return cubrid_data_seek($this->result_id, $n);
}
@@ -184,10 +173,9 @@ class CI_DB_cubrid_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return cubrid_fetch_assoc($this->result_id);
}
@@ -199,16 +187,14 @@ class CI_DB_cubrid_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
return cubrid_fetch_object($this->result_id);
}
}
-
/* End of file cubrid_result.php */
-/* Location: ./system/database/drivers/cubrid/cubrid_result.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/cubrid/cubrid_result.php */
diff --git a/system/database/drivers/cubrid/cubrid_utility.php b/system/database/drivers/cubrid/cubrid_utility.php
index 750c0d8dd..dbfbe5f6b 100644
--- a/system/database/drivers/cubrid/cubrid_utility.php
+++ b/system/database/drivers/cubrid/cubrid_utility.php
@@ -1,13 +1,13 @@
-conn_id)
- {
- return "SELECT '" . $this->database . "'";
- }
- else
- {
- return FALSE;
- }
+ return "SELECT '".$this->database."'";
}
// --------------------------------------------------------------------
@@ -66,12 +56,11 @@ class CI_DB_cubrid_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be optimized
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
* @link http://www.cubrid.org/manual/840/en/Optimize%20Database
*/
- function _optimize_table($table)
+ public function _optimize_table($table)
{
// No SQL based support in CUBRID as of version 8.4.0. Database or
// table optimization can be performed using CUBRID Manager
@@ -86,12 +75,11 @@ class CI_DB_cubrid_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be repaired
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
* @link http://www.cubrid.org/manual/840/en/Checking%20Database%20Consistency
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
// Not supported in CUBRID as of version 8.4.0. Database or
// table consistency can be checked using CUBRID Manager
@@ -103,11 +91,10 @@ class CI_DB_cubrid_utility extends CI_DB_utility {
/**
* CUBRID Export
*
- * @access private
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
// No SQL based support in CUBRID as of version 8.4.0. Database or
// table backup can be performed using CUBRID Manager
@@ -117,4 +104,4 @@ class CI_DB_cubrid_utility extends CI_DB_utility {
}
/* End of file cubrid_utility.php */
-/* Location: ./system/database/drivers/cubrid/cubrid_utility.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/cubrid/cubrid_utility.php */
--
cgit v1.2.3-24-g4f1b
From 69a6093da35640482a8394ca66686e045304b0e3 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 26 Jan 2012 14:04:06 +0200
Subject: Replace array_key_exists() with isset() and ! empty()
---
system/database/drivers/cubrid/cubrid_forge.php | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php
index ce5aa2098..d277ca394 100644
--- a/system/database/drivers/cubrid/cubrid_forge.php
+++ b/system/database/drivers/cubrid/cubrid_forge.php
@@ -89,13 +89,13 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
$attributes = array_change_key_case($attributes, CASE_UPPER);
$sql .= "\n\t\"".$this->db->protect_identifiers($field).'"'
- .(array_key_exists('NAME', $attributes) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : '');
+ .(isset($attributes['NAME']) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : '');
- if (array_key_exists('TYPE', $attributes))
+ if ( ! empty($attributes['TYPE']))
{
$sql .= ' '.$attributes['TYPE'];
- if (array_key_exists('CONSTRAINT', $attributes))
+ if (isset($attributes['CONSTRAINT']))
{
switch ($attributes['TYPE'])
{
@@ -118,16 +118,16 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
/* As of version 8.4.0 CUBRID does not support UNSIGNED INTEGER data type.
* Will be supported in the next release as a part of MySQL Compatibility.
*
- if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
+ if (isset($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
{
$sql .= ' UNSIGNED';
}
*/
- $sql .= (array_key_exists('DEFAULT', $attributes) ? " DEFAULT '".$attributes['DEFAULT']."'" : '')
- .((array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
- .((array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '')
- .((array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE) ? ' UNIQUE' : '');
+ $sql .= (isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '')
+ .((isset($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .((isset($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '')
+ .((isset($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) ? ' UNIQUE' : '');
}
// don't add a comma on the end of the last field
--
cgit v1.2.3-24-g4f1b
From fb86295d7d49e7ddfba266fe9f7305fb44708d4f Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 26 Jan 2012 14:08:47 +0200
Subject: Replace array_key_exists() with isset() and ! empty()
---
system/database/drivers/mssql/mssql_forge.php | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php
index 65513f437..231284c7c 100644
--- a/system/database/drivers/mssql/mssql_forge.php
+++ b/system/database/drivers/mssql/mssql_forge.php
@@ -110,11 +110,11 @@ class CI_DB_mssql_forge extends CI_DB_forge {
$sql .= "\n\t".$this->db->protect_identifiers($field)
.' '.$attributes['TYPE']
- .(array_key_exists('CONSTRAINT', $attributes) ? '('.$attributes['CONSTRAINT'].')' : '')
- .((array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
- .(array_key_exists('DEFAULT', $attributes) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '')
- .((array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
- .((array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
+ .(isset($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '')
+ .((isset($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
+ .(isset($attributes['DEFAULT']) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '')
+ .((isset($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .((isset($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
}
// don't add a comma on the end of the last field
--
cgit v1.2.3-24-g4f1b
From 20ebf1459b6dc1449a545156b70e7cb2932fa9eb Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 26 Jan 2012 14:14:02 +0200
Subject: Replace array_key_exists() with isset() and ! empty()
---
system/database/drivers/sqlite/sqlite_forge.php | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php
index 8bf1f2595..5339f6e3e 100644
--- a/system/database/drivers/sqlite/sqlite_forge.php
+++ b/system/database/drivers/sqlite/sqlite_forge.php
@@ -104,11 +104,11 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
$sql .= "\n\t".$this->db->protect_identifiers($field)
.' '.$attributes['TYPE']
- .(array_key_exists('CONSTRAINT', $attributes) ? '('.$attributes['CONSTRAINT'].')' : '')
- .((array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
- .(array_key_exists('DEFAULT', $attributes) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '')
- .((array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
- .((array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
+ .(isset($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '')
+ .((isset($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
+ .(isset($attributes['DEFAULT']) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '')
+ .((isset($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .((isset($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
}
// don't add a comma on the end of the last field
--
cgit v1.2.3-24-g4f1b
From 684ee3a330c90744b249b48212d85dfe4d3b1caf Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 26 Jan 2012 14:17:39 +0200
Subject: Replace array_key_exists() with isset()
---
system/database/drivers/sqlsrv/sqlsrv_forge.php | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php
index 1367ddc77..c0271f671 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_forge.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php
@@ -110,11 +110,11 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
$sql .= "\n\t".$this->db->protect_identifiers($field)
.' '.$attributes['TYPE']
- .(array_key_exists('CONSTRAINT', $attributes) ? '('.$attributes['CONSTRAINT'].')' : '')
- .((array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
- .(array_key_exists('DEFAULT', $attributes) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '')
- .((array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
- .((array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
+ .(isset($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '')
+ .((isset($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
+ .(isset($attributes['DEFAULT']) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '')
+ .((isset($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .((isset($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
}
// don't add a comma on the end of the last field
--
cgit v1.2.3-24-g4f1b
From c6953f4077fe3ee394abb37eaa0575527bd013cc Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 26 Jan 2012 14:43:16 +0200
Subject: Fix _limit()
---
system/database/drivers/cubrid/cubrid_driver.php | 2 +-
system/database/drivers/cubrid/cubrid_forge.php | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index 1cfaf3e42..b89746b7d 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -696,7 +696,7 @@ class CI_DB_cubrid_driver extends CI_DB {
*/
protected function _limit($sql, $limit, $offset)
{
- return $sql.'LIMIT '.($offset == 0 ? '' : ', ').$limit;
+ return $sql.'LIMIT '.($offset == 0 ? '' : $offset.', ').$limit;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php
index d277ca394..4b1c2839a 100644
--- a/system/database/drivers/cubrid/cubrid_forge.php
+++ b/system/database/drivers/cubrid/cubrid_forge.php
@@ -89,13 +89,13 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
$attributes = array_change_key_case($attributes, CASE_UPPER);
$sql .= "\n\t\"".$this->db->protect_identifiers($field).'"'
- .(isset($attributes['NAME']) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : '');
+ .( ! empty($attributes['NAME']) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : '');
if ( ! empty($attributes['TYPE']))
{
$sql .= ' '.$attributes['TYPE'];
- if (isset($attributes['CONSTRAINT']))
+ if ( ! empty($attributes['CONSTRAINT']))
{
switch ($attributes['TYPE'])
{
@@ -125,9 +125,9 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
*/
$sql .= (isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '')
- .((isset($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
- .((isset($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '')
- .((isset($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) ? ' UNIQUE' : '');
+ .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '')
+ .(( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) ? ' UNIQUE' : '');
}
// don't add a comma on the end of the last field
--
cgit v1.2.3-24-g4f1b
From b537c4d32d109cef2ddf541aa976c3e96736bf06 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 26 Jan 2012 14:45:45 +0200
Subject: Fix _limit()
---
system/database/drivers/sqlite/sqlite_driver.php | 2 +-
system/database/drivers/sqlite/sqlite_forge.php | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index 96458e032..119722d2f 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -583,7 +583,7 @@ class CI_DB_sqlite_driver extends CI_DB {
*/
protected function _limit($sql, $limit, $offset)
{
- return $sql.'LIMIT '.($offset == 0 ? '' : ', ').$limit;
+ return $sql.'LIMIT '.($offset == 0 ? '' : $offset.', ').$limit;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php
index 5339f6e3e..99766878b 100644
--- a/system/database/drivers/sqlite/sqlite_forge.php
+++ b/system/database/drivers/sqlite/sqlite_forge.php
@@ -104,11 +104,11 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
$sql .= "\n\t".$this->db->protect_identifiers($field)
.' '.$attributes['TYPE']
- .(isset($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '')
- .((isset($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
+ .( ! empty($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '')
+ .(( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
.(isset($attributes['DEFAULT']) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '')
- .((isset($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
- .((isset($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
+ .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
}
// don't add a comma on the end of the last field
--
cgit v1.2.3-24-g4f1b
From 993f932cb27f68ac4a3272502a823af0835b291c Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 26 Jan 2012 14:49:23 +0200
Subject: Another minor improvement and fix a possible false-positive
---
system/database/drivers/sqlsrv/sqlsrv_driver.php | 2 +-
system/database/drivers/sqlsrv/sqlsrv_forge.php | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php
index cdd178261..0c24ef38f 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_driver.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -303,7 +303,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
}
$query = $this->query('SELECT COUNT(*) AS numrows FROM '.$this->dbprefix.$table);
- if ($query->num_rows() === 0)
+ if ($query->num_rows() == 0)
{
return 0;
}
diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php
index c0271f671..3beb86b4e 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_forge.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php
@@ -110,11 +110,11 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
$sql .= "\n\t".$this->db->protect_identifiers($field)
.' '.$attributes['TYPE']
- .(isset($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '')
- .((isset($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
+ .( ! empty($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '')
+ .(( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
.(isset($attributes['DEFAULT']) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '')
- .((isset($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
- .((isset($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
+ .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
}
// don't add a comma on the end of the last field
--
cgit v1.2.3-24-g4f1b
From b76029d8be1f2d98f1668d61e7f7ac3d9274b8f3 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 26 Jan 2012 15:13:19 +0200
Subject: Improve the ODBC database driver
---
system/database/drivers/odbc/odbc_driver.php | 220 +++++++++-----------------
system/database/drivers/odbc/odbc_forge.php | 143 +++++------------
system/database/drivers/odbc/odbc_result.php | 129 +++++++--------
system/database/drivers/odbc/odbc_utility.php | 44 ++----
4 files changed, 185 insertions(+), 351 deletions(-)
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index 6ba39f0cd..a674c390e 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -1,13 +1,13 @@
-hostname, $this->username, $this->password);
}
@@ -83,10 +79,9 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_pconnect()
+ public function db_pconnect()
{
return @odbc_pconnect($this->hostname, $this->username, $this->password);
}
@@ -99,10 +94,9 @@ class CI_DB_odbc_driver extends CI_DB {
* Keep / reestablish the db connection if no queries have been
* sent for a length of time exceeding the server's idle timeout
*
- * @access public
* @return void
*/
- function reconnect()
+ public function reconnect()
{
// not implemented in odbc
}
@@ -112,10 +106,9 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
* @return resource
*/
- function db_select()
+ public function db_select()
{
// Not needed for ODBC
return TRUE;
@@ -126,12 +119,11 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Set client character set
*
- * @access public
* @param string
* @param string
- * @return resource
+ * @return bool
*/
- function db_set_charset($charset, $collation)
+ public function db_set_charset($charset, $collation)
{
// @todo - add support if needed
return TRUE;
@@ -142,12 +134,11 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Version number query string
*
- * @access public
* @return string
*/
- function _version()
+ protected function _version()
{
- return "SELECT version() AS ver";
+ return 'SELECT version() AS ver';
}
// --------------------------------------------------------------------
@@ -155,14 +146,12 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
* @return resource
*/
- function _execute($sql)
+ protected function _execute($sql)
{
- $sql = $this->_prep_query($sql);
- return @odbc_exec($this->conn_id, $sql);
+ return @odbc_exec($this->conn_id, $this->_prep_query($sql));
}
// --------------------------------------------------------------------
@@ -172,11 +161,10 @@ class CI_DB_odbc_driver extends CI_DB {
*
* If needed, each database adapter can prep the query string
*
- * @access private called by execute()
* @param string an SQL query
* @return string
*/
- function _prep_query($sql)
+ protected function _prep_query($sql)
{
return $sql;
}
@@ -186,18 +174,12 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Begin Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -205,7 +187,7 @@ class CI_DB_odbc_driver extends CI_DB {
// Reset the transaction failure flag.
// If the $test_mode flag is set to TRUE transactions will be rolled back
// even if the queries produce a successful result.
- $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
+ $this->_trans_failure = ($test_mode === TRUE);
return odbc_autocommit($this->conn_id, FALSE);
}
@@ -215,18 +197,12 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -241,18 +217,12 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -267,12 +237,11 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Escape String
*
- * @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
+ public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -290,9 +259,9 @@ class CI_DB_odbc_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace( array('%', '_', $this->_like_escape_chr),
- array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
- $str);
+ return str_replace(array('%', '_', $this->_like_escape_chr),
+ array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
+ $str);
}
return $str;
@@ -303,10 +272,9 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
return @odbc_num_rows($this->conn_id);
}
@@ -316,10 +284,9 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Insert ID
*
- * @access public
- * @return integer
+ * @return int
*/
- function insert_id()
+ public function insert_id()
{
return @odbc_insert_id($this->conn_id);
}
@@ -332,27 +299,26 @@ class CI_DB_odbc_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
* @param string
- * @return string
+ * @return int
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
return 0;
}
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
+ $query = $this->query($this->_count_string.$this->_protect_identifiers('numrows').' FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
{
return 0;
}
- $row = $query->row();
+ $query = $query->row();
$this->_reset_select();
- return (int) $row->numrows;
+ return (int) $query->numrows;
}
// --------------------------------------------------------------------
@@ -366,11 +332,11 @@ class CI_DB_odbc_driver extends CI_DB {
* @param boolean
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
- $sql = "SHOW TABLES FROM `".$this->database."`";
+ $sql = 'SHOW TABLES FROM `'.$this->database.'`';
- if ($prefix_limit !== FALSE AND $this->dbprefix != '')
+ if ($prefix_limit !== FALSE && $this->dbprefix != '')
{
//$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
return FALSE; // not currently supported
@@ -386,13 +352,12 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access public
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
- return "SHOW COLUMNS FROM ".$table;
+ return 'SHOW COLUMNS FROM '.$table;
}
// --------------------------------------------------------------------
@@ -402,13 +367,12 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
- * @return object
+ * @return string
*/
- function _field_data($table)
+ protected function _field_data($table)
{
- return "SELECT TOP 1 FROM ".$table;
+ return 'SELECT TOP 1 FROM '.$table;
}
// --------------------------------------------------------------------
@@ -416,10 +380,9 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* The error message string
*
- * @access private
* @return string
*/
- function _error_message()
+ protected function _error_message()
{
return odbc_errormsg($this->conn_id);
}
@@ -429,10 +392,9 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* The error message number
*
- * @access private
- * @return integer
+ * @return int
*/
- function _error_number()
+ protected function _error_number()
{
return odbc_error($this->conn_id);
}
@@ -444,11 +406,10 @@ class CI_DB_odbc_driver extends CI_DB {
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -459,24 +420,20 @@ class CI_DB_odbc_driver extends CI_DB {
{
if (strpos($item, '.'.$id) !== FALSE)
{
- $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
+ $item = str_replace('.', $this->_escape_char.'.', $item);
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item);
}
}
if (strpos($item, '.') !== FALSE)
{
- $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
- }
- else
- {
- $str = $this->_escape_char.$item.$this->_escape_char;
+ $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
}
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char);
}
// --------------------------------------------------------------------
@@ -487,11 +444,10 @@ class CI_DB_odbc_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access public
- * @param type
- * @return type
+ * @param string the table name
+ * @return string
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -508,15 +464,14 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert($table, $keys, $values)
+ protected function _insert($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -526,7 +481,6 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -534,24 +488,17 @@ class CI_DB_odbc_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
- $valstr[] = $key." = ".$val;
+ $valstr[] = $key.' = '.$val;
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
-
- $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
-
- $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
-
- $sql .= $orderby.$limit;
-
- return $sql;
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
+ .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '')
+ .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '')
+ .( ! $limit ? '' : ' LIMIT '.$limit);
}
@@ -564,11 +511,10 @@ class CI_DB_odbc_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access public
* @param string the table name
* @return string
*/
- function _truncate($table)
+ protected function _truncate($table)
{
return $this->_delete($table);
}
@@ -580,31 +526,27 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
- function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
if (count($where) > 0 OR count($like) > 0)
{
- $conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions = "\nWHERE ".implode("\n", $this->ar_where);
if (count($where) > 0 && count($like) > 0)
{
- $conditions .= " AND ";
+ $conditions .= ' AND ';
}
$conditions .= implode("\n", $like);
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- return "DELETE FROM ".$table.$conditions.$limit;
+ return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit);
}
// --------------------------------------------------------------------
@@ -614,16 +556,14 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access public
* @param string the sql query string
- * @param integer the number of rows to limit the query to
- * @param integer the offset value
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
- // Does ODBC doesn't use the LIMIT clause?
- return $sql;
+ return $sql.($offset == 0 ? '' : $offset.', ').$limit;
}
// --------------------------------------------------------------------
@@ -631,19 +571,15 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
* @param resource
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
@odbc_close($conn_id);
}
-
}
-
-
/* End of file odbc_driver.php */
-/* Location: ./system/database/drivers/odbc/odbc_driver.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/odbc/odbc_driver.php */
diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php
index e0ec687c8..49e5c3e72 100644
--- a/system/database/drivers/odbc/odbc_forge.php
+++ b/system/database/drivers/odbc/odbc_forge.php
@@ -1,13 +1,13 @@
-db->db_debug)
- {
- return $this->db->display_error('db_unsuported_feature');
- }
- return FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
// --------------------------------------------------------------------
@@ -59,19 +52,14 @@ class CI_DB_odbc_forge extends CI_DB_forge {
/**
* Drop database
*
- * @access private
* @param string the database name
* @return bool
*/
- function _drop_database($name)
+ public function _drop_database($name)
{
// ODBC has no "drop database" command since it's
// designed to connect to an existing database
- if ($this->db->db_debug)
- {
- return $this->db->display_error('db_unsuported_feature');
- }
- return FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
// --------------------------------------------------------------------
@@ -79,7 +67,6 @@ class CI_DB_odbc_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param array the fields
* @param mixed primary key(s)
@@ -87,7 +74,7 @@ class CI_DB_odbc_forge extends CI_DB_forge {
* @param boolean should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
@@ -96,54 +83,29 @@ class CI_DB_odbc_forge extends CI_DB_forge {
$sql .= 'IF NOT EXISTS ';
}
- $sql .= $this->db->_escape_identifiers($table)." (";
+ $sql .= $this->db->_escape_identifiers($table).' (';
$current_field_count = 0;
- foreach ($fields as $field=>$attributes)
+ foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
// numeric, we know it was assigned by PHP and the developer manually
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
- $sql .= "\n\t$attributes";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
-
- $sql .= ' '.$attributes['TYPE'];
-
- if (array_key_exists('CONSTRAINT', $attributes))
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
-
- if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (array_key_exists('DEFAULT', $attributes))
- {
- $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
- }
-
- if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
+ $sql .= "\n\t".$this->db->protect_identifiers($field)
+ .' '.$attributes['TYPE']
+ .( ! empty($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '')
+ .(( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
+ .(isset($attributes['DEFAULT'], $attributes) ? " DEFAULT '".$attributes['DEFAULT']."'" : '')
+ .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
}
// don't add a comma on the end of the last field
@@ -155,8 +117,7 @@ class CI_DB_odbc_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->protect_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -165,20 +126,18 @@ class CI_DB_odbc_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key = $this->db->_protect_identifiers($key);
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key = array($this->db->_protect_identifiers($key));
+ $key = array($this->db->protect_identifiers($key));
}
- $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
}
}
- $sql .= "\n)";
-
- return $sql;
+ return $sql."\n)";
}
// --------------------------------------------------------------------
@@ -186,17 +145,12 @@ class CI_DB_odbc_forge extends CI_DB_forge {
/**
* Drop Table
*
- * @access private
* @return bool
*/
- function _drop_table($table)
+ public function _drop_table($table)
{
// Not a supported ODBC feature
- if ($this->db->db_debug)
- {
- return $this->db->display_error('db_unsuported_feature');
- }
- return FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
// --------------------------------------------------------------------
@@ -207,49 +161,29 @@ class CI_DB_odbc_forge extends CI_DB_forge {
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
- * @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param string the table name
* @param string the column definition
* @param string the default value
- * @param boolean should 'NOT NULL' be added
+ * @param bool should 'NOT NULL' be added
* @param string the field after which we should add the new field
- * @return object
+ * @return string
*/
- function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
+ $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name);
// DROP has everything it needs now.
- if ($alter_type == 'DROP')
+ if ($alter_type === 'DROP')
{
return $sql;
}
- $sql .= " $column_definition";
-
- if ($default_value != '')
- {
- $sql .= " DEFAULT \"$default_value\"";
- }
-
- if ($null === NULL)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if ($after_field != '')
- {
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
- }
-
- return $sql;
-
+ return $sql.' '.$column_definition
+ .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '')
+ .($null === NULL ? ' NULL' : ' NOT NULL')
+ .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : '');
}
@@ -260,19 +194,16 @@ class CI_DB_odbc_forge extends CI_DB_forge {
*
* Generates a platform-specific query so that a table can be renamed
*
- * @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
- function _rename_table($table_name, $new_table_name)
+ public function _rename_table($table_name, $new_table_name)
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
}
-
}
/* End of file odbc_forge.php */
-/* Location: ./system/database/drivers/odbc/odbc_forge.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/odbc/odbc_forge.php */
diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php
index ba660856e..509c77a1b 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -1,13 +1,13 @@
-result_id);
}
- // --------------------------------------------------------------------
-
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @odbc_num_fields($this->result_id);
}
@@ -69,13 +63,12 @@ class CI_DB_odbc_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
- for ($i = 0; $i < $this->num_fields(); $i++)
+ for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
{
$field_names[] = odbc_field_name($this->result_id, $i);
}
@@ -90,22 +83,19 @@ class CI_DB_odbc_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
- for ($i = 0; $i < $this->num_fields(); $i++)
+ for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
{
- $F = new stdClass();
- $F->name = odbc_field_name($this->result_id, $i);
- $F->type = odbc_field_type($this->result_id, $i);
- $F->max_length = odbc_field_len($this->result_id, $i);
- $F->primary_key = 0;
- $F->default = '';
-
- $retval[] = $F;
+ $retval[$i] = new stdClass();
+ $retval[$i]->name = odbc_field_name($this->result_id, $i);
+ $retval[$i]->type = odbc_field_type($this->result_id, $i);
+ $retval[$i]->max_length = odbc_field_len($this->result_id, $i);
+ $retval[$i]->primary_key = 0;
+ $retval[$i]->default = '';
}
return $retval;
@@ -116,9 +106,9 @@ class CI_DB_odbc_result extends CI_DB_result {
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
if (is_resource($this->result_id))
{
@@ -132,15 +122,15 @@ class CI_DB_odbc_result extends CI_DB_result {
/**
* Data Seek
*
- * Moves the internal pointer to the desired offset. We call
+ * Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
* @return array
*/
- function _data_seek($n = 0)
+ protected function _data_seek($n = 0)
{
+ // Not supported
return FALSE;
}
@@ -151,19 +141,13 @@ class CI_DB_odbc_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
- if (function_exists('odbc_fetch_object'))
- {
- return odbc_fetch_array($this->result_id);
- }
- else
- {
- return $this->_odbc_fetch_array($this->result_id);
- }
+ return function_exists('odbc_fetch_object')
+ ? odbc_fetch_array($this->result_id)
+ : $this->_odbc_fetch_array($this->result_id);
}
// --------------------------------------------------------------------
@@ -173,40 +157,38 @@ class CI_DB_odbc_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
- if (function_exists('odbc_fetch_object'))
- {
- return odbc_fetch_object($this->result_id);
- }
- else
- {
- return $this->_odbc_fetch_object($this->result_id);
- }
+ return function_exists('odbc_fetch_object')
+ ? odbc_fetch_object($this->result_id)
+ : $this->_odbc_fetch_object($this->result_id);
}
-
/**
* Result - object
*
* subsititutes the odbc_fetch_object function when
* not available (odbc_fetch_object requires unixODBC)
*
- * @access private
* @return object
*/
- function _odbc_fetch_object(& $odbc_result) {
+ private function _odbc_fetch_object(& $odbc_result)
+ {
$rs = array();
- $rs_obj = FALSE;
- if (odbc_fetch_into($odbc_result, $rs)) {
- foreach ($rs as $k=>$v) {
- $field_name= odbc_field_name($odbc_result, $k+1);
- $rs_obj->$field_name = $v;
- }
+ if ( ! odbc_fetch_into($odbc_result, $rs))
+ {
+ return FALSE;
}
+
+ $rs_obj = new stdClass();
+ foreach ($rs as $k => $v)
+ {
+ $field_name = odbc_field_name($odbc_result, $k+1);
+ $rs_obj->$field_name = $v;
+ }
+
return $rs_obj;
}
@@ -217,24 +199,27 @@ class CI_DB_odbc_result extends CI_DB_result {
* subsititutes the odbc_fetch_array function when
* not available (odbc_fetch_array requires unixODBC)
*
- * @access private
* @return array
*/
- function _odbc_fetch_array(& $odbc_result) {
+ private function _odbc_fetch_array(& $odbc_result)
+ {
$rs = array();
- $rs_assoc = FALSE;
- if (odbc_fetch_into($odbc_result, $rs)) {
- $rs_assoc=array();
- foreach ($rs as $k=>$v) {
- $field_name= odbc_field_name($odbc_result, $k+1);
- $rs_assoc[$field_name] = $v;
- }
+ if ( ! odbc_fetch_into($odbc_result, $rs))
+ {
+ return FALSE;
+ }
+
+ $rs_assoc = array();
+ foreach ($rs as $k => $v)
+ {
+ $field_name = odbc_field_name($odbc_result, $k+1);
+ $rs_assoc[$field_name] = $v;
}
+
return $rs_assoc;
}
}
-
/* End of file odbc_result.php */
-/* Location: ./system/database/drivers/odbc/odbc_result.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/odbc/odbc_result.php */
diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php
index bae3fe853..e71bc5a03 100644
--- a/system/database/drivers/odbc/odbc_utility.php
+++ b/system/database/drivers/odbc/odbc_utility.php
@@ -1,13 +1,13 @@
-db->db_debug)
- {
- return $this->db->display_error('db_unsuported_feature');
- }
- return FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
// --------------------------------------------------------------------
@@ -59,18 +52,13 @@ class CI_DB_odbc_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be optimized
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _optimize_table($table)
+ public function _optimize_table($table)
{
// Not a supported ODBC feature
- if ($this->db->db_debug)
- {
- return $this->db->display_error('db_unsuported_feature');
- }
- return FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
// --------------------------------------------------------------------
@@ -80,18 +68,13 @@ class CI_DB_odbc_utility extends CI_DB_utility {
*
* Generates a platform-specific query so that a table can be repaired
*
- * @access private
* @param string the table name
- * @return object
+ * @return bool
*/
- function _repair_table($table)
+ public function _repair_table($table)
{
// Not a supported ODBC feature
- if ($this->db->db_debug)
- {
- return $this->db->display_error('db_unsuported_feature');
- }
- return FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
// --------------------------------------------------------------------
@@ -99,11 +82,10 @@ class CI_DB_odbc_utility extends CI_DB_utility {
/**
* ODBC Export
*
- * @access private
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');
@@ -112,4 +94,4 @@ class CI_DB_odbc_utility extends CI_DB_utility {
}
/* End of file odbc_utility.php */
-/* Location: ./system/database/drivers/odbc/odbc_utility.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/odbc/odbc_utility.php */
--
cgit v1.2.3-24-g4f1b
From 214583f1ba4c026141e595dac5868d5074095a7e Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 26 Jan 2012 16:39:09 +0200
Subject: Improve the PostgreSQL database driver
---
system/database/drivers/postgre/postgre_driver.php | 357 ++++++++++-----------
system/database/drivers/postgre/postgre_forge.php | 136 +++-----
system/database/drivers/postgre/postgre_result.php | 60 ++--
.../database/drivers/postgre/postgre_utility.php | 33 +-
4 files changed, 257 insertions(+), 329 deletions(-)
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 42329bded..8b8f33371 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -1,13 +1,13 @@
- 'host',
- 'port' => 'port',
- 'database' => 'dbname',
- 'username' => 'user',
- 'password' => 'password'
- );
-
- $connect_string = "";
+ 'hostname' => 'host',
+ 'port' => 'port',
+ 'database' => 'dbname',
+ 'username' => 'user',
+ 'password' => 'password'
+ );
+
foreach ($components as $key => $val)
{
if (isset($this->$key) && $this->$key != '')
{
- $connect_string .= " $val=".$this->$key;
+ $this->_pg_dsn .= $val.'='.$this->$key.' ';
}
}
- return trim($connect_string);
+
+ if (strlen($this->_pg_dsn) > 0)
+ {
+ $this->_pg_dsn = rtrim($this->_pg_dsn);
+ }
}
// --------------------------------------------------------------------
@@ -90,12 +97,17 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Non-persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_connect()
+ public function db_connect()
{
- return @pg_connect($this->_connect_string());
+ $ret = @pg_connect($this->_pg_dsn);
+ if (is_resource($ret) && $this->char_set != '')
+ {
+ pg_set_client_encoding($ret, $this->char_set);
+ }
+
+ return $ret;
}
// --------------------------------------------------------------------
@@ -103,12 +115,17 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Persistent database connection
*
- * @access private called by the base class
* @return resource
*/
- function db_pconnect()
+ public function db_pconnect()
{
- return @pg_pconnect($this->_connect_string());
+ $ret = @pg_pconnect($this->_pg_dsn);
+ if (is_resource($ret) && $this->char_set != '')
+ {
+ pg_set_client_encoding($ret, $this->char_set);
+ }
+
+ return $ret;
}
// --------------------------------------------------------------------
@@ -119,10 +136,9 @@ class CI_DB_postgre_driver extends CI_DB {
* Keep / reestablish the db connection if no queries have been
* sent for a length of time exceeding the server's idle timeout
*
- * @access public
* @return void
*/
- function reconnect()
+ public function reconnect()
{
if (pg_ping($this->conn_id) === FALSE)
{
@@ -135,10 +151,9 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Select the database
*
- * @access private called by the base class
* @return resource
*/
- function db_select()
+ public function db_select()
{
// Not needed for Postgre so we'll return TRUE
return TRUE;
@@ -149,15 +164,35 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Set client character set
*
- * @access public
* @param string
* @param string
- * @return resource
+ * @return bool
*/
- function db_set_charset($charset, $collation)
+ public function db_set_charset($charset, $collation)
{
- // @todo - add support if needed
- return TRUE;
+ return (pg_set_client_encoding($this->conn_id, $charset) === 0);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Database version
+ *
+ * This method overrides the one from the base class, as if PHP was
+ * compiled with PostgreSQL version >= 7.4 libraries, we have a native
+ * function to get the server's version.
+ *
+ * @return string
+ */
+
+ public function version()
+ {
+ $version = pg_version($this->conn_id);
+
+ /* If we don't have the server version string - fall back to
+ * the base driver class' method
+ */
+ return isset($version['server']) ? $version['server'] : parent::version();
}
// --------------------------------------------------------------------
@@ -165,12 +200,11 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Version number query string
*
- * @access public
* @return string
*/
- function _version()
+ protected function _version()
{
- return "SELECT version() AS ver";
+ return 'SELECT version() AS ver';
}
// --------------------------------------------------------------------
@@ -178,14 +212,12 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Execute the query
*
- * @access private called by the base class
* @param string an SQL query
* @return resource
*/
- function _execute($sql)
+ protected function _execute($sql)
{
- $sql = $this->_prep_query($sql);
- return @pg_query($this->conn_id, $sql);
+ return @pg_query($this->conn_id, $this->_prep_query($sql));
}
// --------------------------------------------------------------------
@@ -195,11 +227,10 @@ class CI_DB_postgre_driver extends CI_DB {
*
* If needed, each database adapter can prep the query string
*
- * @access private called by execute()
* @param string an SQL query
* @return string
*/
- function _prep_query($sql)
+ protected function _prep_query($sql)
{
return $sql;
}
@@ -209,18 +240,13 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Begin Transaction
*
- * @access public
+ * @param bool
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ public function trans_begin($test_mode = FALSE)
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -228,9 +254,9 @@ class CI_DB_postgre_driver extends CI_DB {
// Reset the transaction failure flag.
// If the $test_mode flag is set to TRUE transactions will be rolled back
// even if the queries produce a successful result.
- $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
+ $this->_trans_failure = ($test_mode === TRUE);
- return @pg_exec($this->conn_id, "begin");
+ return (bool) @pg_query($this->conn_id, 'BEGIN');
}
// --------------------------------------------------------------------
@@ -238,23 +264,17 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Commit Transaction
*
- * @access public
* @return bool
*/
- function trans_commit()
+ public function trans_commit()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
- return @pg_exec($this->conn_id, "commit");
+ return (bool) @pg_query($this->conn_id, 'COMMIT');
}
// --------------------------------------------------------------------
@@ -262,23 +282,17 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_rollback()
+ public function trans_rollback()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
- return @pg_exec($this->conn_id, "rollback");
+ return (bool) @pg_query($this->conn_id, 'ROLLBACK');
}
// --------------------------------------------------------------------
@@ -286,12 +300,11 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Escape String
*
- * @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
+ public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -308,9 +321,9 @@ class CI_DB_postgre_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace( array('%', '_', $this->_like_escape_chr),
- array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
- $str);
+ return str_replace(array('%', '_', $this->_like_escape_chr),
+ array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
+ $str);
}
return $str;
@@ -321,10 +334,9 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
return @pg_affected_rows($this->result_id);
}
@@ -334,40 +346,45 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Insert ID
*
- * @access public
- * @return integer
+ * @return int
*/
- function insert_id()
+ public function insert_id()
{
- $v = $this->_version();
- $v = $v['server'];
+ $v = pg_version($this->conn_id);
+ $v = isset($v['server']) ? $v['server'] : 0; // 'server' key is only available since PosgreSQL 7.4
- $table = func_num_args() > 0 ? func_get_arg(0) : NULL;
- $column = func_num_args() > 1 ? func_get_arg(1) : NULL;
+ $table = (func_num_args() > 0) ? func_get_arg(0) : NULL;
+ $column = (func_num_args() > 1) ? func_get_arg(1) : NULL;
if ($table == NULL && $v >= '8.1')
{
- $sql='SELECT LASTVAL() as ins_id';
- }
- elseif ($table != NULL && $column != NULL && $v >= '8.0')
- {
- $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column);
- $query = $this->query($sql);
- $row = $query->row();
- $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq);
+ $sql = 'SELECT LASTVAL() AS ins_id';
}
elseif ($table != NULL)
{
- // seq_name passed in table parameter
- $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table);
+ if ($column != NULL && $v >= '8.0')
+ {
+ $sql = 'SELECT pg_get_serial_sequence(\''.$table."', '".$column."') AS seq";
+ $query = $this->query($sql);
+ $query = $query->row();
+ $seq = $query->seq;
+ }
+ else
+ {
+ // seq_name passed in table parameter
+ $seq = $table;
+ }
+
+ $sql = 'SELECT CURRVAL(\''.$seq."') AS ins_id";
}
else
{
return pg_last_oid($this->result_id);
}
+
$query = $this->query($sql);
- $row = $query->row();
- return $row->ins_id;
+ $query = $query->row();
+ return (int) $query->ins_id;
}
// --------------------------------------------------------------------
@@ -378,27 +395,25 @@ class CI_DB_postgre_driver extends CI_DB {
* Generates a platform-specific query string that counts all records in
* the specified database
*
- * @access public
* @param string
* @return string
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
return 0;
}
- $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
-
+ $query = $this->query($this->_count_string.$this->_protect_identifiers('numrows').' FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
{
return 0;
}
- $row = $query->row();
+ $query = $query->row();
$this->_reset_select();
- return (int) $row->numrows;
+ return (int) $query->numrows;
}
// --------------------------------------------------------------------
@@ -408,17 +423,16 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access private
- * @param boolean
+ * @param bool
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected function _list_tables($prefix_limit = FALSE)
{
$sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'";
- if ($prefix_limit !== FALSE AND $this->dbprefix != '')
+ if ($prefix_limit !== FALSE && $this->dbprefix != '')
{
- $sql .= " AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
+ return $sql." AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
}
return $sql;
@@ -431,13 +445,12 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access public
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
- return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'";
+ return "SELECT column_name FROM information_schema.columns WHERE table_name = '".$table."'";
}
// --------------------------------------------------------------------
@@ -447,13 +460,12 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @access public
* @param string the table name
- * @return object
+ * @return string
*/
- function _field_data($table)
+ protected function _field_data($table)
{
- return "SELECT * FROM ".$table." LIMIT 1";
+ return 'SELECT * FROM '.$table.' LIMIT 1';
}
// --------------------------------------------------------------------
@@ -461,10 +473,9 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* The error message string
*
- * @access private
* @return string
*/
- function _error_message()
+ protected function _error_message()
{
return pg_last_error($this->conn_id);
}
@@ -474,11 +485,11 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* The error message number
*
- * @access private
- * @return integer
+ * @return string
*/
- function _error_number()
+ protected function _error_number()
{
+ // Not supported in Postgre
return '';
}
@@ -489,11 +500,10 @@ class CI_DB_postgre_driver extends CI_DB {
*
* This function escapes column and table names
*
- * @access private
* @param string
* @return string
*/
- function _escape_identifiers($item)
+ public function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -504,24 +514,20 @@ class CI_DB_postgre_driver extends CI_DB {
{
if (strpos($item, '.'.$id) !== FALSE)
{
- $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
+ $item = str_replace('.', $this->_escape_char.'.', $item);
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item);
}
}
if (strpos($item, '.') !== FALSE)
{
- $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
- }
- else
- {
- $str = $this->_escape_char.$item.$this->_escape_char;
+ $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
}
// remove duplicates if the user already included the escape
- return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
+ return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char);
}
// --------------------------------------------------------------------
@@ -532,11 +538,10 @@ class CI_DB_postgre_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
- * @access public
- * @param type
- * @return type
+ * @param string table name
+ * @return string
*/
- function _from_tables($tables)
+ protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -553,15 +558,14 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert($table, $keys, $values)
+ protected function _insert($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -571,15 +575,14 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific insert string from the supplied data
*
- * @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
- function _insert_batch($table, $keys, $values)
+ protected function _insert_batch($table, $keys, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES '.implode(', ', $values);
}
// --------------------------------------------------------------------
@@ -589,7 +592,6 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @access public
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -597,24 +599,17 @@ class CI_DB_postgre_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
- $valstr[] = $key." = ".$val;
+ $valstr[] = $key.' = '.$val;
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
-
- $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
-
- $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
-
- $sql .= $orderby.$limit;
-
- return $sql;
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
+ .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '')
+ .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '')
+ .( ! $limit ? '' : ' LIMIT '.$limit);
}
// --------------------------------------------------------------------
@@ -626,13 +621,12 @@ class CI_DB_postgre_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
- * @access public
* @param string the table name
* @return string
*/
- function _truncate($table)
+ protected function _truncate($table)
{
- return "TRUNCATE ".$table;
+ return 'TRUNCATE '.$table;
}
// --------------------------------------------------------------------
@@ -642,31 +636,27 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
- function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
if (count($where) > 0 OR count($like) > 0)
{
- $conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions = "\nWHERE ".implode("\n", $this->ar_where);
if (count($where) > 0 && count($like) > 0)
{
- $conditions .= " AND ";
+ $conditions .= ' AND ';
}
$conditions .= implode("\n", $like);
}
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- return "DELETE FROM ".$table.$conditions.$limit;
+ return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit);
}
// --------------------------------------------------------------------
@@ -675,22 +665,14 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
- * @access public
* @param string the sql query string
- * @param integer the number of rows to limit the query to
- * @param integer the offset value
+ * @param int the number of rows to limit the query to
+ * @param int the offset value
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql, $limit, $offset)
{
- $sql .= "LIMIT ".$limit;
-
- if ($offset > 0)
- {
- $sql .= " OFFSET ".$offset;
- }
-
- return $sql;
+ return $sql.' LIMIT '.$limit.($offset == 0 ? '' : ' OFFSET '.$offset);
}
// --------------------------------------------------------------------
@@ -698,18 +680,15 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
* @param resource
* @return void
*/
- function _close($conn_id)
+ protected function _close($conn_id)
{
@pg_close($conn_id);
}
-
}
-
/* End of file postgre_driver.php */
-/* Location: ./system/database/drivers/postgre/postgre_driver.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/postgre/postgre_driver.php */
diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php
index 756fd347a..5af834b8d 100644
--- a/system/database/drivers/postgre/postgre_forge.php
+++ b/system/database/drivers/postgre/postgre_forge.php
@@ -1,13 +1,13 @@
-$attributes)
+ foreach ($fields as $field => $attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
// numeric, we know it was assigned by PHP and the developer manually
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
- $sql .= "\n\t$attributes";
+ $sql .= "\n\t".$attributes;
}
else
{
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
+ $sql .= "\n\t".$this->db->protect_identifiers($field);
- $is_unsigned = (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE);
+ $attributes = array_change_key_case($attributes, CASE_UPPER);
+ $is_unsigned = ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE);
// Convert datatypes to be PostgreSQL-compatible
switch (strtoupper($attributes['TYPE']))
@@ -122,44 +117,24 @@ class CI_DB_postgre_forge extends CI_DB_forge {
case 'BLOB':
$attributes['TYPE'] = 'BYTEA';
break;
+ default:
+ break;
}
// If this is an auto-incrementing primary key, use the serial data type instead
- if (in_array($field, $primary_keys) && array_key_exists('AUTO_INCREMENT', $attributes)
- && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' SERIAL';
- }
- else
- {
- $sql .= ' '.$attributes['TYPE'];
- }
+ $sql .= (in_array($field, $primary_keys) && ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
+ ? ' SERIAL' : ' '.$attributes['TYPE'];
// Modified to prevent constraints with integer data types
- if (array_key_exists('CONSTRAINT', $attributes) && strpos($attributes['TYPE'], 'INT') === false)
+ if ( ! empty($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') === FALSE)
{
$sql .= '('.$attributes['CONSTRAINT'].')';
}
- if (array_key_exists('DEFAULT', $attributes))
- {
- $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
- }
-
- if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- // Added new attribute to create unqite fields. Also works with MySQL
- if (array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE)
- {
- $sql .= ' UNIQUE';
- }
+ $sql .= (isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '')
+ .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ // Added new attribute to create unqite fields. Also works with MySQL
+ .(( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) ? ' UNIQUE' : '');
}
// don't add a comma on the end of the last field
@@ -168,7 +143,7 @@ class CI_DB_postgre_forge extends CI_DB_forge {
$sql .= ',';
}
}
-
+
return $sql;
}
@@ -177,15 +152,14 @@ class CI_DB_postgre_forge extends CI_DB_forge {
/**
* Create Table
*
- * @access private
* @param string the table name
* @param array the fields
* @param mixed primary key(s)
* @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @param bool should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
@@ -198,18 +172,17 @@ class CI_DB_postgre_forge extends CI_DB_forge {
}
}
- $sql .= $this->db->_escape_identifiers($table)." (";
- $sql .= $this->_process_fields($fields, $primary_keys);
+ $sql .= $this->db->_escape_identifiers($table).' ('.$this->_process_fields($fields, $primary_keys);
if (count($primary_keys) > 0)
{
- // Something seems to break when passing an array to _protect_identifiers()
+ // Something seems to break when passing an array to protect_identifiers()
foreach ($primary_keys as $index => $key)
{
- $primary_keys[$index] = $this->db->_protect_identifiers($key);
+ $primary_keys[$index] = $this->db->protect_identifiers($key);
}
- $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')';
}
$sql .= "\n);";
@@ -220,16 +193,16 @@ class CI_DB_postgre_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key = $this->db->_protect_identifiers($key);
+ $key = $this->db->protect_identifiers($key);
}
else
{
- $key = array($this->db->_protect_identifiers($key));
+ $key = array($this->db->protect_identifiers($key));
}
foreach ($key as $field)
{
- $sql .= "CREATE INDEX " . $table . "_" . str_replace(array('"', "'"), '', $field) . "_index ON $table ($field); ";
+ $sql .= 'CREATE INDEX '.$table.'_'.str_replace(array('"', "'"), '', $field).'_index ON '.$table.' ('.$field.'); ';
}
}
}
@@ -241,10 +214,13 @@ class CI_DB_postgre_forge extends CI_DB_forge {
/**
* Drop Table
+ *
+ * @param string table name
+ * @return string
*/
- function _drop_table($table)
+ public function _drop_table($table)
{
- return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table)." CASCADE";
+ return 'DROP TABLE IF EXISTS '.$this->db->_escape_identifiers($table).' CASCADE';
}
// --------------------------------------------------------------------
@@ -255,34 +231,27 @@ class CI_DB_postgre_forge extends CI_DB_forge {
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
- * @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param string the table name
* @param string the column definition
* @param string the default value
- * @param boolean should 'NOT NULL' be added
+ * @param bool should 'NOT NULL' be added
* @param string the field after which we should add the new field
- * @return object
+ * @return string
*/
- function _alter_table($alter_type, $table, $fields, $after_field = '')
+ public function _alter_table($alter_type, $table, $fields, $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ";
+ $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' ';
// DROP has everything it needs now.
- if ($alter_type == 'DROP')
+ if ($alter_type === 'DROP')
{
- return $sql.$this->db->_protect_identifiers($fields);
+ return $sql.$this->db->protect_identifiers($fields);
}
- $sql .= $this->_process_fields($fields);
-
- if ($after_field != '')
- {
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
- }
-
- return $sql;
+ return $sql.$this->_process_fields($fields)
+ .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : '');
}
// --------------------------------------------------------------------
@@ -292,17 +261,16 @@ class CI_DB_postgre_forge extends CI_DB_forge {
*
* Generates a platform-specific query so that a table can be renamed
*
- * @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
- function _rename_table($table_name, $new_table_name)
+ public function _rename_table($table_name, $new_table_name)
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
}
+
}
/* End of file postgre_forge.php */
-/* Location: ./system/database/drivers/postgre/postgre_forge.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/postgre/postgre_forge.php */
diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php
index 9161bf955..2cfa997e7 100644
--- a/system/database/drivers/postgre/postgre_result.php
+++ b/system/database/drivers/postgre/postgre_result.php
@@ -1,13 +1,13 @@
-result_id);
}
@@ -54,10 +51,9 @@ class CI_DB_postgre_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
return @pg_num_fields($this->result_id);
}
@@ -69,13 +65,12 @@ class CI_DB_postgre_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
- for ($i = 0; $i < $this->num_fields(); $i++)
+ for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
{
$field_names[] = pg_field_name($this->result_id, $i);
}
@@ -90,22 +85,19 @@ class CI_DB_postgre_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
- for ($i = 0; $i < $this->num_fields(); $i++)
+ for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
{
- $F = new stdClass();
- $F->name = pg_field_name($this->result_id, $i);
- $F->type = pg_field_type($this->result_id, $i);
- $F->max_length = pg_field_size($this->result_id, $i);
- $F->primary_key = 0;
- $F->default = '';
-
- $retval[] = $F;
+ $retval[$i] = new stdClass();
+ $retval[$i]->name = pg_field_name($this->result_id, $i);
+ $retval[$i]->type = pg_field_type($this->result_id, $i);
+ $retval[$i]->max_length = pg_field_size($this->result_id, $i);
+ $retval[$i]->primary_key = 0;
+ $retval[$i]->default = '';
}
return $retval;
@@ -116,9 +108,9 @@ class CI_DB_postgre_result extends CI_DB_result {
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
if (is_resource($this->result_id))
{
@@ -132,14 +124,13 @@ class CI_DB_postgre_result extends CI_DB_result {
/**
* Data Seek
*
- * Moves the internal pointer to the desired offset. We call
+ * Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
* result set starts at zero
*
- * @access private
* @return array
*/
- function _data_seek($n = 0)
+ protected function _data_seek($n = 0)
{
return pg_result_seek($this->result_id, $n);
}
@@ -151,10 +142,9 @@ class CI_DB_postgre_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return pg_fetch_assoc($this->result_id);
}
@@ -166,16 +156,14 @@ class CI_DB_postgre_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object()
{
return pg_fetch_object($this->result_id);
}
}
-
/* End of file postgre_result.php */
-/* Location: ./system/database/drivers/postgre/postgre_result.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/postgre/postgre_result.php */
diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php
index dffd8c549..c175a382b 100644
--- a/system/database/drivers/postgre/postgre_utility.php
+++ b/system/database/drivers/postgre/postgre_utility.php
@@ -1,13 +1,13 @@
-db->display_error('db_unsuported_feature');
}
}
-
/* End of file postgre_utility.php */
-/* Location: ./system/database/drivers/postgre/postgre_utility.php */
\ No newline at end of file
+/* Location: ./system/database/drivers/postgre/postgre_utility.php */
--
cgit v1.2.3-24-g4f1b
From 0e5a17f6c736397c1e9581071cb852b5291fa97e Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 26 Jan 2012 16:49:03 +0200
Subject: Update the changelog
---
user_guide_src/source/changelog.rst | 1 +
1 file changed, 1 insertion(+)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 48011f208..0e5b21395 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -47,6 +47,7 @@ Release Date: Not Released
get_compiled_insert(), get_compiled_update(), get_compiled_delete().
- Taking care of LIKE condition when used with MySQL UPDATE statement.
- Adding $escape parameter to the order_by function, this enables ordering by custom fields.
+ - The PostgreSQL database driver now uses pg_version() for server version checking, when appropriate.
- Libraries
--
cgit v1.2.3-24-g4f1b
From ca7e5f1eb15408b9d71e55d9a0e54b96f5ddc6aa Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 26 Jan 2012 17:58:28 +0200
Subject: Call parent::__construct() in our constructor
---
system/database/drivers/cubrid/cubrid_driver.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index b89746b7d..d1fc5f0fa 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -57,8 +57,10 @@ class CI_DB_cubrid_driver extends CI_DB {
protected $_count_string = 'SELECT COUNT(*) AS ';
protected $_random_keyword = ' RAND()'; // database specific random keyword
- public function __construct()
+ public function __construct($params)
{
+ parent::__construct($params);
+
// If no port is defined by the user, use the default value
if ($this->port == '')
{
--
cgit v1.2.3-24-g4f1b
From c25c3d3d61ff38a348224252c1b3c9041e50ac32 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Fri, 27 Jan 2012 11:35:30 +0200
Subject: Remove an empty line :)
---
system/database/drivers/postgre/postgre_driver.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 8b8f33371..4e35cd6d7 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -184,7 +184,6 @@ class CI_DB_postgre_driver extends CI_DB {
*
* @return string
*/
-
public function version()
{
$version = pg_version($this->conn_id);
--
cgit v1.2.3-24-g4f1b
From 8d5b24a8c55dc1ae7721e10de094c4aba2ca7eae Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Fri, 27 Jan 2012 14:37:38 +0200
Subject: Fix issue #128
---
system/core/Lang.php | 23 ++++++++++++-----------
user_guide_src/source/changelog.rst | 1 +
2 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/system/core/Lang.php b/system/core/Lang.php
index c40a6856e..d68c04812 100755
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Language Class
*
@@ -74,22 +72,20 @@ class CI_Lang {
if ($add_suffix == TRUE)
{
- $langfile = str_replace('_lang.', '', $langfile).'_lang';
+ $langfile = str_replace('_lang', '', $langfile).'_lang';
}
$langfile .= '.php';
- if (in_array($langfile, $this->is_loaded, TRUE))
+ if ($idiom == '')
{
- return;
+ $config =& get_config();
+ $idiom = ( ! empty($config['language'])) ? $config['language'] : 'english';
}
- $config =& get_config();
-
- if ($idiom == '')
+ if ($return == FALSE && isset($this->is_loaded[$langfile]) && $this->is_loaded[$langfile] === $idiom)
{
- $deft_lang = ( ! isset($config['language'])) ? 'english' : $config['language'];
- $idiom = ($deft_lang == '') ? 'english' : $deft_lang;
+ return;
}
// Determine where the language file is and load it
@@ -121,6 +117,11 @@ class CI_Lang {
if ( ! isset($lang) OR ! is_array($lang))
{
log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile);
+
+ if ($return == TRUE)
+ {
+ return array();
+ }
return;
}
@@ -129,7 +130,7 @@ class CI_Lang {
return $lang;
}
- $this->is_loaded[] = $langfile;
+ $this->is_loaded[$langfile] = $idiom;
$this->language = array_merge($this->language, $lang);
unset($lang);
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 48011f208..71143b99b 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -97,6 +97,7 @@ Bug fixes for 3.0
- In Pagination library, when use_page_numbers=TRUE previous link and page 1 link do not have the same url
- Fixed a bug (#561) - Errors in :doc:`XML-RPC Library ` were not properly escaped.
- Fixed a bug (#904) - ``CI_Loader::initialize()`` caused a PHP Fatal error to be triggered if error level E_STRICT is used.
+- Fixed a bug (#128) - :doc:`Language Library ` did not correctly keep track of loaded language files.
Version 2.1.0
=============
--
cgit v1.2.3-24-g4f1b
From 65571d9d9684573887dc4a481b44f33b13584059 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Fri, 27 Jan 2012 14:51:58 +0200
Subject: Remove an unnecessary unset()
---
system/core/Lang.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/system/core/Lang.php b/system/core/Lang.php
index d68c04812..711ccab70 100755
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
@@ -132,7 +132,6 @@ class CI_Lang {
$this->is_loaded[$langfile] = $idiom;
$this->language = array_merge($this->language, $lang);
- unset($lang);
log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile);
return TRUE;
--
cgit v1.2.3-24-g4f1b
From 7719a037c4648be714ebe577aa38acba012f7d90 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Fri, 27 Jan 2012 21:05:55 +0200
Subject: Switch _process_fields() from private to protected
---
system/database/drivers/cubrid/cubrid_forge.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php
index 4b1c2839a..8423180e9 100644
--- a/system/database/drivers/cubrid/cubrid_forge.php
+++ b/system/database/drivers/cubrid/cubrid_forge.php
@@ -70,7 +70,7 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
* @param mixed the fields
* @return string
*/
- private function _process_fields($fields)
+ protected function _process_fields($fields)
{
$current_field_count = 0;
$sql = '';
--
cgit v1.2.3-24-g4f1b
From e90b6844701a8d7240cb2ac595c2d9d0d211d765 Mon Sep 17 00:00:00 2001
From: Kwaan Online <>
Date: Tue, 31 Jan 2012 10:15:30 +0000
Subject: - Updated timezone selete list to match function output. - Updated
timezone reference to match function output. - Note some reference locations
have been abridged so they fit the table format. A note has been added to
this effect.
---
user_guide_src/source/helpers/date_helper.rst | 152 ++++++++++++++++----------
1 file changed, 92 insertions(+), 60 deletions(-)
diff --git a/user_guide_src/source/helpers/date_helper.rst b/user_guide_src/source/helpers/date_helper.rst
index ad06dd628..bd5a3aa18 100644
--- a/user_guide_src/source/helpers/date_helper.rst
+++ b/user_guide_src/source/helpers/date_helper.rst
@@ -327,36 +327,46 @@ Generates a pull-down menu of timezones, like this one:
@@ -393,66 +403,88 @@ Timezone Reference
The following table indicates each timezone and its location.
+Note some of the location lists have been abridged for clarity and formatting.
+
+------------+----------------------------------------------------------------+
| Time Zone | Location |
+============+================================================================+
-| UM12 | (UTC - 12:00) Enitwetok, Kwajalien |
+| UM12 | (UTC - 12:00) Baker/Howland Island |
++------------+----------------------------------------------------------------+
+| UM11 | (UTC - 11:00) Samoa Time Zone, Niue |
++------------+----------------------------------------------------------------+
+| UM10 | (UTC - 10:00) Hawaii-Aleutian Standard Time, Cook Islands |
++------------+----------------------------------------------------------------+
+| UM95 | (UTC - 09:30) Marquesas Islands |
++------------+----------------------------------------------------------------+
+| UM9 | (UTC - 09:00) Alaska Standard Time, Gambier Islands |
++------------+----------------------------------------------------------------+
+| UM8 | (UTC - 08:00) Pacific Standard Time, Clipperton Island |
++------------+----------------------------------------------------------------+
+| UM7 | (UTC - 11:00) Mountain Standard Time |
++------------+----------------------------------------------------------------+
+| UM6 | (UTC - 06:00) Central Standard Time |
++------------+----------------------------------------------------------------+
+| UM5 | (UTC - 05:00) Eastern Standard Time, Western Caribbean |
++------------+----------------------------------------------------------------+
+| UM45 | (UTC - 04:30) Venezuelan Standard Time |
++------------+----------------------------------------------------------------+
+| UM4 | (UTC - 04:00) Atlantic Standard Time, Eastern Caribbean |
+------------+----------------------------------------------------------------+
-| UM11 | (UTC - 11:00) Nome, Midway Island, Samoa |
+| UM35 | (UTC - 03:30) Newfoundland Standard Time |
+------------+----------------------------------------------------------------+
-| UM10 | (UTC - 10:00) Hawaii |
+| UM3 | (UTC - 03:00) Argentina, Brazil, French Guiana, Uruguay |
+------------+----------------------------------------------------------------+
-| UM9 | (UTC - 9:00) Alaska |
+| UM2 | (UTC - 02:00) South Georgia/South Sandwich Islands |
+------------+----------------------------------------------------------------+
-| UM8 | (UTC - 8:00) Pacific Time |
+| UM1 | (UTC -1:00) Azores, Cape Verde Islands |
+------------+----------------------------------------------------------------+
-| UM7 | (UTC - 7:00) Mountain Time |
+| UTC | (UTC) Greenwich Mean Time, Western European Time |
+------------+----------------------------------------------------------------+
-| UM6 | (UTC - 6:00) Central Time, Mexico City |
+| UP1 | (UTC +1:00) Central European Time, West Africa Time |
+------------+----------------------------------------------------------------+
-| UM5 | (UTC - 5:00) Eastern Time, Bogota, Lima, Quito |
+| UP2 | (UTC +2:00) Central Africa Time, Eastern European Time |
+------------+----------------------------------------------------------------+
-| UM4 | (UTC - 4:00) Atlantic Time, Caracas, La Paz |
+| UP3 | (UTC +3:00) Moscow Time, East Africa Time |
+------------+----------------------------------------------------------------+
-| UM25 | (UTC - 3:30) Newfoundland |
+| UP35 | (UTC +3:30) Iran Standard Time |
+------------+----------------------------------------------------------------+
-| UM3 | (UTC - 3:00) Brazil, Buenos Aires, Georgetown, Falkland Is. |
+| UP4 | (UTC +4:00) Azerbaijan Standard Time, Samara Time |
+------------+----------------------------------------------------------------+
-| UM2 | (UTC - 2:00) Mid-Atlantic, Ascention Is., St Helena |
+| UP45 | (UTC +4:30) Afghanistan |
+------------+----------------------------------------------------------------+
-| UM1 | (UTC - 1:00) Azores, Cape Verde Islands |
+| UP5 | (UTC +5:00) Pakistan Standard Time, Yekaterinburg Time |
+------------+----------------------------------------------------------------+
-| UTC | (UTC) Casablanca, Dublin, Edinburgh, London, Lisbon, Monrovia |
+| UP55 | (UTC +5:30) Indian Standard Time, Sri Lanka Time |
+------------+----------------------------------------------------------------+
-| UP1 | (UTC + 1:00) Berlin, Brussels, Copenhagen, Madrid, Paris, Rome |
+| UP575 | (UTC +5:45) Nepal Time |
+------------+----------------------------------------------------------------+
-| UP2 | (UTC + 2:00) Kaliningrad, South Africa, Warsaw |
+| UP6 | (UTC +6:00) Bangladesh Standard Time, Bhutan Time, Omsk Time |
+------------+----------------------------------------------------------------+
-| UP3 | (UTC + 3:00) Baghdad, Riyadh, Moscow, Nairobi |
+| UP65 | (UTC +6:30) Cocos Islands, Myanmar |
+------------+----------------------------------------------------------------+
-| UP25 | (UTC + 3:30) Tehran |
+| UP7 | (UTC +7:00) Krasnoyarsk Time, Cambodia, Laos, Thailand, Vietnam|
+------------+----------------------------------------------------------------+
-| UP4 | (UTC + 4:00) Adu Dhabi, Baku, Muscat, Tbilisi |
+| UP8 | (UTC +8:00) Australian Western Standard Time, Beijing Time |
+------------+----------------------------------------------------------------+
-| UP35 | (UTC + 4:30) Kabul |
+| UP875 | (UTC +8:45) Australian Central Western Standard Time |
+------------+----------------------------------------------------------------+
-| UP5 | (UTC + 5:00) Islamabad, Karachi, Tashkent |
+| UP9 | (UTC +9:00) Japan Standard Time, Korea Standard Time, Yakutsk |
+------------+----------------------------------------------------------------+
-| UP45 | (UTC + 5:30) Bombay, Calcutta, Madras, New Delhi |
+| UP95 | (UTC +9:30) Australian Central Standard Time |
+------------+----------------------------------------------------------------+
-| UP6 | (UTC + 6:00) Almaty, Colomba, Dhaka |
+| UP10 | (UTC +10:00) Australian Eastern Standard Time, Vladivostok Time|
+------------+----------------------------------------------------------------+
-| UP7 | (UTC + 7:00) Bangkok, Hanoi, Jakarta |
+| UP105 | (UTC +10:30) Lord Howe Island |
+------------+----------------------------------------------------------------+
-| UP8 | (UTC + 8:00) Beijing, Hong Kong, Perth, Singapore, Taipei |
+| UP11 | (UTC +11:00) Magadan Time, Solomon Islands, Vanuatu |
+------------+----------------------------------------------------------------+
-| UP9 | (UTC + 9:00) Osaka, Sapporo, Seoul, Tokyo, Yakutsk |
+| UP115 | (UTC +11:30) Norfolk Island |
+------------+----------------------------------------------------------------+
-| UP85 | (UTC + 9:30) Adelaide, Darwin |
+| UP12 | (UTC +12:00) Fiji, Gilbert Islands, Kamchatka, New Zealand |
+------------+----------------------------------------------------------------+
-| UP10 | (UTC + 10:00) Melbourne, Papua New Guinea, Sydney, Vladivostok |
+| UP1275 | (UTC +12:45) Chatham Islands Standard Time |
+------------+----------------------------------------------------------------+
-| UP11 | (UTC + 11:00) Magadan, New Caledonia, Solomon Islands |
+| UP13 | (UTC +13:00) Phoenix Islands Time, Tonga |
+------------+----------------------------------------------------------------+
-| UP12 | (UTC + 12:00) Auckland, Wellington, Fiji, Marshall Island |
+| UP14 | (UTC +14:00) Line Islands |
+------------+----------------------------------------------------------------+
--
cgit v1.2.3-24-g4f1b
From d33e24c2a649420d420ad9b11efb1bbf2421114c Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Sun, 12 Feb 2012 03:23:07 +0200
Subject: Add SQLite escape character
---
system/database/drivers/sqlite/sqlite_driver.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index 119722d2f..25e012bf0 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -43,7 +43,7 @@ class CI_DB_sqlite_driver extends CI_DB {
public $dbdriver = 'sqlite';
// The character used to escape with - not needed for SQLite
- protected $_escape_char = '';
+ protected $_escape_char = '"';
// clause and character used for LIKE escape sequences
protected $_like_escape_str = ' ESCAPE \'%s\' ';
@@ -338,7 +338,7 @@ class CI_DB_sqlite_driver extends CI_DB {
}
$query = $query->row();
- $this->_reset_select();
+ $this->_data_seek(0);
return (int) $query->numrows;
}
--
cgit v1.2.3-24-g4f1b
From 7e93489fed826286abe2d0b5abd65badc13beab9 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Sun, 12 Feb 2012 03:29:06 +0200
Subject: Fix issue #81
---
system/database/drivers/odbc/odbc_result.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php
index 509c77a1b..115ba665c 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -145,7 +145,7 @@ class CI_DB_odbc_result extends CI_DB_result {
*/
protected function _fetch_assoc()
{
- return function_exists('odbc_fetch_object')
+ return function_exists('odbc_fetch_array')
? odbc_fetch_array($this->result_id)
: $this->_odbc_fetch_array($this->result_id);
}
@@ -185,7 +185,7 @@ class CI_DB_odbc_result extends CI_DB_result {
$rs_obj = new stdClass();
foreach ($rs as $k => $v)
{
- $field_name = odbc_field_name($odbc_result, $k+1);
+ $field_name = odbc_field_name($odbc_result, $k);
$rs_obj->$field_name = $v;
}
@@ -212,7 +212,7 @@ class CI_DB_odbc_result extends CI_DB_result {
$rs_assoc = array();
foreach ($rs as $k => $v)
{
- $field_name = odbc_field_name($odbc_result, $k+1);
+ $field_name = odbc_field_name($odbc_result, $k);
$rs_assoc[$field_name] = $v;
}
--
cgit v1.2.3-24-g4f1b
From 47489fbbb38b85584adf34032c4a88477713ddd4 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Sun, 12 Feb 2012 03:30:48 +0200
Subject: Update the changelog
---
user_guide_src/source/changelog.rst | 1 +
1 file changed, 1 insertion(+)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 649616e8d..172250133 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -104,6 +104,7 @@ Bug fixes for 3.0
- Fixed a hosting edge case where an empty $_SERVER['HTTPS'] variable would evaluate to 'on'
- Fixed a bug (#154) - ``CI_Session::sess_update()`` caused the session to be destroyed on pages where multiple AJAX requests were executed at once.
- Fixed a possible bug in ``CI_Input::is_ajax_request()`` where some clients might not send the X-Requested-With HTTP header value exactly as 'XmlHttpRequest'.
+- Fixed a bug (#81) - ODBC result sets used to skip the first row.
Version 2.1.0
=============
--
cgit v1.2.3-24-g4f1b
From bd601d3d18531fa543ee57befac7cba6739c419b Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Sun, 12 Feb 2012 21:16:51 +0200
Subject: Added port handling support for UNIX systems and moved it to the
constructor
---
system/database/drivers/mssql/mssql_driver.php | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 611a4afba..c273323d8 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -57,6 +57,16 @@ class CI_DB_mssql_driver extends CI_DB {
protected $_count_string = 'SELECT COUNT(*) AS ';
protected $_random_keyword = ' NEWID()';
+ public function __construct($params)
+ {
+ parent::__construct($params);
+
+ if ( ! empty($this->port) && ctype_digit($this->port))
+ {
+ $this->hostname .= (DIRECTORY_SEPARATOR === '\\' ? ',' : ':').$this->port;
+ }
+ }
+
/**
* Non-persistent database connection
*
@@ -64,11 +74,6 @@ class CI_DB_mssql_driver extends CI_DB {
*/
public function db_connect()
{
- if ($this->port != '')
- {
- $this->hostname .= ','.$this->port;
- }
-
return @mssql_connect($this->hostname, $this->username, $this->password);
}
@@ -81,11 +86,6 @@ class CI_DB_mssql_driver extends CI_DB {
*/
public function db_pconnect()
{
- if ($this->port != '')
- {
- $this->hostname .= ','.$this->port;
- }
-
return @mssql_pconnect($this->hostname, $this->username, $this->password);
}
--
cgit v1.2.3-24-g4f1b
From a64c61a77b0e1fb23d2063d4f54fef64c93e7e36 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Sun, 12 Feb 2012 22:26:46 +0200
Subject: Improve DSN string support
---
system/database/drivers/postgre/postgre_driver.php | 63 +++++++++++++++-------
1 file changed, 44 insertions(+), 19 deletions(-)
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 4779799a4..89c0cd0c9 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -56,9 +56,6 @@ class CI_DB_postgre_driver extends CI_DB {
protected $_count_string = 'SELECT COUNT(*) AS ';
protected $_random_keyword = ' RANDOM()'; // database specific random keyword
- // Postgre-specific properties
- protected $_pg_dsn;
-
/**
* Constructor
*
@@ -70,26 +67,54 @@ class CI_DB_postgre_driver extends CI_DB {
{
parent::__construct($params);
- $components = array(
- 'hostname' => 'host',
- 'port' => 'port',
- 'database' => 'dbname',
- 'username' => 'user',
- 'password' => 'password'
- );
+ if ( ! empty($this->dsn))
+ {
+ return;
+ }
- foreach ($components as $key => $val)
+ $this->dsn === '' OR $this->dsn = '';
+
+ if (strpos($this->hostname, '/') !== FALSE)
{
- if (isset($this->$key) && $this->$key != '')
- {
- $this->_pg_dsn .= $val.'='.$this->$key.' ';
- }
+ // If UNIX sockets are used, we shouldn't set a port
+ $this->port = '';
}
- if (strlen($this->_pg_dsn) > 0)
+ $this->hostname === '' OR $this->dsn = 'host='.$this->hostname;
+
+ if ( ! empty($this->port) && ctype_digit($this->port))
{
- $this->_pg_dsn = rtrim($this->_pg_dsn);
+ $this->dsn .= 'host='.$this->port.' ';
}
+
+ if ($this->username !== '')
+ {
+ $this->dsn .= 'username='.$this->username.' ';
+
+ /* An empty password is valid!
+ *
+ * $db['password'] = NULL must be done in order to ignore it.
+ */
+ $this->password === NULL OR $this->dsn .= "password='".$this->password."' ";
+ }
+
+ $this->database === '' OR $this->dsn .= 'dbname='.$this->database.' ';
+
+ /* We don't have these options as elements in our standard configuration
+ * array, but they might be set by parse_url() if the configuration was
+ * provided via string. Example:
+ *
+ * postgre://username:password@localhost:5432/database?connect_timeout=5&sslmode=1
+ */
+ foreach (array('connect_timeout', 'options', 'sslmode', 'service') as $key)
+ {
+ if (isset($this->$key) && is_string($this->key) && $this->key !== '')
+ {
+ $this->dsn .= $key."='".$this->key."' ";
+ }
+ }
+
+ $this->dsn = rtrim($this->dsn);
}
// --------------------------------------------------------------------
@@ -101,7 +126,7 @@ class CI_DB_postgre_driver extends CI_DB {
*/
public function db_connect()
{
- $ret = @pg_connect($this->_pg_dsn);
+ $ret = @pg_connect($this->dsn);
if (is_resource($ret) && $this->char_set != '')
{
pg_set_client_encoding($ret, $this->char_set);
@@ -119,7 +144,7 @@ class CI_DB_postgre_driver extends CI_DB {
*/
public function db_pconnect()
{
- $ret = @pg_pconnect($this->_pg_dsn);
+ $ret = @pg_pconnect($this->dsn);
if (is_resource($ret) && $this->char_set != '')
{
pg_set_client_encoding($ret, $this->char_set);
--
cgit v1.2.3-24-g4f1b
From 2854724143db31f3bb0821c168314de51480bd43 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Sun, 12 Feb 2012 22:30:14 +0200
Subject: Use protect_identifiers() instead of _escape_identifiers() in
CI_DB_postgre_forge
---
system/database/drivers/postgre/postgre_forge.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php
index f9c79bf29..6030adf38 100644
--- a/system/database/drivers/postgre/postgre_forge.php
+++ b/system/database/drivers/postgre/postgre_forge.php
@@ -172,7 +172,7 @@ class CI_DB_postgre_forge extends CI_DB_forge {
}
}
- $sql .= $this->db->_escape_identifiers($table).' ('.$this->_process_fields($fields, $primary_keys);
+ $sql .= $this->db->protect_identifiers($table).' ('.$this->_process_fields($fields, $primary_keys);
if (count($primary_keys) > 0)
{
@@ -220,7 +220,7 @@ class CI_DB_postgre_forge extends CI_DB_forge {
*/
public function _drop_table($table)
{
- return 'DROP TABLE IF EXISTS '.$this->db->_escape_identifiers($table).' CASCADE';
+ return 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table).' CASCADE';
}
// --------------------------------------------------------------------
--
cgit v1.2.3-24-g4f1b
From 2e430a3f3b160641c36037fbaf92457e0b3bb51e Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Sun, 12 Feb 2012 23:37:58 +0200
Subject: Added CUBRID DSN string & persistent connections support
---
system/database/drivers/cubrid/cubrid_driver.php | 104 +++++++++++++----------
system/database/drivers/cubrid/cubrid_forge.php | 4 +-
2 files changed, 60 insertions(+), 48 deletions(-)
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index d1fc5f0fa..f7dec72de 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -57,15 +57,21 @@ class CI_DB_cubrid_driver extends CI_DB {
protected $_count_string = 'SELECT COUNT(*) AS ';
protected $_random_keyword = ' RAND()'; // database specific random keyword
+ // CUBRID-specific properties
+ public $auto_commit = TRUE;
+
public function __construct($params)
{
parent::__construct($params);
- // If no port is defined by the user, use the default value
- if ($this->port == '')
+ if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:[^:]*:[^:]*:(\?.+)?$/', $this->dsn, $matches))
{
- // Default CUBRID broker port
- $this->port = 33000;
+ preg_match('/autocommit=on/', $matches[2], $matches) OR $this->auto_commit = FALSE;
+ }
+ else
+ {
+ // If no port is defined by the user, use the default value
+ $this->port == '' OR $this->port = 33000;
}
}
@@ -76,44 +82,62 @@ class CI_DB_cubrid_driver extends CI_DB {
*/
public function db_connect()
{
- $conn = cubrid_connect($this->hostname, $this->port, $this->database, $this->username, $this->password);
-
- if ($conn)
- {
- // Check if a user wants to run queries in dry, i.e. run the
- // queries but not commit them.
- if (isset($this->auto_commit) && ! $this->auto_commit)
- {
- cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_FALSE);
- }
- else
- {
- cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_TRUE);
- $this->auto_commit = TRUE;
- }
- }
-
- return $conn;
+ return $this->_cubrid_connect();
}
// --------------------------------------------------------------------
/**
* Persistent database connection
+ *
* In CUBRID persistent DB connection is supported natively in CUBRID
* engine which can be configured in the CUBRID Broker configuration
* file by setting the CCI_PCONNECT parameter to ON. In that case, all
* connections established between the client application and the
- * server will become persistent. This is calling the same
- * @cubrid_connect function will establish persisten connection
- * considering that the CCI_PCONNECT is ON.
+ * server will become persistent.
*
- * @access private called by the base class
* @return resource
*/
public function db_pconnect()
{
- return $this->db_connect();
+ return $this->_cubrid_connect(TRUE);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * CUBRID connection
+ *
+ * A CUBRID-specific method to create a connection to the database.
+ * Except for determining if a persistent connection should be used,
+ * the rest of the logic is the same for db_connect() and db_pconnect().
+ *
+ * @param bool
+ * @return resource
+ */
+ protected function _cubrid_connect($persistent = FALSE)
+ {
+ if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:([^:]*):([^:]*):(\?.+)?$/', $this->dsn, $matches))
+ {
+ $conn_id = ($matches[2] === '' && $matches[3] === '' && $this->username !== '' && $this->password !== '')
+ ? cubrid_connect_with_url($this->dsn, $this->username, $this->password)
+ : cubrid_connect_with_url($this->dsn);
+ }
+ else
+ {
+ $_temp = ($persistent !== TRUE) ? 'cubrid_connect' : 'cubrid_pconnect';
+ $conn_id = ($this->username !== '')
+ ? $_temp($this->hostname, $this->port, $this->database, $this->username, $this->password)
+ : $_temp($this->hostname, $this->port, $this->database);
+ }
+
+ if ($conn_id)
+ {
+ $_temp = ($this->auto_commit) ? CUBRID_AUTOCOMMIT_TRUE : CUBRID_AUTOCOMMIT_FALSE;
+ cubrid_set_autocommit($conn_id, $_temp);
+ }
+
+ return $conn_id;
}
// --------------------------------------------------------------------
@@ -161,9 +185,7 @@ class CI_DB_cubrid_driver extends CI_DB {
*/
public function db_set_charset($charset, $collation)
{
- // In CUBRID, there is no need to set charset or collation.
- // This is why returning true will allow the application continue
- // its normal process.
+ // Not supported in CUBRID
return TRUE;
}
@@ -189,8 +211,7 @@ class CI_DB_cubrid_driver extends CI_DB {
*/
protected function _execute($sql)
{
- $sql = $this->_prep_query($sql);
- return @cubrid_query($sql, $this->conn_id);
+ return @cubrid_query($this->_prep_query($sql), $this->conn_id);
}
// --------------------------------------------------------------------
@@ -205,7 +226,6 @@ class CI_DB_cubrid_driver extends CI_DB {
*/
protected function _prep_query($sql)
{
- // No need to prepare
return $sql;
}
@@ -385,7 +405,7 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param boolean
+ * @param bool
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -607,8 +627,6 @@ class CI_DB_cubrid_driver extends CI_DB {
protected function _update_batch($table, $values, $index, $where = NULL)
{
$ids = array();
- $where = ($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '';
-
foreach ($values as $key => $val)
{
$ids[] = $val[$index];
@@ -622,9 +640,7 @@ class CI_DB_cubrid_driver extends CI_DB {
}
}
- $sql = 'UPDATE '.$table.' SET ';
$cases = '';
-
foreach ($final as $k => $v)
{
$cases .= $k." = CASE \n"
@@ -632,7 +648,7 @@ class CI_DB_cubrid_driver extends CI_DB {
.'ELSE '.$k.' END, ';
}
- return $sql.substr($cases, 0, -2)
+ return 'UPDATE '.$table.' SET '.substr($cases, 0, -2)
.' WHERE '.(($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '')
.$index.' IN ('.implode(',', $ids).')';
}
@@ -672,13 +688,9 @@ class CI_DB_cubrid_driver extends CI_DB {
if (count($where) > 0 OR count($like) > 0)
{
- $conditions = "\nWHERE ".implode("\n", $this->ar_where);
-
- if (count($where) > 0 && count($like) > 0)
- {
- $conditions .= ' AND ';
- }
- $conditions .= implode("\n", $like);
+ $conditions = "\nWHERE ".implode("\n", $where)
+ .((count($where) > 0 && count($like) > 0) ? ' AND ' : '')
+ .implode("\n", $like);
}
return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit);
diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php
index 8423180e9..11143a05f 100644
--- a/system/database/drivers/cubrid/cubrid_forge.php
+++ b/system/database/drivers/cubrid/cubrid_forge.php
@@ -163,7 +163,7 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
}
*/
- $sql .= $this->db->_escape_identifiers($table).' ('.$this->_process_fields($fields);
+ $sql .= $this->db->protect_identifiers($table).' ('.$this->_process_fields($fields);
// If there is a PK defined
if (count($primary_keys) > 0)
@@ -203,7 +203,7 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
*/
public function _drop_table($table)
{
- return 'DROP TABLE IF EXISTS '.$this->db->_escape_identifiers($table);
+ return 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table);
}
// --------------------------------------------------------------------
--
cgit v1.2.3-24-g4f1b
From 6ae2852d0e5b112baa302995d1448f1147a7bf0e Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Sun, 12 Feb 2012 23:41:46 +0200
Subject: Update the changelog
---
user_guide_src/source/changelog.rst | 2 ++
1 file changed, 2 insertions(+)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 649616e8d..31b99ee5f 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -51,6 +51,8 @@ Release Date: Not Released
- MySQLi driver now supports persistent connections when running on PHP >= 5.3.
- Added dsn if the group connections in the config use PDO or any driver which need DSN.
- Improved PDO database support.
+ - Added DSN string support for CUBRID.
+ - Added persistent connections support for CUBRID.
- Libraries
--
cgit v1.2.3-24-g4f1b
From 46f6dbc6a60e37ad1b88458f8cdfd3e1d1d94f5e Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Mon, 13 Feb 2012 01:39:53 +0200
Subject: Added DSN string support
---
system/database/drivers/odbc/odbc_driver.php | 10 ++++++++--
user_guide_src/source/changelog.rst | 1 +
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index a674c390e..c9aaa6e68 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -62,6 +62,12 @@ class CI_DB_odbc_driver extends CI_DB {
parent::__construct($params);
$this->_random_keyword = ' RND('.time().')'; // database specific random keyword
+
+ // Legacy support for DSN in the hostname field
+ if ($this->dsn == '')
+ {
+ $this->dsn = $this->hostname;
+ }
}
/**
@@ -71,7 +77,7 @@ class CI_DB_odbc_driver extends CI_DB {
*/
public function db_connect()
{
- return @odbc_connect($this->hostname, $this->username, $this->password);
+ return @odbc_connect($this->dsn, $this->username, $this->password);
}
// --------------------------------------------------------------------
@@ -83,7 +89,7 @@ class CI_DB_odbc_driver extends CI_DB {
*/
public function db_pconnect()
{
- return @odbc_pconnect($this->hostname, $this->username, $this->password);
+ return @odbc_pconnect($this->dsn, $this->username, $this->password);
}
// --------------------------------------------------------------------
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 172250133..1a38f5249 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -51,6 +51,7 @@ Release Date: Not Released
- MySQLi driver now supports persistent connections when running on PHP >= 5.3.
- Added dsn if the group connections in the config use PDO or any driver which need DSN.
- Improved PDO database support.
+ - Added DSN string support for ODBC.
- Libraries
--
cgit v1.2.3-24-g4f1b
From 36cd531e9874d32a272088838055bdd56045c41b Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Mon, 13 Feb 2012 01:40:55 +0200
Subject: Fix auto_commit initialization
---
system/database/drivers/cubrid/cubrid_driver.php | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index f7dec72de..a0d874a8c 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -66,7 +66,10 @@ class CI_DB_cubrid_driver extends CI_DB {
if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:[^:]*:[^:]*:(\?.+)?$/', $this->dsn, $matches))
{
- preg_match('/autocommit=on/', $matches[2], $matches) OR $this->auto_commit = FALSE;
+ if (preg_match('/autocommit=off/', $matches[2], $matches))
+ {
+ $this->auto_commit = FALSE;
+ }
}
else
{
--
cgit v1.2.3-24-g4f1b
From fe4b4e9d5f5c19da77c8e675f33f030766019ac3 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Mon, 13 Feb 2012 05:40:25 +0200
Subject: Fix pconnect with DSN
---
system/database/drivers/cubrid/cubrid_driver.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index a0d874a8c..8d5344af9 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -122,9 +122,10 @@ class CI_DB_cubrid_driver extends CI_DB {
{
if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:([^:]*):([^:]*):(\?.+)?$/', $this->dsn, $matches))
{
+ $_temp = ($persistent !== TRUE) ? 'cubrid_connect_with_url' : 'cubrid_pconnect_with_url';
$conn_id = ($matches[2] === '' && $matches[3] === '' && $this->username !== '' && $this->password !== '')
- ? cubrid_connect_with_url($this->dsn, $this->username, $this->password)
- : cubrid_connect_with_url($this->dsn);
+ ? $_temp($this->dsn, $this->username, $this->password)
+ : $_temp($this->dsn);
}
else
{
--
cgit v1.2.3-24-g4f1b
From d0b256f96d81d5577c619c3912db9a0e79a43b6c Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Mon, 13 Feb 2012 12:20:11 +0200
Subject: Revert fix for #81 - it actually breaks things
---
system/database/drivers/odbc/odbc_result.php | 4 ++--
user_guide_src/source/changelog.rst | 1 -
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php
index 115ba665c..06d99226e 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -185,7 +185,7 @@ class CI_DB_odbc_result extends CI_DB_result {
$rs_obj = new stdClass();
foreach ($rs as $k => $v)
{
- $field_name = odbc_field_name($odbc_result, $k);
+ $field_name = odbc_field_name($odbc_result, $k+1);
$rs_obj->$field_name = $v;
}
@@ -212,7 +212,7 @@ class CI_DB_odbc_result extends CI_DB_result {
$rs_assoc = array();
foreach ($rs as $k => $v)
{
- $field_name = odbc_field_name($odbc_result, $k);
+ $field_name = odbc_field_name($odbc_result, $k+1);
$rs_assoc[$field_name] = $v;
}
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 1a38f5249..79d26ba5b 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -105,7 +105,6 @@ Bug fixes for 3.0
- Fixed a hosting edge case where an empty $_SERVER['HTTPS'] variable would evaluate to 'on'
- Fixed a bug (#154) - ``CI_Session::sess_update()`` caused the session to be destroyed on pages where multiple AJAX requests were executed at once.
- Fixed a possible bug in ``CI_Input::is_ajax_request()`` where some clients might not send the X-Requested-With HTTP header value exactly as 'XmlHttpRequest'.
-- Fixed a bug (#81) - ODBC result sets used to skip the first row.
Version 2.1.0
=============
--
cgit v1.2.3-24-g4f1b
From cac407d6399e9325454b48418cf3fce873ce1b14 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Tue, 14 Feb 2012 11:45:36 +0200
Subject: Replace a preg_match() with stripos()
---
system/database/drivers/cubrid/cubrid_driver.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index 8d5344af9..147e463ce 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -66,7 +66,7 @@ class CI_DB_cubrid_driver extends CI_DB {
if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:[^:]*:[^:]*:(\?.+)?$/', $this->dsn, $matches))
{
- if (preg_match('/autocommit=off/', $matches[2], $matches))
+ if (stripos($matches[2], 'autocommit=off') !== FALSE)
{
$this->auto_commit = FALSE;
}
--
cgit v1.2.3-24-g4f1b
From bb8a68344931fc4621b8c3a173a7dcd572890fd8 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Tue, 14 Feb 2012 12:17:13 +0200
Subject: Fix issue #81
---
system/database/drivers/odbc/odbc_result.php | 22 ++++++++++++++--------
user_guide_src/source/changelog.rst | 1 +
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php
index 06d99226e..320b9327c 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -67,13 +67,19 @@ class CI_DB_odbc_result extends CI_DB_result {
*/
public function list_fields()
{
- $field_names = array();
- for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
+ $num_fields = $this->num_fields();
+ if ($num_fields > 0)
{
- $field_names[] = odbc_field_name($this->result_id, $i);
+ $field_names = array();
+ for ($i = 1; $i <= $num_fields; $i++)
+ {
+ $field_names[] = odbc_field_name($this->result_id, $i);
+ }
+
+ return $field_names;
}
- return $field_names;
+ return array();
}
// --------------------------------------------------------------------
@@ -88,12 +94,12 @@ class CI_DB_odbc_result extends CI_DB_result {
public function field_data()
{
$retval = array();
- for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
+ for ($i = 0, $odbc_index = 1, $c = $this->num_fields(); $i < $c; $i++, $odbc_index++)
{
$retval[$i] = new stdClass();
- $retval[$i]->name = odbc_field_name($this->result_id, $i);
- $retval[$i]->type = odbc_field_type($this->result_id, $i);
- $retval[$i]->max_length = odbc_field_len($this->result_id, $i);
+ $retval[$i]->name = odbc_field_name($this->result_id, $odbc_index);
+ $retval[$i]->type = odbc_field_type($this->result_id, $odbc_index);
+ $retval[$i]->max_length = odbc_field_len($this->result_id, $odbc_index);
$retval[$i]->primary_key = 0;
$retval[$i]->default = '';
}
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 93348566c..e08f3be89 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -106,6 +106,7 @@ Bug fixes for 3.0
- Fixed a hosting edge case where an empty $_SERVER['HTTPS'] variable would evaluate to 'on'
- Fixed a bug (#154) - ``CI_Session::sess_update()`` caused the session to be destroyed on pages where multiple AJAX requests were executed at once.
- Fixed a possible bug in ``CI_Input::is_ajax_request()`` where some clients might not send the X-Requested-With HTTP header value exactly as 'XmlHttpRequest'.
+- Fixed a bug (#81) - ODBC's list_field() and field_data() methods skipped the first column due to odbc_field_*() functions' index starting at 1 instead of 0.
Version 2.1.0
=============
--
cgit v1.2.3-24-g4f1b
From 394a3f171c72176d3e31a2562e604a26a703f957 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Wed, 15 Feb 2012 14:35:11 +0200
Subject: Add improvements from @CUBRID's implementation
---
system/database/drivers/cubrid/cubrid_driver.php | 33 +++++++-------
system/database/drivers/cubrid/cubrid_forge.php | 26 ++++++-----
system/database/drivers/cubrid/cubrid_result.php | 54 +++++------------------
system/database/drivers/cubrid/cubrid_utility.php | 11 ++---
user_guide_src/source/changelog.rst | 2 +
5 files changed, 48 insertions(+), 78 deletions(-)
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index 147e463ce..aa8e997ce 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -43,7 +43,7 @@ class CI_DB_cubrid_driver extends CI_DB {
public $dbdriver = 'cubrid';
// The character used for escaping - no need in CUBRID
- protected $_escape_char = '';
+ protected $_escape_char = '`';
// clause and character used for LIKE escape sequences - not used in CUBRID
protected $_like_escape_str = '';
@@ -135,12 +135,6 @@ class CI_DB_cubrid_driver extends CI_DB {
: $_temp($this->hostname, $this->port, $this->database);
}
- if ($conn_id)
- {
- $_temp = ($this->auto_commit) ? CUBRID_AUTOCOMMIT_TRUE : CUBRID_AUTOCOMMIT_FALSE;
- cubrid_set_autocommit($conn_id, $_temp);
- }
-
return $conn_id;
}
@@ -332,7 +326,9 @@ class CI_DB_cubrid_driver extends CI_DB {
return $str;
}
- if (function_exists('cubrid_real_escape_string') && is_resource($this->conn_id))
+ if (function_exists('cubrid_real_escape_string') &&
+ (is_resource($this->conn_id)
+ OR (get_resource_type($this->conn_id) === 'Unknown' && preg_match('/Resource id #/', strval($this->conn_id)))))
{
$str = cubrid_real_escape_string($str, $this->conn_id);
}
@@ -359,7 +355,7 @@ class CI_DB_cubrid_driver extends CI_DB {
*/
public function affected_rows()
{
- return @cubrid_affected_rows($this->conn_id);
+ return @cubrid_affected_rows();
}
// --------------------------------------------------------------------
@@ -550,7 +546,7 @@ class CI_DB_cubrid_driver extends CI_DB {
*/
protected function _insert($table, $keys, $values)
{
- return 'INSERT INTO '.$table.' ("'.implode('", "', $keys).'") VALUES ('.implode(', ', $values).')';
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -568,7 +564,7 @@ class CI_DB_cubrid_driver extends CI_DB {
*/
protected function _replace($table, $keys, $values)
{
- return 'REPLACE INTO '.$table.' ("'.implode('", "', $keys).'") VALUES ('.implode(', ', $values).')';
+ return 'REPLACE INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
}
// --------------------------------------------------------------------
@@ -585,7 +581,7 @@ class CI_DB_cubrid_driver extends CI_DB {
*/
protected function _insert_batch($table, $keys, $values)
{
- return 'INSERT INTO '.$table.' ("'.implode('", "', $keys).'") VALUES '.implode(', ', $values);
+ return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES '.implode(', ', $values);
}
// --------------------------------------------------------------------
@@ -602,15 +598,20 @@ class CI_DB_cubrid_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
- protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array())
{
foreach ($values as $key => $val)
{
- $valstr[] = sprintf('"%s" = %s', $key, $val);
+ $valstr[] = $key.' = '.$val;
+ }
+
+ $where = ($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '';
+ if (count($like) > 0)
+ {
+ $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like);
}
- return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
- .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '')
+ return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where
.(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '')
.( ! $limit ? '' : ' LIMIT '.$limit);
}
diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php
index 11143a05f..5f7985705 100644
--- a/system/database/drivers/cubrid/cubrid_forge.php
+++ b/system/database/drivers/cubrid/cubrid_forge.php
@@ -21,7 +21,7 @@
* @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
- * @since Version 1.0
+ * @since Version 3.0
* @filesource
*/
@@ -42,8 +42,8 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
*/
public function _create_database($name)
{
- // CUBRID does not allow to create a database in SQL. The GUI tools
- // have to be used for this purpose.
+ // CUBRID does not allow to create a database in SQL. GUI or
+ // command line tools have to be used for this purpose.
return FALSE;
}
@@ -57,8 +57,8 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
*/
public function _drop_database($name)
{
- // CUBRID does not allow to drop a database in SQL. The GUI tools
- // have to be used for this purpose.
+ // CUBRID does not allow to drop a database in SQL. GUI or
+ // command line tools have to be used for this purpose.
return FALSE;
}
@@ -88,7 +88,7 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
- $sql .= "\n\t\"".$this->db->protect_identifiers($field).'"'
+ $sql .= "\n\t".$this->db->protect_identifiers($field)
.( ! empty($attributes['NAME']) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : '');
if ( ! empty($attributes['TYPE']))
@@ -104,7 +104,9 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
case 'numeric':
$sql .= '('.implode(',', $attributes['CONSTRAINT']).')';
break;
- case 'enum': // As of version 8.4.0 CUBRID does not support enum data type
+ case 'enum':
+ // Will be supported in the future as part a part of
+ // MySQL compatibility features.
break;
case 'set':
$sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")';
@@ -115,7 +117,7 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
}
}
- /* As of version 8.4.0 CUBRID does not support UNSIGNED INTEGER data type.
+ /* As of version 8.4.1 CUBRID does not support UNSIGNED INTEGER data type.
* Will be supported in the next release as a part of MySQL Compatibility.
*
if (isset($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
@@ -156,7 +158,7 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
{
$sql = 'CREATE TABLE ';
- /* As of version 8.4.0 CUBRID does not support this SQL syntax.
+ /* As of version 8.4.1 CUBRID does not support this SQL syntax.
if ($if_not_exists === TRUE)
{
$sql .= 'IF NOT EXISTS ';
@@ -168,7 +170,7 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
// If there is a PK defined
if (count($primary_keys) > 0)
{
- $key_name = 'pk_'.$table.'_'.$this->db->protect_identifiers(implode('_', $primary_keys));
+ $key_name = $this->db->protect_identifiers('pk_'.$table.'_'.implode('_', $primary_keys));
$sql .= ",\n\tCONSTRAINT ".$key_name.' PRIMARY KEY('.implode(', ', $this->db->protect_identifiers($primary_keys)).')';
}
@@ -178,12 +180,12 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key_name = $this->db->protect_identifiers(implode('_', $key));
+ $key_name = $this->db->protect_identifiers('idx_'.$table.implode('_', $key));
$key = $this->db->protect_identifiers($key);
}
else
{
- $key_name = $this->db->protect_identifiers($key);
+ $key_name = $this->db->protect_identifiers('idx_'.$table.$key);
$key = array($key_name);
}
diff --git a/system/database/drivers/cubrid/cubrid_result.php b/system/database/drivers/cubrid/cubrid_result.php
index 7a72cdde4..3351b3430 100644
--- a/system/database/drivers/cubrid/cubrid_result.php
+++ b/system/database/drivers/cubrid/cubrid_result.php
@@ -83,51 +83,21 @@ class CI_DB_cubrid_result extends CI_DB_result {
*/
public function field_data()
{
- $retval = $tablePrimaryKeys = array();
+ $retval = array();
+ $i = 0;
while ($field = cubrid_fetch_field($this->result_id))
{
- $F = new stdClass();
- $F->name = $field->name;
- $F->type = $field->type;
- $F->default = $field->def;
- $F->max_length = $field->max_length;
-
- // At this moment primary_key property is not returned when
- // cubrid_fetch_field is called. The following code will
- // provide a patch for it. primary_key property will be added
- // in the next release.
-
- // TODO: later version of CUBRID will provide primary_key
- // property.
- // When PK is defined in CUBRID, an index is automatically
- // created in the db_index system table in the form of
- // pk_tblname_fieldname. So the following will count how many
- // columns are there which satisfy this format.
- // The query will search for exact single columns, thus
- // compound PK is not supported.
- $res = cubrid_query($this->conn_id,
- "SELECT COUNT(*) FROM db_index WHERE class_name = '".$field->table
- ."' AND is_primary_key = 'YES' AND index_name = 'pk_".$field->table.'_'.$field->name."'"
- );
-
- if ($res)
- {
- $row = cubrid_fetch_array($res, CUBRID_NUM);
- $F->primary_key = ($row[0] > 0 ? 1 : NULL);
- }
- else
- {
- $F->primary_key = NULL;
- }
-
- if (is_resource($res))
- {
- cubrid_close_request($res);
- $this->result_id = FALSE;
- }
-
- $retval[] = $F;
+ $retval[$i] = new stdClass();
+ $retval[$i]->name = $field->name;
+ // CUBRID returns type as e.g. varchar(100),
+ // so we need to remove all digits and brackets.
+ $retval[$i]->type = preg_replace('/[\d()]/', '', $field->type);
+ $retval[$i]->default = $field->def;
+ // Use CUBRID's native API to obtain column's max_length,
+ // otherwise $field->max_length has incorrect info
+ $retval[$i]->max_length = cubrid_field_len($this->result_id, $i);
+ $retval[$i++]->primary_key = $field->primary_key;
}
return $retval;
diff --git a/system/database/drivers/cubrid/cubrid_utility.php b/system/database/drivers/cubrid/cubrid_utility.php
index dbfbe5f6b..ab9056ffb 100644
--- a/system/database/drivers/cubrid/cubrid_utility.php
+++ b/system/database/drivers/cubrid/cubrid_utility.php
@@ -21,7 +21,7 @@
* @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
- * @since Version 1.0
+ * @since Version 3.0
* @filesource
*/
@@ -39,14 +39,9 @@ class CI_DB_cubrid_utility extends CI_DB_utility {
*
* @return array
*/
- public function _list_databases()
+ public function list_databases()
{
- // CUBRID does not allow to see the list of all databases on the
- // server. It is the way its architecture is designed. Every
- // database is independent and isolated.
- // For this reason we can return only the name of the currect
- // connected database.
- return "SELECT '".$this->database."'";
+ return $this->data_cache['db_names'] = cubrid_list_dbs($this->db->conn_id);
}
// --------------------------------------------------------------------
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 164c39a95..233fed678 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -53,6 +53,7 @@ Release Date: Not Released
- Improved PDO database support.
- Added DSN string support for CUBRID.
- Added persistent connections support for CUBRID.
+ - CUBRID driver's utility class now overrides list_databases() in order to use cubrid_list_dbs().
- Libraries
@@ -107,6 +108,7 @@ Bug fixes for 3.0
- Fixed a hosting edge case where an empty $_SERVER['HTTPS'] variable would evaluate to 'on'
- Fixed a bug (#154) - ``CI_Session::sess_update()`` caused the session to be destroyed on pages where multiple AJAX requests were executed at once.
- Fixed a possible bug in ``CI_Input::is_ajax_request()`` where some clients might not send the X-Requested-With HTTP header value exactly as 'XmlHttpRequest'.
+- Fixed a bug in CUBRID's affected_rows() where a connection resource was passed to cubrid_affected_rows() instead of a result.
Version 2.1.0
=============
--
cgit v1.2.3-24-g4f1b
From cf63120a60da9485ab1f94bc58b5d62e6b05a0fd Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 16 Feb 2012 11:36:28 +0200
Subject: A change in the class descriptions
---
system/database/drivers/cubrid/cubrid_driver.php | 2 +-
system/database/drivers/cubrid/cubrid_forge.php | 2 +-
system/database/drivers/cubrid/cubrid_result.php | 2 +-
system/database/drivers/cubrid/cubrid_utility.php | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index aa8e997ce..1dc7a454b 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -21,7 +21,7 @@
* @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
- * @since Version 2.0.2
+ * @since Version 2.1
* @filesource
*/
diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php
index 5f7985705..048a0597b 100644
--- a/system/database/drivers/cubrid/cubrid_forge.php
+++ b/system/database/drivers/cubrid/cubrid_forge.php
@@ -21,7 +21,7 @@
* @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
- * @since Version 3.0
+ * @since Version 2.1
* @filesource
*/
diff --git a/system/database/drivers/cubrid/cubrid_result.php b/system/database/drivers/cubrid/cubrid_result.php
index 3351b3430..453954754 100644
--- a/system/database/drivers/cubrid/cubrid_result.php
+++ b/system/database/drivers/cubrid/cubrid_result.php
@@ -21,7 +21,7 @@
* @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
- * @since Version 2.0.2
+ * @since Version 2.1
* @filesource
*/
diff --git a/system/database/drivers/cubrid/cubrid_utility.php b/system/database/drivers/cubrid/cubrid_utility.php
index ab9056ffb..9819abd08 100644
--- a/system/database/drivers/cubrid/cubrid_utility.php
+++ b/system/database/drivers/cubrid/cubrid_utility.php
@@ -21,7 +21,7 @@
* @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
- * @since Version 3.0
+ * @since Version 2.1
* @filesource
*/
--
cgit v1.2.3-24-g4f1b
From 7efad20597ef7e06f8cf837a9f40918d2d3f2727 Mon Sep 17 00:00:00 2001
From: Jamie Rumbelow
Date: Sun, 19 Feb 2012 12:37:00 +0000
Subject: Renaming Active Record to Query Builder across the system
---
application/config/database.php | 8 +-
system/core/Loader.php | 10 +-
system/database/DB.php | 18 +-
system/database/DB_active_rec.php | 2217 --------------------
system/database/DB_driver.php | 4 +-
system/database/DB_query_builder.php | 2217 ++++++++++++++++++++
system/database/drivers/cubrid/cubrid_driver.php | 4 +-
system/database/drivers/mssql/mssql_driver.php | 4 +-
system/database/drivers/mysql/mysql_driver.php | 4 +-
system/database/drivers/mysqli/mysqli_driver.php | 4 +-
system/database/drivers/oci8/oci8_driver.php | 4 +-
system/database/drivers/odbc/odbc_driver.php | 4 +-
system/database/drivers/pdo/pdo_driver.php | 4 +-
system/database/drivers/postgre/postgre_driver.php | 4 +-
system/database/drivers/sqlite/sqlite_driver.php | 4 +-
system/database/drivers/sqlsrv/sqlsrv_driver.php | 2 +-
user_guide_src/source/database/active_record.rst | 1008 ---------
user_guide_src/source/database/configuration.rst | 12 +-
user_guide_src/source/database/connecting.rst | 2 +-
user_guide_src/source/database/examples.rst | 8 +-
user_guide_src/source/database/index.rst | 4 +-
user_guide_src/source/database/queries.rst | 2 +-
user_guide_src/source/database/query_builder.rst | 1008 +++++++++
user_guide_src/source/general/models.rst | 2 +-
user_guide_src/source/helpers/directory_helper.rst | 2 +-
user_guide_src/source/overview/features.rst | 2 +-
.../source/tutorial/create_news_items.rst | 2 +-
user_guide_src/source/tutorial/index.rst | 2 +-
user_guide_src/source/tutorial/news_section.rst | 4 +-
29 files changed, 3285 insertions(+), 3285 deletions(-)
delete mode 100644 system/database/DB_active_rec.php
create mode 100644 system/database/DB_query_builder.php
delete mode 100644 user_guide_src/source/database/active_record.rst
create mode 100644 user_guide_src/source/database/query_builder.rst
diff --git a/application/config/database.php b/application/config/database.php
index bd68db1d8..b1cad9025 100644
--- a/application/config/database.php
+++ b/application/config/database.php
@@ -45,7 +45,7 @@
| ['dbdriver'] The database type. e.g.: mysql. Currently supported:
mysql, mysqli, pdo, postgre, odbc, mssql, sqlite, oci8
| ['dbprefix'] You can add an optional prefix, which will be added
-| to the table name when using the Active Record class
+| to the table name when using the Query Builder class
| ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
| ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
| ['cache_on'] TRUE/FALSE - Enables/disables query caching
@@ -68,12 +68,12 @@
| The $active_group variable lets you choose which connection group to
| make active. By default there is only one group (the 'default' group).
|
-| The $active_record variables lets you determine whether or not to load
-| the active record class
+| The $query_builder variables lets you determine whether or not to load
+| the query builder class
*/
$active_group = 'default';
-$active_record = TRUE;
+$query_builder = TRUE;
$db['default']['dsn'] = '';
$db['default']['hostname'] = 'localhost';
diff --git a/system/core/Loader.php b/system/core/Loader.php
index 12daaa928..750e8cdd6 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -315,16 +315,16 @@ class CI_Loader {
*
* @param string the DB credentials
* @param bool whether to return the DB object
- * @param bool whether to enable active record (this allows us to override the config setting)
+ * @param bool whether to enable query builder (this allows us to override the config setting)
* @return object
*/
- public function database($params = '', $return = FALSE, $active_record = NULL)
+ public function database($params = '', $return = FALSE, $query_builder = NULL)
{
// Grab the super object
$CI =& get_instance();
// Do we even need to load the database class?
- if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db))
+ if (class_exists('CI_DB') AND $return == FALSE AND $query_builder == NULL AND isset($CI->db) AND is_object($CI->db))
{
return FALSE;
}
@@ -333,7 +333,7 @@ class CI_Loader {
if ($return === TRUE)
{
- return DB($params, $active_record);
+ return DB($params, $query_builder);
}
// Initialize the db variable. Needed to prevent
@@ -341,7 +341,7 @@ class CI_Loader {
$CI->db = '';
// Load the DB class
- $CI->db =& DB($params, $active_record);
+ $CI->db =& DB($params, $query_builder);
}
// --------------------------------------------------------------------
diff --git a/system/database/DB.php b/system/database/DB.php
index d06ffb40e..9ce6103ca 100755
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -32,9 +32,9 @@
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
* @param string
- * @param bool Determines if active record should be used or not
+ * @param bool Determines if query builder should be used or not
*/
-function &DB($params = '', $active_record_override = NULL)
+function &DB($params = '', $query_builder_override = NULL)
{
// Load the DB config file if a DSN string wasn't passed
if (is_string($params) AND strpos($params, '://') === FALSE)
@@ -115,22 +115,22 @@ function &DB($params = '', $active_record_override = NULL)
show_error('You have not selected a database type to connect to.');
}
- // Load the DB classes. Note: Since the active record class is optional
+ // Load the DB classes. Note: Since the query builder class is optional
// we need to dynamically create a class that extends proper parent class
- // based on whether we're using the active record class or not.
- if ($active_record_override !== NULL)
+ // based on whether we're using the query builder class or not.
+ if ($query_builder_override !== NULL)
{
- $active_record = $active_record_override;
+ $query_builder = $query_builder_override;
}
require_once(BASEPATH.'database/DB_driver.php');
- if ( ! isset($active_record) OR $active_record == TRUE)
+ if ( ! isset($query_builder) OR $query_builder == TRUE)
{
- require_once(BASEPATH.'database/DB_active_rec.php');
+ require_once(BASEPATH.'database/DB_query_builder.php');
if ( ! class_exists('CI_DB'))
{
- class CI_DB extends CI_DB_active_record { }
+ class CI_DB extends CI_DB_query_builder { }
}
}
elseif ( ! class_exists('CI_DB'))
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
deleted file mode 100644
index 424735157..000000000
--- a/system/database/DB_active_rec.php
+++ /dev/null
@@ -1,2217 +0,0 @@
-ar_select[] = $val;
- $this->ar_no_escape[] = $escape;
-
- if ($this->ar_caching === TRUE)
- {
- $this->ar_cache_select[] = $val;
- $this->ar_cache_exists[] = 'select';
- $this->ar_cache_no_escape[] = $escape;
- }
- }
- }
-
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Select Max
- *
- * Generates a SELECT MAX(field) portion of a query
- *
- * @param string the field
- * @param string an alias
- * @return object
- */
- public function select_max($select = '', $alias = '')
- {
- return $this->_max_min_avg_sum($select, $alias, 'MAX');
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Select Min
- *
- * Generates a SELECT MIN(field) portion of a query
- *
- * @param string the field
- * @param string an alias
- * @return object
- */
- public function select_min($select = '', $alias = '')
- {
- return $this->_max_min_avg_sum($select, $alias, 'MIN');
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Select Average
- *
- * Generates a SELECT AVG(field) portion of a query
- *
- * @param string the field
- * @param string an alias
- * @return object
- */
- public function select_avg($select = '', $alias = '')
- {
- return $this->_max_min_avg_sum($select, $alias, 'AVG');
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Select Sum
- *
- * Generates a SELECT SUM(field) portion of a query
- *
- * @param string the field
- * @param string an alias
- * @return object
- */
- public function select_sum($select = '', $alias = '')
- {
- return $this->_max_min_avg_sum($select, $alias, 'SUM');
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Processing Function for the four functions above:
- *
- * select_max()
- * select_min()
- * select_avg()
- * select_sum()
- *
- * @param string the field
- * @param string an alias
- * @return object
- */
- protected function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX')
- {
- if ( ! is_string($select) OR $select == '')
- {
- $this->display_error('db_invalid_query');
- }
-
- $type = strtoupper($type);
-
- if ( ! in_array($type, array('MAX', 'MIN', 'AVG', 'SUM')))
- {
- show_error('Invalid function type: '.$type);
- }
-
- if ($alias == '')
- {
- $alias = $this->_create_alias_from_table(trim($select));
- }
-
- $sql = $this->_protect_identifiers($type.'('.trim($select).')').' AS '.$this->_protect_identifiers(trim($alias));
- $this->ar_select[] = $sql;
-
- if ($this->ar_caching === TRUE)
- {
- $this->ar_cache_select[] = $sql;
- $this->ar_cache_exists[] = 'select';
- }
-
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Determines the alias name based on the table
- *
- * @param string
- * @return string
- */
- protected function _create_alias_from_table($item)
- {
- if (strpos($item, '.') !== FALSE)
- {
- return end(explode('.', $item));
- }
-
- return $item;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * DISTINCT
- *
- * Sets a flag which tells the query string compiler to add DISTINCT
- *
- * @param bool
- * @return object
- */
- public function distinct($val = TRUE)
- {
- $this->ar_distinct = (is_bool($val)) ? $val : TRUE;
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * From
- *
- * Generates the FROM portion of the query
- *
- * @param mixed can be a string or array
- * @return object
- */
- public function from($from)
- {
- foreach ((array)$from as $val)
- {
- if (strpos($val, ',') !== FALSE)
- {
- foreach (explode(',', $val) as $v)
- {
- $v = trim($v);
- $this->_track_aliases($v);
- $v = $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
-
- if ($this->ar_caching === TRUE)
- {
- $this->ar_cache_from[] = $v;
- $this->ar_cache_exists[] = 'from';
- }
- }
- }
- else
- {
- $val = trim($val);
-
- // Extract any aliases that might exist. We use this information
- // in the _protect_identifiers to know whether to add a table prefix
- $this->_track_aliases($val);
- $this->ar_from[] = $val = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
-
- if ($this->ar_caching === TRUE)
- {
- $this->ar_cache_from[] = $val;
- $this->ar_cache_exists[] = 'from';
- }
- }
- }
-
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Join
- *
- * Generates the JOIN portion of the query
- *
- * @param string
- * @param string the join condition
- * @param string the type of join
- * @return object
- */
- public function join($table, $cond, $type = '')
- {
- if ($type != '')
- {
- $type = strtoupper(trim($type));
-
- if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER')))
- {
- $type = '';
- }
- else
- {
- $type .= ' ';
- }
- }
-
- // Extract any aliases that might exist. We use this information
- // in the _protect_identifiers to know whether to add a table prefix
- $this->_track_aliases($table);
-
- // Strip apart the condition and protect the identifiers
- if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $cond, $match))
- {
- $cond = $this->_protect_identifiers($match[1]).$match[2].$this->_protect_identifiers($match[3]);
- }
-
- // Assemble the JOIN statement
- $this->ar_join[] = $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
-
- if ($this->ar_caching === TRUE)
- {
- $this->ar_cache_join[] = $join;
- $this->ar_cache_exists[] = 'join';
- }
-
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Where
- *
- * Generates the WHERE portion of the query. Separates
- * multiple calls with AND
- *
- * @param mixed
- * @param mixed
- * @return object
- */
- public function where($key, $value = NULL, $escape = TRUE)
- {
- return $this->_where($key, $value, 'AND ', $escape);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * OR Where
- *
- * Generates the WHERE portion of the query. Separates
- * multiple calls with OR
- *
- * @param mixed
- * @param mixed
- * @return object
- */
- public function or_where($key, $value = NULL, $escape = TRUE)
- {
- return $this->_where($key, $value, 'OR ', $escape);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Where
- *
- * Called by where() or or_where()
- *
- * @param mixed
- * @param mixed
- * @param string
- * @return object
- */
- protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
- {
- $type = $this->_group_get_type($type);
-
- if ( ! is_array($key))
- {
- $key = array($key => $value);
- }
-
- // If the escape value was not set will will base it on the global setting
- if ( ! is_bool($escape))
- {
- $escape = $this->_protect_identifiers;
- }
-
- foreach ($key as $k => $v)
- {
- $prefix = (count($this->ar_where) === 0 AND count($this->ar_cache_where) === 0) ? '' : $type;
-
- if (is_null($v) && ! $this->_has_operator($k))
- {
- // value appears not to have been set, assign the test to IS NULL
- $k .= ' IS NULL';
- }
-
- if ( ! is_null($v))
- {
- if ($escape === TRUE)
- {
- $k = $this->_protect_identifiers($k, FALSE, $escape);
- $v = ' '.$this->escape($v);
- }
-
- if ( ! $this->_has_operator($k))
- {
- $k .= ' = ';
- }
- }
- else
- {
- $k = $this->_protect_identifiers($k, FALSE, $escape);
- }
-
- $this->ar_where[] = $prefix.$k.$v;
- if ($this->ar_caching === TRUE)
- {
- $this->ar_cache_where[] = $prefix.$k.$v;
- $this->ar_cache_exists[] = 'where';
- }
-
- }
-
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Where_in
- *
- * Generates a WHERE field IN ('item', 'item') SQL query joined with
- * AND if appropriate
- *
- * @param string The field to search
- * @param array The values searched on
- * @return object
- */
- public function where_in($key = NULL, $values = NULL)
- {
- return $this->_where_in($key, $values);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Where_in_or
- *
- * Generates a WHERE field IN ('item', 'item') SQL query joined with
- * OR if appropriate
- *
- * @param string The field to search
- * @param array The values searched on
- * @return object
- */
- public function or_where_in($key = NULL, $values = NULL)
- {
- return $this->_where_in($key, $values, FALSE, 'OR ');
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Where_not_in
- *
- * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
- * with AND if appropriate
- *
- * @param string The field to search
- * @param array The values searched on
- * @return object
- */
- public function where_not_in($key = NULL, $values = NULL)
- {
- return $this->_where_in($key, $values, TRUE);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Where_not_in_or
- *
- * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
- * with OR if appropriate
- *
- * @param string The field to search
- * @param array The values searched on
- * @return object
- */
- public function or_where_not_in($key = NULL, $values = NULL)
- {
- return $this->_where_in($key, $values, TRUE, 'OR ');
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Where_in
- *
- * Called by where_in, where_in_or, where_not_in, where_not_in_or
- *
- * @param string The field to search
- * @param array The values searched on
- * @param boolean If the statement would be IN or NOT IN
- * @param string
- * @return object
- */
- protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ')
- {
- if ($key === NULL OR $values === NULL)
- {
- return;
- }
-
- $type = $this->_group_get_type($type);
-
- if ( ! is_array($values))
- {
- $values = array($values);
- }
-
- $not = ($not) ? ' NOT' : '';
-
- foreach ($values as $value)
- {
- $this->ar_wherein[] = $this->escape($value);
- }
-
- $prefix = (count($this->ar_where) === 0) ? '' : $type;
- $this->ar_where[] = $where_in = $prefix.$this->_protect_identifiers($key).$not.' IN ('.implode(', ', $this->ar_wherein).') ';
-
- if ($this->ar_caching === TRUE)
- {
- $this->ar_cache_where[] = $where_in;
- $this->ar_cache_exists[] = 'where';
- }
-
- // reset the array for multiple calls
- $this->ar_wherein = array();
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Like
- *
- * Generates a %LIKE% portion of the query. Separates
- * multiple calls with AND
- *
- * @param mixed
- * @param mixed
- * @return object
- */
- public function like($field, $match = '', $side = 'both')
- {
- return $this->_like($field, $match, 'AND ', $side);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Not Like
- *
- * Generates a NOT LIKE portion of the query. Separates
- * multiple calls with AND
- *
- * @param mixed
- * @param mixed
- * @return object
- */
- public function not_like($field, $match = '', $side = 'both')
- {
- return $this->_like($field, $match, 'AND ', $side, 'NOT');
- }
-
- // --------------------------------------------------------------------
-
- /**
- * OR Like
- *
- * Generates a %LIKE% portion of the query. Separates
- * multiple calls with OR
- *
- * @param mixed
- * @param mixed
- * @return object
- */
- public function or_like($field, $match = '', $side = 'both')
- {
- return $this->_like($field, $match, 'OR ', $side);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * OR Not Like
- *
- * Generates a NOT LIKE portion of the query. Separates
- * multiple calls with OR
- *
- * @param mixed
- * @param mixed
- * @return object
- */
- public function or_not_like($field, $match = '', $side = 'both')
- {
- return $this->_like($field, $match, 'OR ', $side, 'NOT');
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Like
- *
- * Called by like() or orlike()
- *
- * @param mixed
- * @param mixed
- * @param string
- * @return object
- */
- protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
- {
- $type = $this->_group_get_type($type);
-
- if ( ! is_array($field))
- {
- $field = array($field => $match);
- }
-
- foreach ($field as $k => $v)
- {
- $k = $this->_protect_identifiers($k);
- $prefix = (count($this->ar_like) === 0) ? '' : $type;
- $v = $this->escape_like_str($v);
-
- if ($side === 'none')
- {
- $like_statement = $prefix." $k $not LIKE '{$v}'";
- }
- elseif ($side === 'before')
- {
- $like_statement = $prefix." $k $not LIKE '%{$v}'";
- }
- elseif ($side === 'after')
- {
- $like_statement = $prefix." $k $not LIKE '{$v}%'";
- }
- else
- {
- $like_statement = $prefix." $k $not LIKE '%{$v}%'";
- }
-
- // some platforms require an escape sequence definition for LIKE wildcards
- if ($this->_like_escape_str != '')
- {
- $like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_chr);
- }
-
- $this->ar_like[] = $like_statement;
- if ($this->ar_caching === TRUE)
- {
- $this->ar_cache_like[] = $like_statement;
- $this->ar_cache_exists[] = 'like';
- }
-
- }
-
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Starts a query group.
- *
- * @param string (Internal use only)
- * @param string (Internal use only)
- * @return object
- */
- public function group_start($not = '', $type = 'AND ')
- {
- $type = $this->_group_get_type($type);
- $this->ar_where_group_started = TRUE;
- $prefix = (count($this->ar_where) === 0 AND count($this->ar_cache_where) === 0) ? '' : $type;
- $this->ar_where[] = $value = $prefix.$not.str_repeat(' ', ++$this->ar_where_group_count).' (';
-
- if ($this->ar_caching)
- {
- $this->ar_cache_where[] = $value;
- }
-
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Starts a query group, but ORs the group
- *
- * @return object
- */
- public function or_group_start()
- {
- return $this->group_start('', 'OR ');
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Starts a query group, but NOTs the group
- *
- * @return object
- */
- public function not_group_start()
- {
- return $this->group_start('NOT ', 'AND ');
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Starts a query group, but OR NOTs the group
- *
- * @return object
- */
- public function or_not_group_start()
- {
- return $this->group_start('NOT ', 'OR ');
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Ends a query group
- *
- * @return object
- */
- public function group_end()
- {
- $this->ar_where_group_started = FALSE;
- $this->ar_where[] = $value = str_repeat(' ', $this->ar_where_group_count--) . ')';
-
- if ($this->ar_caching)
- {
- $this->ar_cache_where[] = $value;
- }
-
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Group_get_type
- *
- * Called by group_start(), _like(), _where() and _where_in()
- *
- * @param string
- * @return string
- */
- protected function _group_get_type($type)
- {
- if ($this->ar_where_group_started)
- {
- $type = '';
- $this->ar_where_group_started = FALSE;
- }
-
- return $type;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * GROUP BY
- *
- * @param string
- * @return object
- */
- public function group_by($by)
- {
- if (is_string($by))
- {
- $by = explode(',', $by);
- }
-
- foreach ($by as $val)
- {
- $val = trim($val);
-
- if ($val != '')
- {
- $this->ar_groupby[] = $val = $this->_protect_identifiers($val);
-
- if ($this->ar_caching === TRUE)
- {
- $this->ar_cache_groupby[] = $val;
- $this->ar_cache_exists[] = 'groupby';
- }
- }
- }
-
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Sets the HAVING value
- *
- * Separates multiple calls with AND
- *
- * @param string
- * @param string
- * @return object
- */
- public function having($key, $value = '', $escape = TRUE)
- {
- return $this->_having($key, $value, 'AND ', $escape);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Sets the OR HAVING value
- *
- * Separates multiple calls with OR
- *
- * @param string
- * @param string
- * @return object
- */
- public function or_having($key, $value = '', $escape = TRUE)
- {
- return $this->_having($key, $value, 'OR ', $escape);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Sets the HAVING values
- *
- * Called by having() or or_having()
- *
- * @param string
- * @param string
- * @return object
- */
- protected function _having($key, $value = '', $type = 'AND ', $escape = TRUE)
- {
- if ( ! is_array($key))
- {
- $key = array($key => $value);
- }
-
- foreach ($key as $k => $v)
- {
- $prefix = (count($this->ar_having) === 0) ? '' : $type;
-
- if ($escape === TRUE)
- {
- $k = $this->_protect_identifiers($k);
- }
-
- if ( ! $this->_has_operator($k))
- {
- $k .= ' = ';
- }
-
- if ($v != '')
- {
- $v = ' '.$this->escape($v);
- }
-
- $this->ar_having[] = $prefix.$k.$v;
- if ($this->ar_caching === TRUE)
- {
- $this->ar_cache_having[] = $prefix.$k.$v;
- $this->ar_cache_exists[] = 'having';
- }
- }
-
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Sets the ORDER BY value
- *
- * @param string
- * @param string direction: asc or desc
- * @param bool enable field name escaping
- * @return object
- */
- public function order_by($orderby, $direction = '', $escape = TRUE)
- {
- if (strtolower($direction) === 'random')
- {
- $orderby = ''; // Random results want or don't need a field name
- $direction = $this->_random_keyword;
- }
- elseif (trim($direction) != '')
- {
- $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC';
- }
-
-
- if ((strpos($orderby, ',') !== FALSE) && $escape === TRUE)
- {
- $temp = array();
- foreach (explode(',', $orderby) as $part)
- {
- $part = trim($part);
- if ( ! in_array($part, $this->ar_aliased_tables))
- {
- $part = $this->_protect_identifiers(trim($part));
- }
-
- $temp[] = $part;
- }
-
- $orderby = implode(', ', $temp);
- }
- elseif ($direction != $this->_random_keyword)
- {
- if ($escape === TRUE)
- {
- $orderby = $this->_protect_identifiers($orderby);
- }
- }
-
- $this->ar_orderby[] = $orderby_statement = $orderby.$direction;
-
- if ($this->ar_caching === TRUE)
- {
- $this->ar_cache_orderby[] = $orderby_statement;
- $this->ar_cache_exists[] = 'orderby';
- }
-
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Sets the LIMIT value
- *
- * @param integer the limit value
- * @param integer the offset value
- * @return object
- */
- public function limit($value, $offset = NULL)
- {
- $this->ar_limit = (int) $value;
-
- if ( ! is_null($offset))
- {
- $this->ar_offset = (int) $offset;
- }
-
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Sets the OFFSET value
- *
- * @param integer the offset value
- * @return object
- */
- public function offset($offset)
- {
- $this->ar_offset = (int) $offset;
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * The "set" function. Allows key/value pairs to be set for inserting or updating
- *
- * @param mixed
- * @param string
- * @param boolean
- * @return object
- */
- public function set($key, $value = '', $escape = TRUE)
- {
- $key = $this->_object_to_array($key);
-
- if ( ! is_array($key))
- {
- $key = array($key => $value);
- }
-
- foreach ($key as $k => $v)
- {
- if ($escape === FALSE)
- {
- $this->ar_set[$this->_protect_identifiers($k)] = $v;
- }
- else
- {
- $this->ar_set[$this->_protect_identifiers($k, FALSE, TRUE)] = $this->escape($v);
- }
- }
-
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Get SELECT query string
- *
- * Compiles a SELECT query string and returns the sql.
- *
- * @access public
- * @param string the table name to select from (optional)
- * @param boolean TRUE: resets AR values; FALSE: leave AR vaules alone
- * @return string
- */
- public function get_compiled_select($table = '', $reset = TRUE)
- {
- if ($table != '')
- {
- $this->_track_aliases($table);
- $this->from($table);
- }
-
- $select = $this->_compile_select();
-
- if ($reset === TRUE)
- {
- $this->_reset_select();
- }
-
- return $select;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Get
- *
- * Compiles the select statement based on the other functions called
- * and runs the query
- *
- * @param string the table
- * @param string the limit clause
- * @param string the offset clause
- * @return object
- */
- public function get($table = '', $limit = null, $offset = null)
- {
- if ($table != '')
- {
- $this->_track_aliases($table);
- $this->from($table);
- }
-
- if ( ! is_null($limit))
- {
- $this->limit($limit, $offset);
- }
-
- $result = $this->query($this->_compile_select());
- $this->_reset_select();
- return $result;
- }
-
- /**
- * "Count All Results" query
- *
- * Generates a platform-specific query string that counts all records
- * returned by an Active Record query.
- *
- * @param string
- * @return string
- */
- public function count_all_results($table = '')
- {
- if ($table != '')
- {
- $this->_track_aliases($table);
- $this->from($table);
- }
-
- $result = $this->query($this->_compile_select($this->_count_string.$this->_protect_identifiers('numrows')));
- $this->_reset_select();
-
- if ($result->num_rows() === 0)
- {
- return 0;
- }
-
- $row = $result->row();
- return (int) $row->numrows;
- }
- // --------------------------------------------------------------------
-
- /**
- * Get_Where
- *
- * Allows the where clause, limit and offset to be added directly
- *
- * @param string the where clause
- * @param string the limit clause
- * @param string the offset clause
- * @return object
- */
- public function get_where($table = '', $where = null, $limit = null, $offset = null)
- {
- if ($table != '')
- {
- $this->from($table);
- }
-
- if ( ! is_null($where))
- {
- $this->where($where);
- }
-
- if ( ! is_null($limit))
- {
- $this->limit($limit, $offset);
- }
-
- $result = $this->query($this->_compile_select());
- $this->_reset_select();
- return $result;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Insert_Batch
- *
- * Compiles batch insert strings and runs the queries
- *
- * @param string the table to retrieve the results from
- * @param array an associative array of insert values
- * @return object
- */
- public function insert_batch($table = '', $set = NULL)
- {
- if ( ! is_null($set))
- {
- $this->set_insert_batch($set);
- }
-
- if (count($this->ar_set) === 0)
- {
- if ($this->db_debug)
- {
- // No valid data array. Folds in cases where keys and values did not match up
- return $this->display_error('db_must_use_set');
- }
- return FALSE;
- }
-
- if ($table == '')
- {
- if ( ! isset($this->ar_from[0]))
- {
- return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
- }
-
- $table = $this->ar_from[0];
- }
-
- // Batch this baby
- for ($i = 0, $total = count($this->ar_set); $i < $total; $i += 100)
- {
- $this->query($this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100)));
- }
-
- $this->_reset_write();
- return TRUE;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts
- *
- * @param mixed
- * @param string
- * @param boolean
- * @return object
- */
- public function set_insert_batch($key, $value = '', $escape = TRUE)
- {
- $key = $this->_object_to_array_batch($key);
-
- if ( ! is_array($key))
- {
- $key = array($key => $value);
- }
-
- $keys = array_keys(current($key));
- sort($keys);
-
- foreach ($key as $row)
- {
- if (count(array_diff($keys, array_keys($row))) > 0 OR count(array_diff(array_keys($row), $keys)) > 0)
- {
- // batch function above returns an error on an empty array
- $this->ar_set[] = array();
- return;
- }
-
- ksort($row); // puts $row in the same order as our keys
-
- if ($escape === FALSE)
- {
- $this->ar_set[] = '('.implode(',', $row).')';
- }
- else
- {
- $clean = array();
- foreach ($row as $value)
- {
- $clean[] = $this->escape($value);
- }
-
- $this->ar_set[] = '('.implode(',', $clean).')';
- }
- }
-
- foreach ($keys as $k)
- {
- $this->ar_keys[] = $this->_protect_identifiers($k);
- }
-
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Get INSERT query string
- *
- * Compiles an insert query and returns the sql
- *
- * @access public
- * @param string the table to insert into
- * @param boolean TRUE: reset AR values; FALSE: leave AR values alone
- * @return string
- */
- public function get_compiled_insert($table = '', $reset = TRUE)
- {
- if ($this->_validate_insert($table) === FALSE)
- {
- return FALSE;
- }
-
- $sql = $this->_insert(
- $this->_protect_identifiers(
- $this->ar_from[0], TRUE, NULL, FALSE
- ),
- array_keys($this->ar_set),
- array_values($this->ar_set)
- );
-
- if ($reset === TRUE)
- {
- $this->_reset_write();
- }
-
- return $sql;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Insert
- *
- * Compiles an insert string and runs the query
- *
- * @access public
- * @param string the table to insert data into
- * @param array an associative array of insert values
- * @return object
- */
- public function insert($table = '', $set = NULL)
- {
- if ( ! is_null($set))
- {
- $this->set($set);
- }
-
- if ($this->_validate_insert($table) === FALSE)
- {
- return FALSE;
- }
-
- $sql = $this->_insert(
- $this->_protect_identifiers(
- $this->ar_from[0], TRUE, NULL, FALSE
- ),
- array_keys($this->ar_set),
- array_values($this->ar_set)
- );
-
- $this->_reset_write();
- return $this->query($sql);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Validate Insert
- *
- * This method is used by both insert() and get_compiled_insert() to
- * validate that the there data is actually being set and that table
- * has been chosen to be inserted into.
- *
- * @access public
- * @param string the table to insert data into
- * @return string
- */
- protected function _validate_insert($table = '')
- {
- if (count($this->ar_set) === 0)
- {
- return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
- }
-
- if ($table == '')
- {
- if ( ! isset($this->ar_from[0]))
- {
- return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
- }
- }
- else
- {
- $this->ar_from[0] = $table;
- }
-
- return TRUE;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Replace
- *
- * Compiles an replace into string and runs the query
- *
- * @param string the table to replace data into
- * @param array an associative array of insert values
- * @return object
- */
- public function replace($table = '', $set = NULL)
- {
- if ( ! is_null($set))
- {
- $this->set($set);
- }
-
- if (count($this->ar_set) === 0)
- {
- return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
- }
-
- if ($table == '')
- {
- if ( ! isset($this->ar_from[0]))
- {
- return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
- }
-
- $table = $this->ar_from[0];
- }
-
- $sql = $this->_replace($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));
- $this->_reset_write();
- return $this->query($sql);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Get UPDATE query string
- *
- * Compiles an update query and returns the sql
- *
- * @access public
- * @param string the table to update
- * @param boolean TRUE: reset AR values; FALSE: leave AR values alone
- * @return string
- */
- public function get_compiled_update($table = '', $reset = TRUE)
- {
- // Combine any cached components with the current statements
- $this->_merge_cache();
-
- if ($this->_validate_update($table) === FALSE)
- {
- return FALSE;
- }
-
- $sql = $this->_update($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit);
-
- if ($reset === TRUE)
- {
- $this->_reset_write();
- }
-
- return $sql;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Update
- *
- * Compiles an update string and runs the query
- *
- * @param string the table to retrieve the results from
- * @param array an associative array of update values
- * @param mixed the where clause
- * @return object
- */
- public function update($table = '', $set = NULL, $where = NULL, $limit = NULL)
- {
- // Combine any cached components with the current statements
- $this->_merge_cache();
-
- if ( ! is_null($set))
- {
- $this->set($set);
- }
-
- if ($this->_validate_update($table) === FALSE)
- {
- return FALSE;
- }
-
- if ($where != NULL)
- {
- $this->where($where);
- }
-
- if ($limit != NULL)
- {
- $this->limit($limit);
- }
-
- $sql = $this->_update($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit, $this->ar_like);
- $this->_reset_write();
- return $this->query($sql);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Validate Update
- *
- * This method is used by both update() and get_compiled_update() to
- * validate that data is actually being set and that a table has been
- * chosen to be update.
- *
- * @access public
- * @param string the table to update data on
- * @return bool
- */
- protected function _validate_update($table = '')
- {
- if (count($this->ar_set) == 0)
- {
- return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
- }
-
- if ($table == '')
- {
- if ( ! isset($this->ar_from[0]))
- {
- return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
- }
- }
- else
- {
- $this->ar_from[0] = $table;
- }
-
- return TRUE;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Update_Batch
- *
- * Compiles an update string and runs the query
- *
- * @param string the table to retrieve the results from
- * @param array an associative array of update values
- * @param string the where key
- * @return bool
- */
- public function update_batch($table = '', $set = NULL, $index = NULL)
- {
- // Combine any cached components with the current statements
- $this->_merge_cache();
-
- if (is_null($index))
- {
- return ($this->db_debug) ? $this->display_error('db_must_use_index') : FALSE;
- }
-
- if ( ! is_null($set))
- {
- $this->set_update_batch($set, $index);
- }
-
- if (count($this->ar_set) === 0)
- {
- return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
- }
-
- if ($table == '')
- {
- if ( ! isset($this->ar_from[0]))
- {
- return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
- }
-
- $table = $this->ar_from[0];
- }
-
- // Batch this baby
- for ($i = 0, $total = count($this->ar_set); $i < $total; $i += 100)
- {
- $this->query($this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where));
- }
-
- $this->_reset_write();
- return TRUE;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * The "set_update_batch" function. Allows key/value pairs to be set for batch updating
- *
- * @param array
- * @param string
- * @param boolean
- * @return object
- */
- public function set_update_batch($key, $index = '', $escape = TRUE)
- {
- $key = $this->_object_to_array_batch($key);
-
- if ( ! is_array($key))
- {
- // @todo error
- }
-
- foreach ($key as $k => $v)
- {
- $index_set = FALSE;
- $clean = array();
- foreach ($v as $k2 => $v2)
- {
- if ($k2 == $index)
- {
- $index_set = TRUE;
- }
- else
- {
- $not[] = $k.'-'.$v;
- }
-
- $clean[$this->_protect_identifiers($k2)] = ($escape === FALSE) ? $v2 : $this->escape($v2);
- }
-
- if ($index_set == FALSE)
- {
- return $this->display_error('db_batch_missing_index');
- }
-
- $this->ar_set[] = $clean;
- }
-
- return $this;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Empty Table
- *
- * Compiles a delete string and runs "DELETE FROM table"
- *
- * @param string the table to empty
- * @return object
- */
- public function empty_table($table = '')
- {
- if ($table == '')
- {
- if ( ! isset($this->ar_from[0]))
- {
- return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
- }
-
- $table = $this->ar_from[0];
- }
- else
- {
- $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
- }
-
- $sql = $this->_delete($table);
- $this->_reset_write();
- return $this->query($sql);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Truncate
- *
- * Compiles a truncate string and runs the query
- * If the database does not support the truncate() command
- * This function maps to "DELETE FROM table"
- *
- * @param string the table to truncate
- * @return object
- */
- public function truncate($table = '')
- {
- if ($table == '')
- {
- if ( ! isset($this->ar_from[0]))
- {
- return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
- }
-
- $table = $this->ar_from[0];
- }
- else
- {
- $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
- }
-
- $sql = $this->_truncate($table);
- $this->_reset_write();
- return $this->query($sql);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Get DELETE query string
- *
- * Compiles a delete query string and returns the sql
- *
- * @access public
- * @param string the table to delete from
- * @param boolean TRUE: reset AR values; FALSE: leave AR values alone
- * @return string
- */
- public function get_compiled_delete($table = '', $reset = TRUE)
- {
- $this->return_delete_sql = TRUE;
- $sql = $this->delete($table, '', NULL, $reset);
- $this->return_delete_sql = FALSE;
- return $sql;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Delete
- *
- * Compiles a delete string and runs the query
- *
- * @param mixed the table(s) to delete from. String or array
- * @param mixed the where clause
- * @param mixed the limit clause
- * @param boolean
- * @return object
- */
- public function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE)
- {
- // Combine any cached components with the current statements
- $this->_merge_cache();
-
- if ($table == '')
- {
- if ( ! isset($this->ar_from[0]))
- {
- return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
- }
-
- $table = $this->ar_from[0];
- }
- elseif (is_array($table))
- {
- foreach ($table as $single_table)
- {
- $this->delete($single_table, $where, $limit, FALSE);
- }
-
- $this->_reset_write();
- return;
- }
- else
- {
- $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
- }
-
- if ($where != '')
- {
- $this->where($where);
- }
-
- if ($limit != NULL)
- {
- $this->limit($limit);
- }
-
- if (count($this->ar_where) === 0 && count($this->ar_wherein) === 0 && count($this->ar_like) === 0)
- {
- return ($this->db_debug) ? $this->display_error('db_del_must_use_where') : FALSE;
- }
-
- $sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit);
- if ($reset_data)
- {
- $this->_reset_write();
- }
-
- return ($this->return_delete_sql === TRUE) ? $sql : $this->query($sql);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * DB Prefix
- *
- * Prepends a database prefix if one exists in configuration
- *
- * @param string the table
- * @return string
- */
- public function dbprefix($table = '')
- {
- if ($table == '')
- {
- $this->display_error('db_table_name_required');
- }
-
- return $this->dbprefix.$table;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Set DB Prefix
- *
- * Set's the DB Prefix to something new without needing to reconnect
- *
- * @param string the prefix
- * @return string
- */
- public function set_dbprefix($prefix = '')
- {
- return $this->dbprefix = $prefix;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Track Aliases
- *
- * Used to track SQL statements written with aliased tables.
- *
- * @param string The table to inspect
- * @return string
- */
- protected function _track_aliases($table)
- {
- if (is_array($table))
- {
- foreach ($table as $t)
- {
- $this->_track_aliases($t);
- }
- return;
- }
-
- // Does the string contain a comma? If so, we need to separate
- // the string into discreet statements
- if (strpos($table, ',') !== FALSE)
- {
- return $this->_track_aliases(explode(',', $table));
- }
-
- // if a table alias is used we can recognize it by a space
- if (strpos($table, ' ') !== FALSE)
- {
- // if the alias is written with the AS keyword, remove it
- $table = preg_replace('/ AS /i', ' ', $table);
-
- // Grab the alias
- $table = trim(strrchr($table, ' '));
-
- // Store the alias, if it doesn't already exist
- if ( ! in_array($table, $this->ar_aliased_tables))
- {
- $this->ar_aliased_tables[] = $table;
- }
- }
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Compile the SELECT statement
- *
- * Generates a query string based on which functions were used.
- * Should not be called directly. The get() function calls it.
- *
- * @return string
- */
- protected function _compile_select($select_override = FALSE)
- {
- // Combine any cached components with the current statements
- $this->_merge_cache();
-
- // Write the "select" portion of the query
- if ($select_override !== FALSE)
- {
- $sql = $select_override;
- }
- else
- {
- $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';
-
- if (count($this->ar_select) === 0)
- {
- $sql .= '*';
- }
- else
- {
- // Cycle through the "select" portion of the query and prep each column name.
- // The reason we protect identifiers here rather then in the select() function
- // is because until the user calls the from() function we don't know if there are aliases
- foreach ($this->ar_select as $key => $val)
- {
- $no_escape = isset($this->ar_no_escape[$key]) ? $this->ar_no_escape[$key] : NULL;
- $this->ar_select[$key] = $this->_protect_identifiers($val, FALSE, $no_escape);
- }
-
- $sql .= implode(', ', $this->ar_select);
- }
- }
-
- // Write the "FROM" portion of the query
- if (count($this->ar_from) > 0)
- {
- $sql .= "\nFROM ".$this->_from_tables($this->ar_from);
- }
-
- // Write the "JOIN" portion of the query
- if (count($this->ar_join) > 0)
- {
- $sql .= "\n".implode("\n", $this->ar_join);
- }
-
- // Write the "WHERE" portion of the query
- if (count($this->ar_where) > 0 OR count($this->ar_like) > 0)
- {
- $sql .= "\nWHERE ";
- }
-
- $sql .= implode("\n", $this->ar_where);
-
- // Write the "LIKE" portion of the query
- if (count($this->ar_like) > 0)
- {
- if (count($this->ar_where) > 0)
- {
- $sql .= "\nAND ";
- }
-
- $sql .= implode("\n", $this->ar_like);
- }
-
- // Write the "GROUP BY" portion of the query
- if (count($this->ar_groupby) > 0)
- {
- $sql .= "\nGROUP BY ".implode(', ', $this->ar_groupby);
- }
-
- // Write the "HAVING" portion of the query
- if (count($this->ar_having) > 0)
- {
- $sql .= "\nHAVING ".implode("\n", $this->ar_having);
- }
-
- // Write the "ORDER BY" portion of the query
- if (count($this->ar_orderby) > 0)
- {
- $sql .= "\nORDER BY ".implode(', ', $this->ar_orderby);
- if ($this->ar_order !== FALSE)
- {
- $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC';
- }
- }
-
- // Write the "LIMIT" portion of the query
- if (is_numeric($this->ar_limit))
- {
- return $this->_limit($sql."\n", $this->ar_limit, $this->ar_offset);
- }
-
- return $sql;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Object to Array
- *
- * Takes an object as input and converts the class variables to array key/vals
- *
- * @param object
- * @return array
- */
- public function _object_to_array($object)
- {
- if ( ! is_object($object))
- {
- return $object;
- }
-
- $array = array();
- foreach (get_object_vars($object) as $key => $val)
- {
- // There are some built in keys we need to ignore for this conversion
- if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name')
- {
- $array[$key] = $val;
- }
- }
-
- return $array;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Object to Array
- *
- * Takes an object as input and converts the class variables to array key/vals
- *
- * @param object
- * @return array
- */
- public function _object_to_array_batch($object)
- {
- if ( ! is_object($object))
- {
- return $object;
- }
-
- $array = array();
- $out = get_object_vars($object);
- $fields = array_keys($out);
-
- foreach ($fields as $val)
- {
- // There are some built in keys we need to ignore for this conversion
- if ($val !== '_parent_name')
- {
- $i = 0;
- foreach ($out[$val] as $data)
- {
- $array[$i++][$val] = $data;
- }
- }
- }
-
- return $array;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Start Cache
- *
- * Starts AR caching
- *
- * @return void
- */
- public function start_cache()
- {
- $this->ar_caching = TRUE;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Stop Cache
- *
- * Stops AR caching
- *
- * @return void
- */
- public function stop_cache()
- {
- $this->ar_caching = FALSE;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Flush Cache
- *
- * Empties the AR cache
- *
- * @access public
- * @return void
- */
- public function flush_cache()
- {
- $this->_reset_run(array(
- 'ar_cache_select' => array(),
- 'ar_cache_from' => array(),
- 'ar_cache_join' => array(),
- 'ar_cache_where' => array(),
- 'ar_cache_like' => array(),
- 'ar_cache_groupby' => array(),
- 'ar_cache_having' => array(),
- 'ar_cache_orderby' => array(),
- 'ar_cache_set' => array(),
- 'ar_cache_exists' => array(),
- 'ar_cache_no_escape' => array()
- ));
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Merge Cache
- *
- * When called, this function merges any cached AR arrays with
- * locally called ones.
- *
- * @return void
- */
- protected function _merge_cache()
- {
- if (count($this->ar_cache_exists) === 0)
- {
- return;
- }
-
- foreach ($this->ar_cache_exists as $val)
- {
- $ar_variable = 'ar_'.$val;
- $ar_cache_var = 'ar_cache_'.$val;
-
- if (count($this->$ar_cache_var) === 0)
- {
- continue;
- }
-
- $this->$ar_variable = array_unique(array_merge($this->$ar_cache_var, $this->$ar_variable));
- }
-
- // If we are "protecting identifiers" we need to examine the "from"
- // portion of the query to determine if there are any aliases
- if ($this->_protect_identifiers === TRUE AND count($this->ar_cache_from) > 0)
- {
- $this->_track_aliases($this->ar_from);
- }
-
- $this->ar_no_escape = $this->ar_cache_no_escape;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Reset Active Record values.
- *
- * Publicly-visible method to reset the AR values.
- *
- * @return void
- */
- public function reset_query()
- {
- $this->_reset_select();
- $this->_reset_write();
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Resets the active record values. Called by the get() function
- *
- * @param array An array of fields to reset
- * @return void
- */
- protected function _reset_run($ar_reset_items)
- {
- foreach ($ar_reset_items as $item => $default_value)
- {
- if ( ! in_array($item, $this->ar_store_array))
- {
- $this->$item = $default_value;
- }
- }
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Resets the active record values. Called by the get() function
- *
- * @return void
- */
- protected function _reset_select()
- {
- $this->_reset_run(array(
- 'ar_select' => array(),
- 'ar_from' => array(),
- 'ar_join' => array(),
- 'ar_where' => array(),
- 'ar_like' => array(),
- 'ar_groupby' => array(),
- 'ar_having' => array(),
- 'ar_orderby' => array(),
- 'ar_wherein' => array(),
- 'ar_aliased_tables' => array(),
- 'ar_no_escape' => array(),
- 'ar_distinct' => FALSE,
- 'ar_limit' => FALSE,
- 'ar_offset' => FALSE,
- 'ar_order' => FALSE
- )
- );
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Resets the active record "write" values.
- *
- * Called by the insert() update() insert_batch() update_batch() and delete() functions
- *
- * @return void
- */
- protected function _reset_write()
- {
- $this->_reset_run(array(
- 'ar_set' => array(),
- 'ar_from' => array(),
- 'ar_where' => array(),
- 'ar_like' => array(),
- 'ar_orderby' => array(),
- 'ar_keys' => array(),
- 'ar_limit' => FALSE,
- 'ar_order' => FALSE
- )
- );
- }
-
-}
-
-/* End of file DB_active_rec.php */
-/* Location: ./system/database/DB_active_rec.php */
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index b829bbe46..339226cbb 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -1270,7 +1270,7 @@ class CI_DB_driver {
/**
* Protect Identifiers
*
- * This function is used extensively by the Active Record class, and by
+ * This function is used extensively by the Query Builder class, and by
* a couple functions in this class.
* It takes a column or table name (optionally with an alias) and inserts
* the table prefix onto it. Some logic is necessary in order to deal with
@@ -1344,7 +1344,7 @@ class CI_DB_driver {
// Does the first segment of the exploded item match
// one of the aliases previously identified? If so,
// we have nothing more to do other than escape the item
- if (in_array($parts[0], $this->ar_aliased_tables))
+ if (in_array($parts[0], $this->qb_aliased_tables))
{
if ($protect_identifiers === TRUE)
{
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
new file mode 100644
index 000000000..b6ad0f3d8
--- /dev/null
+++ b/system/database/DB_query_builder.php
@@ -0,0 +1,2217 @@
+qb_select[] = $val;
+ $this->qb_no_escape[] = $escape;
+
+ if ($this->qb_caching === TRUE)
+ {
+ $this->qb_cache_select[] = $val;
+ $this->qb_cache_exists[] = 'select';
+ $this->qb_cache_no_escape[] = $escape;
+ }
+ }
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Select Max
+ *
+ * Generates a SELECT MAX(field) portion of a query
+ *
+ * @param string the field
+ * @param string an alias
+ * @return object
+ */
+ public function select_max($select = '', $alias = '')
+ {
+ return $this->_max_min_avg_sum($select, $alias, 'MAX');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Select Min
+ *
+ * Generates a SELECT MIN(field) portion of a query
+ *
+ * @param string the field
+ * @param string an alias
+ * @return object
+ */
+ public function select_min($select = '', $alias = '')
+ {
+ return $this->_max_min_avg_sum($select, $alias, 'MIN');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Select Average
+ *
+ * Generates a SELECT AVG(field) portion of a query
+ *
+ * @param string the field
+ * @param string an alias
+ * @return object
+ */
+ public function select_avg($select = '', $alias = '')
+ {
+ return $this->_max_min_avg_sum($select, $alias, 'AVG');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Select Sum
+ *
+ * Generates a SELECT SUM(field) portion of a query
+ *
+ * @param string the field
+ * @param string an alias
+ * @return object
+ */
+ public function select_sum($select = '', $alias = '')
+ {
+ return $this->_max_min_avg_sum($select, $alias, 'SUM');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Processing Function for the four functions above:
+ *
+ * select_max()
+ * select_min()
+ * select_avg()
+ * select_sum()
+ *
+ * @param string the field
+ * @param string an alias
+ * @return object
+ */
+ protected function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX')
+ {
+ if ( ! is_string($select) OR $select == '')
+ {
+ $this->display_error('db_invalid_query');
+ }
+
+ $type = strtoupper($type);
+
+ if ( ! in_array($type, array('MAX', 'MIN', 'AVG', 'SUM')))
+ {
+ show_error('Invalid function type: '.$type);
+ }
+
+ if ($alias == '')
+ {
+ $alias = $this->_create_alias_from_table(trim($select));
+ }
+
+ $sql = $this->_protect_identifiers($type.'('.trim($select).')').' AS '.$this->_protect_identifiers(trim($alias));
+ $this->qb_select[] = $sql;
+
+ if ($this->qb_caching === TRUE)
+ {
+ $this->qb_cache_select[] = $sql;
+ $this->qb_cache_exists[] = 'select';
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Determines the alias name based on the table
+ *
+ * @param string
+ * @return string
+ */
+ protected function _create_alias_from_table($item)
+ {
+ if (strpos($item, '.') !== FALSE)
+ {
+ return end(explode('.', $item));
+ }
+
+ return $item;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * DISTINCT
+ *
+ * Sets a flag which tells the query string compiler to add DISTINCT
+ *
+ * @param bool
+ * @return object
+ */
+ public function distinct($val = TRUE)
+ {
+ $this->qb_distinct = (is_bool($val)) ? $val : TRUE;
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * From
+ *
+ * Generates the FROM portion of the query
+ *
+ * @param mixed can be a string or array
+ * @return object
+ */
+ public function from($from)
+ {
+ foreach ((array)$from as $val)
+ {
+ if (strpos($val, ',') !== FALSE)
+ {
+ foreach (explode(',', $val) as $v)
+ {
+ $v = trim($v);
+ $this->_track_aliases($v);
+ $v = $this->qb_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
+
+ if ($this->qb_caching === TRUE)
+ {
+ $this->qb_cache_from[] = $v;
+ $this->qb_cache_exists[] = 'from';
+ }
+ }
+ }
+ else
+ {
+ $val = trim($val);
+
+ // Extract any aliases that might exist. We use this information
+ // in the _protect_identifiers to know whether to add a table prefix
+ $this->_track_aliases($val);
+ $this->qb_from[] = $val = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
+
+ if ($this->qb_caching === TRUE)
+ {
+ $this->qb_cache_from[] = $val;
+ $this->qb_cache_exists[] = 'from';
+ }
+ }
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Join
+ *
+ * Generates the JOIN portion of the query
+ *
+ * @param string
+ * @param string the join condition
+ * @param string the type of join
+ * @return object
+ */
+ public function join($table, $cond, $type = '')
+ {
+ if ($type != '')
+ {
+ $type = strtoupper(trim($type));
+
+ if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER')))
+ {
+ $type = '';
+ }
+ else
+ {
+ $type .= ' ';
+ }
+ }
+
+ // Extract any aliases that might exist. We use this information
+ // in the _protect_identifiers to know whether to add a table prefix
+ $this->_track_aliases($table);
+
+ // Strip apart the condition and protect the identifiers
+ if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $cond, $match))
+ {
+ $cond = $this->_protect_identifiers($match[1]).$match[2].$this->_protect_identifiers($match[3]);
+ }
+
+ // Assemble the JOIN statement
+ $this->qb_join[] = $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
+
+ if ($this->qb_caching === TRUE)
+ {
+ $this->qb_cache_join[] = $join;
+ $this->qb_cache_exists[] = 'join';
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Where
+ *
+ * Generates the WHERE portion of the query. Separates
+ * multiple calls with AND
+ *
+ * @param mixed
+ * @param mixed
+ * @return object
+ */
+ public function where($key, $value = NULL, $escape = TRUE)
+ {
+ return $this->_where($key, $value, 'AND ', $escape);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * OR Where
+ *
+ * Generates the WHERE portion of the query. Separates
+ * multiple calls with OR
+ *
+ * @param mixed
+ * @param mixed
+ * @return object
+ */
+ public function or_where($key, $value = NULL, $escape = TRUE)
+ {
+ return $this->_where($key, $value, 'OR ', $escape);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Where
+ *
+ * Called by where() or or_where()
+ *
+ * @param mixed
+ * @param mixed
+ * @param string
+ * @return object
+ */
+ protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
+ {
+ $type = $this->_group_get_type($type);
+
+ if ( ! is_array($key))
+ {
+ $key = array($key => $value);
+ }
+
+ // If the escape value was not set will will base it on the global setting
+ if ( ! is_bool($escape))
+ {
+ $escape = $this->_protect_identifiers;
+ }
+
+ foreach ($key as $k => $v)
+ {
+ $prefix = (count($this->qb_where) === 0 AND count($this->qb_cache_where) === 0) ? '' : $type;
+
+ if (is_null($v) && ! $this->_has_operator($k))
+ {
+ // value appears not to have been set, assign the test to IS NULL
+ $k .= ' IS NULL';
+ }
+
+ if ( ! is_null($v))
+ {
+ if ($escape === TRUE)
+ {
+ $k = $this->_protect_identifiers($k, FALSE, $escape);
+ $v = ' '.$this->escape($v);
+ }
+
+ if ( ! $this->_has_operator($k))
+ {
+ $k .= ' = ';
+ }
+ }
+ else
+ {
+ $k = $this->_protect_identifiers($k, FALSE, $escape);
+ }
+
+ $this->qb_where[] = $prefix.$k.$v;
+ if ($this->qb_caching === TRUE)
+ {
+ $this->qb_cache_where[] = $prefix.$k.$v;
+ $this->qb_cache_exists[] = 'where';
+ }
+
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Where_in
+ *
+ * Generates a WHERE field IN ('item', 'item') SQL query joined with
+ * AND if appropriate
+ *
+ * @param string The field to search
+ * @param array The values searched on
+ * @return object
+ */
+ public function where_in($key = NULL, $values = NULL)
+ {
+ return $this->_where_in($key, $values);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Where_in_or
+ *
+ * Generates a WHERE field IN ('item', 'item') SQL query joined with
+ * OR if appropriate
+ *
+ * @param string The field to search
+ * @param array The values searched on
+ * @return object
+ */
+ public function or_where_in($key = NULL, $values = NULL)
+ {
+ return $this->_where_in($key, $values, FALSE, 'OR ');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Where_not_in
+ *
+ * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
+ * with AND if appropriate
+ *
+ * @param string The field to search
+ * @param array The values searched on
+ * @return object
+ */
+ public function where_not_in($key = NULL, $values = NULL)
+ {
+ return $this->_where_in($key, $values, TRUE);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Where_not_in_or
+ *
+ * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
+ * with OR if appropriate
+ *
+ * @param string The field to search
+ * @param array The values searched on
+ * @return object
+ */
+ public function or_where_not_in($key = NULL, $values = NULL)
+ {
+ return $this->_where_in($key, $values, TRUE, 'OR ');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Where_in
+ *
+ * Called by where_in, where_in_or, where_not_in, where_not_in_or
+ *
+ * @param string The field to search
+ * @param array The values searched on
+ * @param boolean If the statement would be IN or NOT IN
+ * @param string
+ * @return object
+ */
+ protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ')
+ {
+ if ($key === NULL OR $values === NULL)
+ {
+ return;
+ }
+
+ $type = $this->_group_get_type($type);
+
+ if ( ! is_array($values))
+ {
+ $values = array($values);
+ }
+
+ $not = ($not) ? ' NOT' : '';
+
+ foreach ($values as $value)
+ {
+ $this->qb_wherein[] = $this->escape($value);
+ }
+
+ $prefix = (count($this->qb_where) === 0) ? '' : $type;
+ $this->qb_where[] = $where_in = $prefix.$this->_protect_identifiers($key).$not.' IN ('.implode(', ', $this->qb_wherein).') ';
+
+ if ($this->qb_caching === TRUE)
+ {
+ $this->qb_cache_where[] = $where_in;
+ $this->qb_cache_exists[] = 'where';
+ }
+
+ // reset the array for multiple calls
+ $this->qb_wherein = array();
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Like
+ *
+ * Generates a %LIKE% portion of the query. Separates
+ * multiple calls with AND
+ *
+ * @param mixed
+ * @param mixed
+ * @return object
+ */
+ public function like($field, $match = '', $side = 'both')
+ {
+ return $this->_like($field, $match, 'AND ', $side);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Not Like
+ *
+ * Generates a NOT LIKE portion of the query. Separates
+ * multiple calls with AND
+ *
+ * @param mixed
+ * @param mixed
+ * @return object
+ */
+ public function not_like($field, $match = '', $side = 'both')
+ {
+ return $this->_like($field, $match, 'AND ', $side, 'NOT');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * OR Like
+ *
+ * Generates a %LIKE% portion of the query. Separates
+ * multiple calls with OR
+ *
+ * @param mixed
+ * @param mixed
+ * @return object
+ */
+ public function or_like($field, $match = '', $side = 'both')
+ {
+ return $this->_like($field, $match, 'OR ', $side);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * OR Not Like
+ *
+ * Generates a NOT LIKE portion of the query. Separates
+ * multiple calls with OR
+ *
+ * @param mixed
+ * @param mixed
+ * @return object
+ */
+ public function or_not_like($field, $match = '', $side = 'both')
+ {
+ return $this->_like($field, $match, 'OR ', $side, 'NOT');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Like
+ *
+ * Called by like() or orlike()
+ *
+ * @param mixed
+ * @param mixed
+ * @param string
+ * @return object
+ */
+ protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
+ {
+ $type = $this->_group_get_type($type);
+
+ if ( ! is_array($field))
+ {
+ $field = array($field => $match);
+ }
+
+ foreach ($field as $k => $v)
+ {
+ $k = $this->_protect_identifiers($k);
+ $prefix = (count($this->qb_like) === 0) ? '' : $type;
+ $v = $this->escape_like_str($v);
+
+ if ($side === 'none')
+ {
+ $like_statement = $prefix." $k $not LIKE '{$v}'";
+ }
+ elseif ($side === 'before')
+ {
+ $like_statement = $prefix." $k $not LIKE '%{$v}'";
+ }
+ elseif ($side === 'after')
+ {
+ $like_statement = $prefix." $k $not LIKE '{$v}%'";
+ }
+ else
+ {
+ $like_statement = $prefix." $k $not LIKE '%{$v}%'";
+ }
+
+ // some platforms require an escape sequence definition for LIKE wildcards
+ if ($this->_like_escape_str != '')
+ {
+ $like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_chr);
+ }
+
+ $this->qb_like[] = $like_statement;
+ if ($this->qb_caching === TRUE)
+ {
+ $this->qb_cache_like[] = $like_statement;
+ $this->qb_cache_exists[] = 'like';
+ }
+
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Starts a query group.
+ *
+ * @param string (Internal use only)
+ * @param string (Internal use only)
+ * @return object
+ */
+ public function group_start($not = '', $type = 'AND ')
+ {
+ $type = $this->_group_get_type($type);
+ $this->qb_where_group_started = TRUE;
+ $prefix = (count($this->qb_where) === 0 AND count($this->qb_cache_where) === 0) ? '' : $type;
+ $this->qb_where[] = $value = $prefix.$not.str_repeat(' ', ++$this->qb_where_group_count).' (';
+
+ if ($this->qb_caching)
+ {
+ $this->qb_cache_where[] = $value;
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Starts a query group, but ORs the group
+ *
+ * @return object
+ */
+ public function or_group_start()
+ {
+ return $this->group_start('', 'OR ');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Starts a query group, but NOTs the group
+ *
+ * @return object
+ */
+ public function not_group_start()
+ {
+ return $this->group_start('NOT ', 'AND ');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Starts a query group, but OR NOTs the group
+ *
+ * @return object
+ */
+ public function or_not_group_start()
+ {
+ return $this->group_start('NOT ', 'OR ');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Ends a query group
+ *
+ * @return object
+ */
+ public function group_end()
+ {
+ $this->qb_where_group_started = FALSE;
+ $this->qb_where[] = $value = str_repeat(' ', $this->qb_where_group_count--) . ')';
+
+ if ($this->qb_caching)
+ {
+ $this->qb_cache_where[] = $value;
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Group_get_type
+ *
+ * Called by group_start(), _like(), _where() and _where_in()
+ *
+ * @param string
+ * @return string
+ */
+ protected function _group_get_type($type)
+ {
+ if ($this->qb_where_group_started)
+ {
+ $type = '';
+ $this->qb_where_group_started = FALSE;
+ }
+
+ return $type;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * GROUP BY
+ *
+ * @param string
+ * @return object
+ */
+ public function group_by($by)
+ {
+ if (is_string($by))
+ {
+ $by = explode(',', $by);
+ }
+
+ foreach ($by as $val)
+ {
+ $val = trim($val);
+
+ if ($val != '')
+ {
+ $this->qb_groupby[] = $val = $this->_protect_identifiers($val);
+
+ if ($this->qb_caching === TRUE)
+ {
+ $this->qb_cache_groupby[] = $val;
+ $this->qb_cache_exists[] = 'groupby';
+ }
+ }
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Sets the HAVING value
+ *
+ * Separates multiple calls with AND
+ *
+ * @param string
+ * @param string
+ * @return object
+ */
+ public function having($key, $value = '', $escape = TRUE)
+ {
+ return $this->_having($key, $value, 'AND ', $escape);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Sets the OR HAVING value
+ *
+ * Separates multiple calls with OR
+ *
+ * @param string
+ * @param string
+ * @return object
+ */
+ public function or_having($key, $value = '', $escape = TRUE)
+ {
+ return $this->_having($key, $value, 'OR ', $escape);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Sets the HAVING values
+ *
+ * Called by having() or or_having()
+ *
+ * @param string
+ * @param string
+ * @return object
+ */
+ protected function _having($key, $value = '', $type = 'AND ', $escape = TRUE)
+ {
+ if ( ! is_array($key))
+ {
+ $key = array($key => $value);
+ }
+
+ foreach ($key as $k => $v)
+ {
+ $prefix = (count($this->qb_having) === 0) ? '' : $type;
+
+ if ($escape === TRUE)
+ {
+ $k = $this->_protect_identifiers($k);
+ }
+
+ if ( ! $this->_has_operator($k))
+ {
+ $k .= ' = ';
+ }
+
+ if ($v != '')
+ {
+ $v = ' '.$this->escape($v);
+ }
+
+ $this->qb_having[] = $prefix.$k.$v;
+ if ($this->qb_caching === TRUE)
+ {
+ $this->qb_cache_having[] = $prefix.$k.$v;
+ $this->qb_cache_exists[] = 'having';
+ }
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Sets the ORDER BY value
+ *
+ * @param string
+ * @param string direction: asc or desc
+ * @param bool enable field name escaping
+ * @return object
+ */
+ public function order_by($orderby, $direction = '', $escape = TRUE)
+ {
+ if (strtolower($direction) === 'random')
+ {
+ $orderby = ''; // Random results want or don't need a field name
+ $direction = $this->_random_keyword;
+ }
+ elseif (trim($direction) != '')
+ {
+ $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC';
+ }
+
+
+ if ((strpos($orderby, ',') !== FALSE) && $escape === TRUE)
+ {
+ $temp = array();
+ foreach (explode(',', $orderby) as $part)
+ {
+ $part = trim($part);
+ if ( ! in_array($part, $this->qb_aliased_tables))
+ {
+ $part = $this->_protect_identifiers(trim($part));
+ }
+
+ $temp[] = $part;
+ }
+
+ $orderby = implode(', ', $temp);
+ }
+ elseif ($direction != $this->_random_keyword)
+ {
+ if ($escape === TRUE)
+ {
+ $orderby = $this->_protect_identifiers($orderby);
+ }
+ }
+
+ $this->qb_orderby[] = $orderby_statement = $orderby.$direction;
+
+ if ($this->qb_caching === TRUE)
+ {
+ $this->qb_cache_orderby[] = $orderby_statement;
+ $this->qb_cache_exists[] = 'orderby';
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Sets the LIMIT value
+ *
+ * @param integer the limit value
+ * @param integer the offset value
+ * @return object
+ */
+ public function limit($value, $offset = NULL)
+ {
+ $this->qb_limit = (int) $value;
+
+ if ( ! is_null($offset))
+ {
+ $this->qb_offset = (int) $offset;
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Sets the OFFSET value
+ *
+ * @param integer the offset value
+ * @return object
+ */
+ public function offset($offset)
+ {
+ $this->qb_offset = (int) $offset;
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * The "set" function. Allows key/value pairs to be set for inserting or updating
+ *
+ * @param mixed
+ * @param string
+ * @param boolean
+ * @return object
+ */
+ public function set($key, $value = '', $escape = TRUE)
+ {
+ $key = $this->_object_to_array($key);
+
+ if ( ! is_array($key))
+ {
+ $key = array($key => $value);
+ }
+
+ foreach ($key as $k => $v)
+ {
+ if ($escape === FALSE)
+ {
+ $this->qb_set[$this->_protect_identifiers($k)] = $v;
+ }
+ else
+ {
+ $this->qb_set[$this->_protect_identifiers($k, FALSE, TRUE)] = $this->escape($v);
+ }
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Get SELECT query string
+ *
+ * Compiles a SELECT query string and returns the sql.
+ *
+ * @access public
+ * @param string the table name to select from (optional)
+ * @param boolean TRUE: resets AR values; FALSE: leave AR vaules alone
+ * @return string
+ */
+ public function get_compiled_select($table = '', $reset = TRUE)
+ {
+ if ($table != '')
+ {
+ $this->_track_aliases($table);
+ $this->from($table);
+ }
+
+ $select = $this->_compile_select();
+
+ if ($reset === TRUE)
+ {
+ $this->_reset_select();
+ }
+
+ return $select;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Get
+ *
+ * Compiles the select statement based on the other functions called
+ * and runs the query
+ *
+ * @param string the table
+ * @param string the limit clause
+ * @param string the offset clause
+ * @return object
+ */
+ public function get($table = '', $limit = null, $offset = null)
+ {
+ if ($table != '')
+ {
+ $this->_track_aliases($table);
+ $this->from($table);
+ }
+
+ if ( ! is_null($limit))
+ {
+ $this->limit($limit, $offset);
+ }
+
+ $result = $this->query($this->_compile_select());
+ $this->_reset_select();
+ return $result;
+ }
+
+ /**
+ * "Count All Results" query
+ *
+ * Generates a platform-specific query string that counts all records
+ * returned by an Query Builder query.
+ *
+ * @param string
+ * @return string
+ */
+ public function count_all_results($table = '')
+ {
+ if ($table != '')
+ {
+ $this->_track_aliases($table);
+ $this->from($table);
+ }
+
+ $result = $this->query($this->_compile_select($this->_count_string.$this->_protect_identifiers('numrows')));
+ $this->_reset_select();
+
+ if ($result->num_rows() === 0)
+ {
+ return 0;
+ }
+
+ $row = $result->row();
+ return (int) $row->numrows;
+ }
+ // --------------------------------------------------------------------
+
+ /**
+ * Get_Where
+ *
+ * Allows the where clause, limit and offset to be added directly
+ *
+ * @param string the where clause
+ * @param string the limit clause
+ * @param string the offset clause
+ * @return object
+ */
+ public function get_where($table = '', $where = null, $limit = null, $offset = null)
+ {
+ if ($table != '')
+ {
+ $this->from($table);
+ }
+
+ if ( ! is_null($where))
+ {
+ $this->where($where);
+ }
+
+ if ( ! is_null($limit))
+ {
+ $this->limit($limit, $offset);
+ }
+
+ $result = $this->query($this->_compile_select());
+ $this->_reset_select();
+ return $result;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Insert_Batch
+ *
+ * Compiles batch insert strings and runs the queries
+ *
+ * @param string the table to retrieve the results from
+ * @param array an associative array of insert values
+ * @return object
+ */
+ public function insert_batch($table = '', $set = NULL)
+ {
+ if ( ! is_null($set))
+ {
+ $this->set_insert_batch($set);
+ }
+
+ if (count($this->qb_set) === 0)
+ {
+ if ($this->db_debug)
+ {
+ // No valid data array. Folds in cases where keys and values did not match up
+ return $this->display_error('db_must_use_set');
+ }
+ return FALSE;
+ }
+
+ if ($table == '')
+ {
+ if ( ! isset($this->qb_from[0]))
+ {
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
+ }
+
+ $table = $this->qb_from[0];
+ }
+
+ // Batch this baby
+ for ($i = 0, $total = count($this->qb_set); $i < $total; $i += 100)
+ {
+ $this->query($this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->qb_keys, array_slice($this->qb_set, $i, 100)));
+ }
+
+ $this->_reset_write();
+ return TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts
+ *
+ * @param mixed
+ * @param string
+ * @param boolean
+ * @return object
+ */
+ public function set_insert_batch($key, $value = '', $escape = TRUE)
+ {
+ $key = $this->_object_to_array_batch($key);
+
+ if ( ! is_array($key))
+ {
+ $key = array($key => $value);
+ }
+
+ $keys = array_keys(current($key));
+ sort($keys);
+
+ foreach ($key as $row)
+ {
+ if (count(array_diff($keys, array_keys($row))) > 0 OR count(array_diff(array_keys($row), $keys)) > 0)
+ {
+ // batch function above returns an error on an empty array
+ $this->qb_set[] = array();
+ return;
+ }
+
+ ksort($row); // puts $row in the same order as our keys
+
+ if ($escape === FALSE)
+ {
+ $this->qb_set[] = '('.implode(',', $row).')';
+ }
+ else
+ {
+ $clean = array();
+ foreach ($row as $value)
+ {
+ $clean[] = $this->escape($value);
+ }
+
+ $this->qb_set[] = '('.implode(',', $clean).')';
+ }
+ }
+
+ foreach ($keys as $k)
+ {
+ $this->qb_keys[] = $this->_protect_identifiers($k);
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Get INSERT query string
+ *
+ * Compiles an insert query and returns the sql
+ *
+ * @access public
+ * @param string the table to insert into
+ * @param boolean TRUE: reset AR values; FALSE: leave AR values alone
+ * @return string
+ */
+ public function get_compiled_insert($table = '', $reset = TRUE)
+ {
+ if ($this->_validate_insert($table) === FALSE)
+ {
+ return FALSE;
+ }
+
+ $sql = $this->_insert(
+ $this->_protect_identifiers(
+ $this->qb_from[0], TRUE, NULL, FALSE
+ ),
+ array_keys($this->qb_set),
+ array_values($this->qb_set)
+ );
+
+ if ($reset === TRUE)
+ {
+ $this->_reset_write();
+ }
+
+ return $sql;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Insert
+ *
+ * Compiles an insert string and runs the query
+ *
+ * @access public
+ * @param string the table to insert data into
+ * @param array an associative array of insert values
+ * @return object
+ */
+ public function insert($table = '', $set = NULL)
+ {
+ if ( ! is_null($set))
+ {
+ $this->set($set);
+ }
+
+ if ($this->_validate_insert($table) === FALSE)
+ {
+ return FALSE;
+ }
+
+ $sql = $this->_insert(
+ $this->_protect_identifiers(
+ $this->qb_from[0], TRUE, NULL, FALSE
+ ),
+ array_keys($this->qb_set),
+ array_values($this->qb_set)
+ );
+
+ $this->_reset_write();
+ return $this->query($sql);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Validate Insert
+ *
+ * This method is used by both insert() and get_compiled_insert() to
+ * validate that the there data is actually being set and that table
+ * has been chosen to be inserted into.
+ *
+ * @access public
+ * @param string the table to insert data into
+ * @return string
+ */
+ protected function _validate_insert($table = '')
+ {
+ if (count($this->qb_set) === 0)
+ {
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
+ }
+
+ if ($table == '')
+ {
+ if ( ! isset($this->qb_from[0]))
+ {
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
+ }
+ }
+ else
+ {
+ $this->qb_from[0] = $table;
+ }
+
+ return TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Replace
+ *
+ * Compiles an replace into string and runs the query
+ *
+ * @param string the table to replace data into
+ * @param array an associative array of insert values
+ * @return object
+ */
+ public function replace($table = '', $set = NULL)
+ {
+ if ( ! is_null($set))
+ {
+ $this->set($set);
+ }
+
+ if (count($this->qb_set) === 0)
+ {
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
+ }
+
+ if ($table == '')
+ {
+ if ( ! isset($this->qb_from[0]))
+ {
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
+ }
+
+ $table = $this->qb_from[0];
+ }
+
+ $sql = $this->_replace($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->qb_set), array_values($this->qb_set));
+ $this->_reset_write();
+ return $this->query($sql);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Get UPDATE query string
+ *
+ * Compiles an update query and returns the sql
+ *
+ * @access public
+ * @param string the table to update
+ * @param boolean TRUE: reset AR values; FALSE: leave AR values alone
+ * @return string
+ */
+ public function get_compiled_update($table = '', $reset = TRUE)
+ {
+ // Combine any cached components with the current statements
+ $this->_merge_cache();
+
+ if ($this->_validate_update($table) === FALSE)
+ {
+ return FALSE;
+ }
+
+ $sql = $this->_update($this->_protect_identifiers($this->qb_from[0], TRUE, NULL, FALSE), $this->qb_set, $this->qb_where, $this->qb_orderby, $this->qb_limit);
+
+ if ($reset === TRUE)
+ {
+ $this->_reset_write();
+ }
+
+ return $sql;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Update
+ *
+ * Compiles an update string and runs the query
+ *
+ * @param string the table to retrieve the results from
+ * @param array an associative array of update values
+ * @param mixed the where clause
+ * @return object
+ */
+ public function update($table = '', $set = NULL, $where = NULL, $limit = NULL)
+ {
+ // Combine any cached components with the current statements
+ $this->_merge_cache();
+
+ if ( ! is_null($set))
+ {
+ $this->set($set);
+ }
+
+ if ($this->_validate_update($table) === FALSE)
+ {
+ return FALSE;
+ }
+
+ if ($where != NULL)
+ {
+ $this->where($where);
+ }
+
+ if ($limit != NULL)
+ {
+ $this->limit($limit);
+ }
+
+ $sql = $this->_update($this->_protect_identifiers($this->qb_from[0], TRUE, NULL, FALSE), $this->qb_set, $this->qb_where, $this->qb_orderby, $this->qb_limit, $this->qb_like);
+ $this->_reset_write();
+ return $this->query($sql);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Validate Update
+ *
+ * This method is used by both update() and get_compiled_update() to
+ * validate that data is actually being set and that a table has been
+ * chosen to be update.
+ *
+ * @access public
+ * @param string the table to update data on
+ * @return bool
+ */
+ protected function _validate_update($table = '')
+ {
+ if (count($this->qb_set) == 0)
+ {
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
+ }
+
+ if ($table == '')
+ {
+ if ( ! isset($this->qb_from[0]))
+ {
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
+ }
+ }
+ else
+ {
+ $this->qb_from[0] = $table;
+ }
+
+ return TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Update_Batch
+ *
+ * Compiles an update string and runs the query
+ *
+ * @param string the table to retrieve the results from
+ * @param array an associative array of update values
+ * @param string the where key
+ * @return bool
+ */
+ public function update_batch($table = '', $set = NULL, $index = NULL)
+ {
+ // Combine any cached components with the current statements
+ $this->_merge_cache();
+
+ if (is_null($index))
+ {
+ return ($this->db_debug) ? $this->display_error('db_must_use_index') : FALSE;
+ }
+
+ if ( ! is_null($set))
+ {
+ $this->set_update_batch($set, $index);
+ }
+
+ if (count($this->qb_set) === 0)
+ {
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
+ }
+
+ if ($table == '')
+ {
+ if ( ! isset($this->qb_from[0]))
+ {
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
+ }
+
+ $table = $this->qb_from[0];
+ }
+
+ // Batch this baby
+ for ($i = 0, $total = count($this->qb_set); $i < $total; $i += 100)
+ {
+ $this->query($this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->qb_set, $i, 100), $this->_protect_identifiers($index), $this->qb_where));
+ }
+
+ $this->_reset_write();
+ return TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * The "set_update_batch" function. Allows key/value pairs to be set for batch updating
+ *
+ * @param array
+ * @param string
+ * @param boolean
+ * @return object
+ */
+ public function set_update_batch($key, $index = '', $escape = TRUE)
+ {
+ $key = $this->_object_to_array_batch($key);
+
+ if ( ! is_array($key))
+ {
+ // @todo error
+ }
+
+ foreach ($key as $k => $v)
+ {
+ $index_set = FALSE;
+ $clean = array();
+ foreach ($v as $k2 => $v2)
+ {
+ if ($k2 == $index)
+ {
+ $index_set = TRUE;
+ }
+ else
+ {
+ $not[] = $k.'-'.$v;
+ }
+
+ $clean[$this->_protect_identifiers($k2)] = ($escape === FALSE) ? $v2 : $this->escape($v2);
+ }
+
+ if ($index_set == FALSE)
+ {
+ return $this->display_error('db_batch_missing_index');
+ }
+
+ $this->qb_set[] = $clean;
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Empty Table
+ *
+ * Compiles a delete string and runs "DELETE FROM table"
+ *
+ * @param string the table to empty
+ * @return object
+ */
+ public function empty_table($table = '')
+ {
+ if ($table == '')
+ {
+ if ( ! isset($this->qb_from[0]))
+ {
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
+ }
+
+ $table = $this->qb_from[0];
+ }
+ else
+ {
+ $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ }
+
+ $sql = $this->_delete($table);
+ $this->_reset_write();
+ return $this->query($sql);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Truncate
+ *
+ * Compiles a truncate string and runs the query
+ * If the database does not support the truncate() command
+ * This function maps to "DELETE FROM table"
+ *
+ * @param string the table to truncate
+ * @return object
+ */
+ public function truncate($table = '')
+ {
+ if ($table == '')
+ {
+ if ( ! isset($this->qb_from[0]))
+ {
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
+ }
+
+ $table = $this->qb_from[0];
+ }
+ else
+ {
+ $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ }
+
+ $sql = $this->_truncate($table);
+ $this->_reset_write();
+ return $this->query($sql);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Get DELETE query string
+ *
+ * Compiles a delete query string and returns the sql
+ *
+ * @access public
+ * @param string the table to delete from
+ * @param boolean TRUE: reset AR values; FALSE: leave AR values alone
+ * @return string
+ */
+ public function get_compiled_delete($table = '', $reset = TRUE)
+ {
+ $this->return_delete_sql = TRUE;
+ $sql = $this->delete($table, '', NULL, $reset);
+ $this->return_delete_sql = FALSE;
+ return $sql;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Delete
+ *
+ * Compiles a delete string and runs the query
+ *
+ * @param mixed the table(s) to delete from. String or array
+ * @param mixed the where clause
+ * @param mixed the limit clause
+ * @param boolean
+ * @return object
+ */
+ public function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE)
+ {
+ // Combine any cached components with the current statements
+ $this->_merge_cache();
+
+ if ($table == '')
+ {
+ if ( ! isset($this->qb_from[0]))
+ {
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
+ }
+
+ $table = $this->qb_from[0];
+ }
+ elseif (is_array($table))
+ {
+ foreach ($table as $single_table)
+ {
+ $this->delete($single_table, $where, $limit, FALSE);
+ }
+
+ $this->_reset_write();
+ return;
+ }
+ else
+ {
+ $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ }
+
+ if ($where != '')
+ {
+ $this->where($where);
+ }
+
+ if ($limit != NULL)
+ {
+ $this->limit($limit);
+ }
+
+ if (count($this->qb_where) === 0 && count($this->qb_wherein) === 0 && count($this->qb_like) === 0)
+ {
+ return ($this->db_debug) ? $this->display_error('db_del_must_use_where') : FALSE;
+ }
+
+ $sql = $this->_delete($table, $this->qb_where, $this->qb_like, $this->qb_limit);
+ if ($reset_data)
+ {
+ $this->_reset_write();
+ }
+
+ return ($this->return_delete_sql === TRUE) ? $sql : $this->query($sql);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * DB Prefix
+ *
+ * Prepends a database prefix if one exists in configuration
+ *
+ * @param string the table
+ * @return string
+ */
+ public function dbprefix($table = '')
+ {
+ if ($table == '')
+ {
+ $this->display_error('db_table_name_required');
+ }
+
+ return $this->dbprefix.$table;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Set DB Prefix
+ *
+ * Set's the DB Prefix to something new without needing to reconnect
+ *
+ * @param string the prefix
+ * @return string
+ */
+ public function set_dbprefix($prefix = '')
+ {
+ return $this->dbprefix = $prefix;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Track Aliases
+ *
+ * Used to track SQL statements written with aliased tables.
+ *
+ * @param string The table to inspect
+ * @return string
+ */
+ protected function _track_aliases($table)
+ {
+ if (is_array($table))
+ {
+ foreach ($table as $t)
+ {
+ $this->_track_aliases($t);
+ }
+ return;
+ }
+
+ // Does the string contain a comma? If so, we need to separate
+ // the string into discreet statements
+ if (strpos($table, ',') !== FALSE)
+ {
+ return $this->_track_aliases(explode(',', $table));
+ }
+
+ // if a table alias is used we can recognize it by a space
+ if (strpos($table, ' ') !== FALSE)
+ {
+ // if the alias is written with the AS keyword, remove it
+ $table = preg_replace('/ AS /i', ' ', $table);
+
+ // Grab the alias
+ $table = trim(strrchr($table, ' '));
+
+ // Store the alias, if it doesn't already exist
+ if ( ! in_array($table, $this->qb_aliased_tables))
+ {
+ $this->qb_aliased_tables[] = $table;
+ }
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Compile the SELECT statement
+ *
+ * Generates a query string based on which functions were used.
+ * Should not be called directly. The get() function calls it.
+ *
+ * @return string
+ */
+ protected function _compile_select($select_override = FALSE)
+ {
+ // Combine any cached components with the current statements
+ $this->_merge_cache();
+
+ // Write the "select" portion of the query
+ if ($select_override !== FALSE)
+ {
+ $sql = $select_override;
+ }
+ else
+ {
+ $sql = ( ! $this->qb_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';
+
+ if (count($this->qb_select) === 0)
+ {
+ $sql .= '*';
+ }
+ else
+ {
+ // Cycle through the "select" portion of the query and prep each column name.
+ // The reason we protect identifiers here rather then in the select() function
+ // is because until the user calls the from() function we don't know if there are aliases
+ foreach ($this->qb_select as $key => $val)
+ {
+ $no_escape = isset($this->qb_no_escape[$key]) ? $this->qb_no_escape[$key] : NULL;
+ $this->qb_select[$key] = $this->_protect_identifiers($val, FALSE, $no_escape);
+ }
+
+ $sql .= implode(', ', $this->qb_select);
+ }
+ }
+
+ // Write the "FROM" portion of the query
+ if (count($this->qb_from) > 0)
+ {
+ $sql .= "\nFROM ".$this->_from_tables($this->qb_from);
+ }
+
+ // Write the "JOIN" portion of the query
+ if (count($this->qb_join) > 0)
+ {
+ $sql .= "\n".implode("\n", $this->qb_join);
+ }
+
+ // Write the "WHERE" portion of the query
+ if (count($this->qb_where) > 0 OR count($this->qb_like) > 0)
+ {
+ $sql .= "\nWHERE ";
+ }
+
+ $sql .= implode("\n", $this->qb_where);
+
+ // Write the "LIKE" portion of the query
+ if (count($this->qb_like) > 0)
+ {
+ if (count($this->qb_where) > 0)
+ {
+ $sql .= "\nAND ";
+ }
+
+ $sql .= implode("\n", $this->qb_like);
+ }
+
+ // Write the "GROUP BY" portion of the query
+ if (count($this->qb_groupby) > 0)
+ {
+ $sql .= "\nGROUP BY ".implode(', ', $this->qb_groupby);
+ }
+
+ // Write the "HAVING" portion of the query
+ if (count($this->qb_having) > 0)
+ {
+ $sql .= "\nHAVING ".implode("\n", $this->qb_having);
+ }
+
+ // Write the "ORDER BY" portion of the query
+ if (count($this->qb_orderby) > 0)
+ {
+ $sql .= "\nORDER BY ".implode(', ', $this->qb_orderby);
+ if ($this->qb_order !== FALSE)
+ {
+ $sql .= ($this->qb_order == 'desc') ? ' DESC' : ' ASC';
+ }
+ }
+
+ // Write the "LIMIT" portion of the query
+ if (is_numeric($this->qb_limit))
+ {
+ return $this->_limit($sql."\n", $this->qb_limit, $this->qb_offset);
+ }
+
+ return $sql;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Object to Array
+ *
+ * Takes an object as input and converts the class variables to array key/vals
+ *
+ * @param object
+ * @return array
+ */
+ public function _object_to_array($object)
+ {
+ if ( ! is_object($object))
+ {
+ return $object;
+ }
+
+ $array = array();
+ foreach (get_object_vars($object) as $key => $val)
+ {
+ // There are some built in keys we need to ignore for this conversion
+ if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name')
+ {
+ $array[$key] = $val;
+ }
+ }
+
+ return $array;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Object to Array
+ *
+ * Takes an object as input and converts the class variables to array key/vals
+ *
+ * @param object
+ * @return array
+ */
+ public function _object_to_array_batch($object)
+ {
+ if ( ! is_object($object))
+ {
+ return $object;
+ }
+
+ $array = array();
+ $out = get_object_vars($object);
+ $fields = array_keys($out);
+
+ foreach ($fields as $val)
+ {
+ // There are some built in keys we need to ignore for this conversion
+ if ($val !== '_parent_name')
+ {
+ $i = 0;
+ foreach ($out[$val] as $data)
+ {
+ $array[$i++][$val] = $data;
+ }
+ }
+ }
+
+ return $array;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Start Cache
+ *
+ * Starts AR caching
+ *
+ * @return void
+ */
+ public function start_cache()
+ {
+ $this->qb_caching = TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Stop Cache
+ *
+ * Stops AR caching
+ *
+ * @return void
+ */
+ public function stop_cache()
+ {
+ $this->qb_caching = FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Flush Cache
+ *
+ * Empties the AR cache
+ *
+ * @access public
+ * @return void
+ */
+ public function flush_cache()
+ {
+ $this->_reset_run(array(
+ 'ar_cache_select' => array(),
+ 'ar_cache_from' => array(),
+ 'ar_cache_join' => array(),
+ 'ar_cache_where' => array(),
+ 'ar_cache_like' => array(),
+ 'ar_cache_groupby' => array(),
+ 'ar_cache_having' => array(),
+ 'ar_cache_orderby' => array(),
+ 'ar_cache_set' => array(),
+ 'ar_cache_exists' => array(),
+ 'ar_cache_no_escape' => array()
+ ));
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Merge Cache
+ *
+ * When called, this function merges any cached AR arrays with
+ * locally called ones.
+ *
+ * @return void
+ */
+ protected function _merge_cache()
+ {
+ if (count($this->qb_cache_exists) === 0)
+ {
+ return;
+ }
+
+ foreach ($this->qb_cache_exists as $val)
+ {
+ $qb_variable = 'ar_'.$val;
+ $qb_cache_var = 'ar_cache_'.$val;
+
+ if (count($this->$qb_cache_var) === 0)
+ {
+ continue;
+ }
+
+ $this->$qb_variable = array_unique(array_merge($this->$qb_cache_var, $this->$qb_variable));
+ }
+
+ // If we are "protecting identifiers" we need to examine the "from"
+ // portion of the query to determine if there are any aliases
+ if ($this->_protect_identifiers === TRUE AND count($this->qb_cache_from) > 0)
+ {
+ $this->_track_aliases($this->qb_from);
+ }
+
+ $this->qb_no_escape = $this->qb_cache_no_escape;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Reset Query Builder values.
+ *
+ * Publicly-visible method to reset the AR values.
+ *
+ * @return void
+ */
+ public function reset_query()
+ {
+ $this->_reset_select();
+ $this->_reset_write();
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Resets the query builder values. Called by the get() function
+ *
+ * @param array An array of fields to reset
+ * @return void
+ */
+ protected function _reset_run($qb_reset_items)
+ {
+ foreach ($qb_reset_items as $item => $default_value)
+ {
+ if ( ! in_array($item, $this->qb_store_array))
+ {
+ $this->$item = $default_value;
+ }
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Resets the query builder values. Called by the get() function
+ *
+ * @return void
+ */
+ protected function _reset_select()
+ {
+ $this->_reset_run(array(
+ 'ar_select' => array(),
+ 'ar_from' => array(),
+ 'ar_join' => array(),
+ 'ar_where' => array(),
+ 'ar_like' => array(),
+ 'ar_groupby' => array(),
+ 'ar_having' => array(),
+ 'ar_orderby' => array(),
+ 'ar_wherein' => array(),
+ 'ar_aliased_tables' => array(),
+ 'ar_no_escape' => array(),
+ 'ar_distinct' => FALSE,
+ 'ar_limit' => FALSE,
+ 'ar_offset' => FALSE,
+ 'ar_order' => FALSE
+ )
+ );
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Resets the query builder "write" values.
+ *
+ * Called by the insert() update() insert_batch() update_batch() and delete() functions
+ *
+ * @return void
+ */
+ protected function _reset_write()
+ {
+ $this->_reset_run(array(
+ 'ar_set' => array(),
+ 'ar_from' => array(),
+ 'ar_where' => array(),
+ 'ar_like' => array(),
+ 'ar_orderby' => array(),
+ 'ar_keys' => array(),
+ 'ar_limit' => FALSE,
+ 'ar_order' => FALSE
+ )
+ );
+ }
+
+}
+
+/* End of file DB_query_builder.php */
+/* Location: ./system/database/DB_query_builder.php */
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index cde719eae..ccabb3b4b 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -31,7 +31,7 @@
* CUBRID Database Adapter Class
*
* Note: _DB is an extender class that the app controller
- * creates dynamically based on whether the active record
+ * creates dynamically based on whether the query builder
* class is being used or not.
*
* @package CodeIgniter
@@ -742,7 +742,7 @@ class CI_DB_cubrid_driver extends CI_DB {
if (count($where) > 0 OR count($like) > 0)
{
$conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions .= implode("\n", $this->qb_where);
if (count($where) > 0 && count($like) > 0)
{
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 2a1098932..b809241b4 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -31,7 +31,7 @@
* MS SQL Database Adapter Class
*
* Note: _DB is an extender class that the app controller
- * creates dynamically based on whether the active record
+ * creates dynamically based on whether the query builder
* class is being used or not.
*
* @package CodeIgniter
@@ -623,7 +623,7 @@ class CI_DB_mssql_driver extends CI_DB {
if (count($where) > 0 OR count($like) > 0)
{
$conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions .= implode("\n", $this->qb_where);
if (count($where) > 0 && count($like) > 0)
{
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index 067710ff0..9b5e331b8 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -29,7 +29,7 @@
* MySQL Database Adapter Class
*
* Note: _DB is an extender class that the app controller
- * creates dynamically based on whether the active record
+ * creates dynamically based on whether the query builder
* class is being used or not.
*
* @package CodeIgniter
@@ -646,7 +646,7 @@ class CI_DB_mysql_driver extends CI_DB {
if (count($where) > 0 OR count($like) > 0)
{
- $conditions = "\nWHERE ".implode("\n", $this->ar_where);
+ $conditions = "\nWHERE ".implode("\n", $this->qb_where);
if (count($where) > 0 && count($like) > 0)
{
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index a79b2a4ad..f2d679f43 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -29,7 +29,7 @@
* MySQLi Database Adapter Class
*
* Note: _DB is an extender class that the app controller
- * creates dynamically based on whether the active record
+ * creates dynamically based on whether the query builder
* class is being used or not.
*
* @package CodeIgniter
@@ -641,7 +641,7 @@ class CI_DB_mysqli_driver extends CI_DB {
$conditions = '';
if (count($where) > 0 OR count($like) > 0)
{
- $conditions = "\nWHERE ".implode("\n", $this->ar_where);
+ $conditions = "\nWHERE ".implode("\n", $this->qb_where);
if (count($where) > 0 && count($like) > 0)
{
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index c6621901b..5fbc0a0a0 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -31,7 +31,7 @@
* oci8 Database Adapter Class
*
* Note: _DB is an extender class that the app controller
- * creates dynamically based on whether the active record
+ * creates dynamically based on whether the query builder
* class is being used or not.
*
* @package CodeIgniter
@@ -754,7 +754,7 @@ class CI_DB_oci8_driver extends CI_DB {
if (count($where) > 0 OR count($like) > 0)
{
$conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions .= implode("\n", $this->qb_where);
if (count($where) > 0 && count($like) > 0)
{
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index 6ba39f0cd..695d0080a 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -31,7 +31,7 @@
* ODBC Database Adapter Class
*
* Note: _DB is an extender class that the app controller
- * creates dynamically based on whether the active record
+ * creates dynamically based on whether the query builder
* class is being used or not.
*
* @package CodeIgniter
@@ -593,7 +593,7 @@ class CI_DB_odbc_driver extends CI_DB {
if (count($where) > 0 OR count($like) > 0)
{
$conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions .= implode("\n", $this->qb_where);
if (count($where) > 0 && count($like) > 0)
{
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index de2b0abeb..77d9adf78 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -31,7 +31,7 @@
* PDO Database Adapter Class
*
* Note: _DB is an extender class that the app controller
- * creates dynamically based on whether the active record
+ * creates dynamically based on whether the query builder
* class is being used or not.
*
* @package CodeIgniter
@@ -888,7 +888,7 @@ class CI_DB_pdo_driver extends CI_DB {
if (count($where) > 0 OR count($like) > 0)
{
$conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions .= implode("\n", $this->qb_where);
if (count($where) > 0 && count($like) > 0)
{
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 42329bded..3a172bc9e 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -31,7 +31,7 @@
* Postgre Database Adapter Class
*
* Note: _DB is an extender class that the app controller
- * creates dynamically based on whether the active record
+ * creates dynamically based on whether the query builder
* class is being used or not.
*
* @package CodeIgniter
@@ -655,7 +655,7 @@ class CI_DB_postgre_driver extends CI_DB {
if (count($where) > 0 OR count($like) > 0)
{
$conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions .= implode("\n", $this->qb_where);
if (count($where) > 0 && count($like) > 0)
{
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index 28c3caecd..3a7b7c673 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -33,7 +33,7 @@
* SQLite Database Adapter Class
*
* Note: _DB is an extender class that the app controller
- * creates dynamically based on whether the active record
+ * creates dynamically based on whether the query builder
* class is being used or not.
*
* @package CodeIgniter
@@ -607,7 +607,7 @@ class CI_DB_sqlite_driver extends CI_DB {
if (count($where) > 0 OR count($like) > 0)
{
$conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
+ $conditions .= implode("\n", $this->qb_where);
if (count($where) > 0 && count($like) > 0)
{
diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php
index 6fd52ef70..a21009ad3 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_driver.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -31,7 +31,7 @@
* SQLSRV Database Adapter Class
*
* Note: _DB is an extender class that the app controller
- * creates dynamically based on whether the active record
+ * creates dynamically based on whether the query builder
* class is being used or not.
*
* @package CodeIgniter
diff --git a/user_guide_src/source/database/active_record.rst b/user_guide_src/source/database/active_record.rst
deleted file mode 100644
index c04e67d2a..000000000
--- a/user_guide_src/source/database/active_record.rst
+++ /dev/null
@@ -1,1008 +0,0 @@
-###################
-Active Record Class
-###################
-
-CodeIgniter uses a modified version of the Active Record Database
-Pattern. This pattern allows information to be retrieved, inserted, and
-updated in your database with minimal scripting. In some cases only one
-or two lines of code are necessary to perform a database action.
-CodeIgniter does not require that each database table be its own class
-file. It instead provides a more simplified interface.
-
-Beyond simplicity, a major benefit to using the Active Record features
-is that it allows you to create database independent applications, since
-the query syntax is generated by each database adapter. It also allows
-for safer queries, since the values are escaped automatically by the
-system.
-
-.. note:: If you intend to write your own queries you can disable this
- class in your database config file, allowing the core database library
- and adapter to utilize fewer resources.
-
-.. contents:: Page Contents
-
-**************
-Selecting Data
-**************
-
-The following functions allow you to build SQL **SELECT** statements.
-
-$this->db->get()
-================
-
-Runs the selection query and returns the result. Can be used by itself
-to retrieve all records from a table::
-
- $query = $this->db->get('mytable'); // Produces: SELECT * FROM mytable
-
-The second and third parameters enable you to set a limit and offset
-clause::
-
- $query = $this->db->get('mytable', 10, 20);
- // Produces: SELECT * FROM mytable LIMIT 20, 10 (in MySQL. Other databases have slightly different syntax)
-
-You'll notice that the above function is assigned to a variable named
-$query, which can be used to show the results::
-
- $query = $this->db->get('mytable');
-
- foreach ($query->result() as $row)
- {
- echo $row->title;
- }
-
-Please visit the :doc:`result functions ` page for a full
-discussion regarding result generation.
-
-$this->db->get_compiled_select()
-================================
-
-Compiles the selection query just like `$this->db->get()`_ but does not *run*
-the query. This method simply returns the SQL query as a string.
-
-Example::
-
- $sql = $this->db->get_compiled_select('mytable');
- echo $sql;
-
- // Produces string: SELECT * FROM mytable
-
-The second parameter enables you to set whether or not the active record query
-will be reset (by default it will be—just like `$this->db->get()`)::
-
- echo $this->db->limit(10,20)->get_compiled_select('mytable', FALSE);
- // Produces string: SELECT * FROM mytable LIMIT 20, 10
- // (in MySQL. Other databases have slightly different syntax)
-
- echo $this->db->select('title, content, date')->get_compiled_select();
-
- // Produces string: SELECT title, content, date FROM mytable
-
-The key thing to notice in the above example is that the second query did not
-utilize `$this->db->from()`_ and did not pass a table name into the first
-parameter. The reason for this outcome is because the query has not been
-executed using `$this->db->get()`_ which resets values or reset directly
-using `$this->db->reset_query()`_.
-
-
-$this->db->get_where()
-======================
-
-Identical to the above function except that it permits you to add a
-"where" clause in the second parameter, instead of using the db->where()
-function::
-
- $query = $this->db->get_where('mytable', array('id' => $id), $limit, $offset);
-
-Please read the about the where function below for more information.
-
-.. note:: get_where() was formerly known as getwhere(), which has been removed
-
-$this->db->select()
-===================
-
-Permits you to write the SELECT portion of your query::
-
- $this->db->select('title, content, date');
- $query = $this->db->get('mytable'); // Produces: SELECT title, content, date FROM mytable
-
-
-.. note:: If you are selecting all (\*) from a table you do not need to
- use this function. When omitted, CodeIgniter assumes you wish to SELECT *
-
-$this->db->select() accepts an optional second parameter. If you set it
-to FALSE, CodeIgniter will not try to protect your field or table names
-with backticks. This is useful if you need a compound select statement.
-
-::
-
- $this->db->select('(SELECT SUM(payments.amount) FROM payments WHERE payments.invoice_id=4') AS amount_paid', FALSE);
- $query = $this->db->get('mytable');
-
-
-$this->db->select_max()
-=======================
-
-Writes a "SELECT MAX(field)" portion for your query. You can optionally
-include a second parameter to rename the resulting field.
-
-::
-
- $this->db->select_max('age');
- $query = $this->db->get('members'); // Produces: SELECT MAX(age) as age FROM members
-
- $this->db->select_max('age', 'member_age');
- $query = $this->db->get('members'); // Produces: SELECT MAX(age) as member_age FROM members
-
-
-$this->db->select_min()
-=======================
-
-Writes a "SELECT MIN(field)" portion for your query. As with
-select_max(), You can optionally include a second parameter to rename
-the resulting field.
-
-::
-
- $this->db->select_min('age');
- $query = $this->db->get('members'); // Produces: SELECT MIN(age) as age FROM members
-
-
-$this->db->select_avg()
-=======================
-
-Writes a "SELECT AVG(field)" portion for your query. As with
-select_max(), You can optionally include a second parameter to rename
-the resulting field.
-
-::
-
- $this->db->select_avg('age');
- $query = $this->db->get('members'); // Produces: SELECT AVG(age) as age FROM members
-
-
-$this->db->select_sum()
-=======================
-
-Writes a "SELECT SUM(field)" portion for your query. As with
-select_max(), You can optionally include a second parameter to rename
-the resulting field.
-
-::
-
- $this->db->select_sum('age');
- $query = $this->db->get('members'); // Produces: SELECT SUM(age) as age FROM members
-
-
-$this->db->from()
-=================
-
-Permits you to write the FROM portion of your query::
-
- $this->db->select('title, content, date');
- $this->db->from('mytable');
- $query = $this->db->get(); // Produces: SELECT title, content, date FROM mytable
-
-.. note:: As shown earlier, the FROM portion of your query can be specified
- in the $this->db->get() function, so use whichever method you prefer.
-
-$this->db->join()
-=================
-
-Permits you to write the JOIN portion of your query::
-
- $this->db->select('*');
- $this->db->from('blogs');
- $this->db->join('comments', 'comments.id = blogs.id');
- $query = $this->db->get();
-
- // Produces:
- // SELECT * FROM blogs JOIN comments ON comments.id = blogs.id
-
-Multiple function calls can be made if you need several joins in one
-query.
-
-If you need a specific type of JOIN you can specify it via the third
-parameter of the function. Options are: left, right, outer, inner, left
-outer, and right outer.
-
-::
-
- $this->db->join('comments', 'comments.id = blogs.id', 'left');
- // Produces: LEFT JOIN comments ON comments.id = blogs.id
-
-$this->db->where()
-==================
-
-This function enables you to set **WHERE** clauses using one of four
-methods:
-
-.. note:: All values passed to this function are escaped automatically,
- producing safer queries.
-
-#. **Simple key/value method:**
-
- ::
-
- $this->db->where('name', $name); // Produces: WHERE name = 'Joe'
-
- Notice that the equal sign is added for you.
-
- If you use multiple function calls they will be chained together with
- AND between them:
-
- ::
-
- $this->db->where('name', $name);
- $this->db->where('title', $title);
- $this->db->where('status', $status);
- // WHERE name = 'Joe' AND title = 'boss' AND status = 'active'
-
-#. **Custom key/value method:**
- You can include an operator in the first parameter in order to
- control the comparison:
-
- ::
-
- $this->db->where('name !=', $name);
- $this->db->where('id <', $id); // Produces: WHERE name != 'Joe' AND id < 45
-
-#. **Associative array method:**
-
- ::
-
- $array = array('name' => $name, 'title' => $title, 'status' => $status);
- $this->db->where($array);
- // Produces: WHERE name = 'Joe' AND title = 'boss' AND status = 'active'
-
- You can include your own operators using this method as well:
-
- ::
-
- $array = array('name !=' => $name, 'id <' => $id, 'date >' => $date);
- $this->db->where($array);
-
-#. **Custom string:**
- You can write your own clauses manually::
-
- $where = "name='Joe' AND status='boss' OR status='active'";
- $this->db->where($where);
-
-
-$this->db->where() accepts an optional third parameter. If you set it to
-FALSE, CodeIgniter will not try to protect your field or table names
-with backticks.
-
-::
-
- $this->db->where('MATCH (field) AGAINST ("value")', NULL, FALSE);
-
-
-$this->db->or_where()
-=====================
-
-This function is identical to the one above, except that multiple
-instances are joined by OR::
-
- $this->db->where('name !=', $name);
- $this->db->or_where('id >', $id); // Produces: WHERE name != 'Joe' OR id > 50
-
-.. note:: or_where() was formerly known as orwhere(), which has been
- removed.
-
-$this->db->where_in()
-=====================
-
-Generates a WHERE field IN ('item', 'item') SQL query joined with AND if
-appropriate
-
-::
-
- $names = array('Frank', 'Todd', 'James');
- $this->db->where_in('username', $names);
- // Produces: WHERE username IN ('Frank', 'Todd', 'James')
-
-
-$this->db->or_where_in()
-========================
-
-Generates a WHERE field IN ('item', 'item') SQL query joined with OR if
-appropriate
-
-::
-
- $names = array('Frank', 'Todd', 'James');
- $this->db->or_where_in('username', $names);
- // Produces: OR username IN ('Frank', 'Todd', 'James')
-
-
-$this->db->where_not_in()
-=========================
-
-Generates a WHERE field NOT IN ('item', 'item') SQL query joined with
-AND if appropriate
-
-::
-
- $names = array('Frank', 'Todd', 'James');
- $this->db->where_not_in('username', $names);
- // Produces: WHERE username NOT IN ('Frank', 'Todd', 'James')
-
-
-$this->db->or_where_not_in()
-============================
-
-Generates a WHERE field NOT IN ('item', 'item') SQL query joined with OR
-if appropriate
-
-::
-
- $names = array('Frank', 'Todd', 'James');
- $this->db->or_where_not_in('username', $names);
- // Produces: OR username NOT IN ('Frank', 'Todd', 'James')
-
-
-$this->db->like()
-=================
-
-This function enables you to generate **LIKE** clauses, useful for doing
-searches.
-
-.. note:: All values passed to this function are escaped automatically.
-
-#. **Simple key/value method:**
-
- ::
-
- $this->db->like('title', 'match'); // Produces: WHERE title LIKE '%match%'
-
- If you use multiple function calls they will be chained together with
- AND between them::
-
- $this->db->like('title', 'match');
- $this->db->like('body', 'match');
- // WHERE title LIKE '%match%' AND body LIKE '%match%
-
- If you want to control where the wildcard (%) is placed, you can use
- an optional third argument. Your options are 'before', 'after' and
- 'both' (which is the default).
-
- ::
-
- $this->db->like('title', 'match', 'before'); // Produces: WHERE title LIKE '%match'
- $this->db->like('title', 'match', 'after'); // Produces: WHERE title LIKE 'match%'
- $this->db->like('title', 'match', 'both'); // Produces: WHERE title LIKE '%match%'
-
-#. **Associative array method:**
-
- ::
-
- $array = array('title' => $match, 'page1' => $match, 'page2' => $match);
- $this->db->like($array);
- // WHERE title LIKE '%match%' AND page1 LIKE '%match%' AND page2 LIKE '%match%'
-
-
-$this->db->or_like()
-====================
-
-This function is identical to the one above, except that multiple
-instances are joined by OR::
-
- $this->db->like('title', 'match'); $this->db->or_like('body', $match);
- // WHERE title LIKE '%match%' OR body LIKE '%match%'
-
-.. note:: or_like() was formerly known as orlike(), which has been removed.
-
-$this->db->not_like()
-=====================
-
-This function is identical to **like()**, except that it generates NOT
-LIKE statements::
-
- $this->db->not_like('title', 'match'); // WHERE title NOT LIKE '%match%
-
-$this->db->or_not_like()
-========================
-
-This function is identical to **not_like()**, except that multiple
-instances are joined by OR::
-
- $this->db->like('title', 'match');
- $this->db->or_not_like('body', 'match');
- // WHERE title LIKE '%match% OR body NOT LIKE '%match%'
-
-$this->db->group_by()
-=====================
-
-Permits you to write the GROUP BY portion of your query::
-
- $this->db->group_by("title"); // Produces: GROUP BY title
-
-You can also pass an array of multiple values as well::
-
- $this->db->group_by(array("title", "date")); // Produces: GROUP BY title, date
-
-.. note:: group_by() was formerly known as groupby(), which has been
- removed.
-
-$this->db->distinct()
-=====================
-
-Adds the "DISTINCT" keyword to a query
-
-::
-
- $this->db->distinct();
- $this->db->get('table'); // Produces: SELECT DISTINCT * FROM table
-
-
-$this->db->having()
-===================
-
-Permits you to write the HAVING portion of your query. There are 2
-possible syntaxes, 1 argument or 2::
-
- $this->db->having('user_id = 45'); // Produces: HAVING user_id = 45
- $this->db->having('user_id', 45); // Produces: HAVING user_id = 45
-
-You can also pass an array of multiple values as well::
-
- $this->db->having(array('title =' => 'My Title', 'id <' => $id));
- // Produces: HAVING title = 'My Title', id < 45
-
-
-If you are using a database that CodeIgniter escapes queries for, you
-can prevent escaping content by passing an optional third argument, and
-setting it to FALSE.
-
-::
-
- $this->db->having('user_id', 45); // Produces: HAVING `user_id` = 45 in some databases such as MySQL
- $this->db->having('user_id', 45, FALSE); // Produces: HAVING user_id = 45
-
-
-$this->db->or_having()
-======================
-
-Identical to having(), only separates multiple clauses with "OR".
-
-$this->db->order_by()
-=====================
-
-Lets you set an ORDER BY clause. The first parameter contains the name
-of the column you would like to order by. The second parameter lets you
-set the direction of the result. Options are asc or desc, or random.
-
-::
-
- $this->db->order_by("title", "desc"); // Produces: ORDER BY title DESC
-
-You can also pass your own string in the first parameter::
-
- $this->db->order_by('title desc, name asc'); // Produces: ORDER BY title DESC, name ASC
-
-Or multiple function calls can be made if you need multiple fields.
-
-::
-
- $this->db->order_by("title", "desc");
- $this->db->order_by("name", "asc"); // Produces: ORDER BY title DESC, name ASC
-
-
-.. note:: order_by() was formerly known as orderby(), which has been
- removed.
-
-.. note:: random ordering is not currently supported in Oracle or MSSQL
- drivers. These will default to 'ASC'.
-
-$this->db->limit()
-==================
-
-Lets you limit the number of rows you would like returned by the query::
-
- $this->db->limit(10); // Produces: LIMIT 10
-
-The second parameter lets you set a result offset.
-
-::
-
- $this->db->limit(10, 20); // Produces: LIMIT 20, 10 (in MySQL. Other databases have slightly different syntax)
-
-$this->db->count_all_results()
-==============================
-
-Permits you to determine the number of rows in a particular Active
-Record query. Queries will accept Active Record restrictors such as
-where(), or_where(), like(), or_like(), etc. Example::
-
- echo $this->db->count_all_results('my_table'); // Produces an integer, like 25
- $this->db->like('title', 'match');
- $this->db->from('my_table');
- echo $this->db->count_all_results(); // Produces an integer, like 17
-
-$this->db->count_all()
-======================
-
-Permits you to determine the number of rows in a particular table.
-Submit the table name in the first parameter. Example::
-
- echo $this->db->count_all('my_table'); // Produces an integer, like 25
-
-**************
-Query grouping
-**************
-
-Query grouping allows you to create groups of WHERE clauses by enclosing them in parentheses. This will allow
-you to create queries with complex WHERE clauses. Nested groups are supported. Example:
-
- $this->db->select('*')->from('my_table')
- ->group_start()
- ->where('a', 'a')
- ->or_group_start()
- ->where('b', 'b')
- ->where('c', 'c')
- ->group_end()
- ->group_end()
- ->where('d', 'd')
- ->get();
-
- // Generates:
- // SELECT * FROM (`my_table`) WHERE ( `a` = 'a' OR ( `b` = 'b' AND `c` = 'c' ) ) AND `d` = 'd'
-
-.. note:: groups need to be balanced, make sure every group_start() is matched by a group_end().
-
-$this->db->group_start()
-========================
-
-Starts a new group by adding an opening parenthesis to the WHERE clause of the query.
-
-$this->db->or_group_start()
-===========================
-
-Starts a new group by adding an opening parenthesis to the WHERE clause of the query, prefixing it with 'OR'.
-
-$this->db->not_group_start()
-============================
-
-Starts a new group by adding an opening parenthesis to the WHERE clause of the query, prefixing it with 'NOT'.
-
-$this->db->or_not_group_start()
-===============================
-
-Starts a new group by adding an opening parenthesis to the WHERE clause of the query, prefixing it with 'OR NOT'.
-
-$this->db->group_end()
-======================
-
-Ends the current group by adding an closing parenthesis to the WHERE clause of the query.
-
-**************
-Inserting Data
-**************
-
-$this->db->insert()
-===================
-
-Generates an insert string based on the data you supply, and runs the
-query. You can either pass an **array** or an **object** to the
-function. Here is an example using an array::
-
- $data = array(
- 'title' => 'My title',
- 'name' => 'My Name',
- 'date' => 'My date'
- );
-
- $this->db->insert('mytable', $data);
- // Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')
-
-The first parameter will contain the table name, the second is an
-associative array of values.
-
-Here is an example using an object::
-
- /*
- class Myclass {
- var $title = 'My Title';
- var $content = 'My Content';
- var $date = 'My Date';
- }
- */
-
- $object = new Myclass;
- $this->db->insert('mytable', $object);
- // Produces: INSERT INTO mytable (title, content, date) VALUES ('My Title', 'My Content', 'My Date')
-
-The first parameter will contain the table name, the second is an
-object.
-
-.. note:: All values are escaped automatically producing safer queries.
-
-$this->db->get_compiled_insert()
-================================
-Compiles the insertion query just like `$this->db->insert()`_ but does not
-*run* the query. This method simply returns the SQL query as a string.
-
-Example::
-
- $data = array(
- 'title' => 'My title',
- 'name' => 'My Name',
- 'date' => 'My date'
- );
-
- $sql = $this->db->set($data)->get_compiled_insert('mytable');
- echo $sql;
-
- // Produces string: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')
-
-The second parameter enables you to set whether or not the active record query
-will be reset (by default it will be--just like `$this->db->insert()`_)::
-
- echo $this->db->set('title', 'My Title')->get_compiled_insert('mytable', FALSE);
-
- // Produces string: INSERT INTO mytable (title) VALUES ('My Title')
-
- echo $this->db->set('content', 'My Content')->get_compiled_insert();
-
- // Produces string: INSERT INTO mytable (title, content) VALUES ('My Title', 'My Content')
-
-The key thing to notice in the above example is that the second query did not
-utlize `$this->db->from()`_ nor did it pass a table name into the first
-parameter. The reason this worked is because the query has not been executed
-using `$this->db->insert()`_ which resets values or reset directly using
-`$this->db->reset_query()`_.
-
-$this->db->insert_batch()
-=========================
-
-Generates an insert string based on the data you supply, and runs the
-query. You can either pass an **array** or an **object** to the
-function. Here is an example using an array::
-
- $data = array(
- array(
- 'title' => 'My title',
- 'name' => 'My Name',
- 'date' => 'My date'
- ),
- array(
- 'title' => 'Another title',
- 'name' => 'Another Name',
- 'date' => 'Another date'
- )
- );
-
- $this->db->insert_batch('mytable', $data);
- // Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date')
-
-The first parameter will contain the table name, the second is an
-associative array of values.
-
-.. note:: All values are escaped automatically producing safer queries.
-
-$this->db->set()
-================
-
-This function enables you to set values for inserts or updates.
-
-**It can be used instead of passing a data array directly to the insert
-or update functions:**
-
-::
-
- $this->db->set('name', $name);
- $this->db->insert('mytable'); // Produces: INSERT INTO mytable (name) VALUES ('{$name}')
-
-If you use multiple function called they will be assembled properly
-based on whether you are doing an insert or an update::
-
- $this->db->set('name', $name);
- $this->db->set('title', $title);
- $this->db->set('status', $status);
- $this->db->insert('mytable');
-
-**set()** will also accept an optional third parameter ($escape), that
-will prevent data from being escaped if set to FALSE. To illustrate the
-difference, here is set() used both with and without the escape
-parameter.
-
-::
-
- $this->db->set('field', 'field+1', FALSE);
- $this->db->insert('mytable'); // gives INSERT INTO mytable (field) VALUES (field+1)
- $this->db->set('field', 'field+1');
- $this->db->insert('mytable'); // gives INSERT INTO mytable (field) VALUES ('field+1')
-
-
-You can also pass an associative array to this function::
-
- $array = array(
- 'name' => $name,
- 'title' => $title,
- 'status' => $status
- );
-
- $this->db->set($array);
- $this->db->insert('mytable');
-
-Or an object::
-
- /*
- class Myclass {
- var $title = 'My Title';
- var $content = 'My Content';
- var $date = 'My Date';
- }
- */
-
- $object = new Myclass;
- $this->db->set($object);
- $this->db->insert('mytable');
-
-
-*************
-Updating Data
-*************
-
-$this->db->update()
-===================
-
-Generates an update string and runs the query based on the data you
-supply. You can pass an **array** or an **object** to the function. Here
-is an example using an array::
-
- $data = array(
- 'title' => $title,
- 'name' => $name,
- 'date' => $date
- );
-
- $this->db->where('id', $id);
- $this->db->update('mytable', $data);
- // Produces: // UPDATE mytable // SET title = '{$title}', name = '{$name}', date = '{$date}' // WHERE id = $id
-
-Or you can supply an object::
-
- /*
- class Myclass {
- var $title = 'My Title';
- var $content = 'My Content';
- var $date = 'My Date';
- }
- */
-
- $object = new Myclass;
- $this->db->where('id', $id);
- $this->db->update('mytable', $object);
- // Produces: // UPDATE mytable // SET title = '{$title}', name = '{$name}', date = '{$date}' // WHERE id = $id
-
-.. note:: All values are escaped automatically producing safer queries.
-
-You'll notice the use of the $this->db->where() function, enabling you
-to set the WHERE clause. You can optionally pass this information
-directly into the update function as a string::
-
- $this->db->update('mytable', $data, "id = 4");
-
-Or as an array::
-
- $this->db->update('mytable', $data, array('id' => $id));
-
-You may also use the $this->db->set() function described above when
-performing updates.
-
-$this->db->update_batch()
-=========================
-
-Generates an update string based on the data you supply, and runs the query.
-You can either pass an **array** or an **object** to the function.
-Here is an example using an array::
-
- $data = array(
- array(
- 'title' => 'My title' ,
- 'name' => 'My Name 2' ,
- 'date' => 'My date 2'
- ),
- array(
- 'title' => 'Another title' ,
- 'name' => 'Another Name 2' ,
- 'date' => 'Another date 2'
- )
- );
-
- $this->db->update_batch('mytable', $data, 'title');
-
- // Produces:
- // UPDATE `mytable` SET `name` = CASE
- // WHEN `title` = 'My title' THEN 'My Name 2'
- // WHEN `title` = 'Another title' THEN 'Another Name 2'
- // ELSE `name` END,
- // `date` = CASE
- // WHEN `title` = 'My title' THEN 'My date 2'
- // WHEN `title` = 'Another title' THEN 'Another date 2'
- // ELSE `date` END
- // WHERE `title` IN ('My title','Another title')
-
-The first parameter will contain the table name, the second is an associative
-array of values, the third parameter is the where key.
-
-.. note:: All values are escaped automatically producing safer queries.
-
-$this->db->get_compiled_update()
-================================
-
-This works exactly the same way as ``$this->db->get_compiled_insert()`` except
-that it produces an UPDATE SQL string instead of an INSERT SQL string.
-
-For more information view documentation for `$this->db->get_compiled_insert()`_.
-
-
-*************
-Deleting Data
-*************
-
-$this->db->delete()
-===================
-
-Generates a delete SQL string and runs the query.
-
-::
-
- $this->db->delete('mytable', array('id' => $id)); // Produces: // DELETE FROM mytable // WHERE id = $id
-
-The first parameter is the table name, the second is the where clause.
-You can also use the where() or or_where() functions instead of passing
-the data to the second parameter of the function::
-
- $this->db->where('id', $id);
- $this->db->delete('mytable');
-
- // Produces:
- // DELETE FROM mytable
- // WHERE id = $id
-
-
-An array of table names can be passed into delete() if you would like to
-delete data from more than 1 table.
-
-::
-
- $tables = array('table1', 'table2', 'table3');
- $this->db->where('id', '5');
- $this->db->delete($tables);
-
-
-If you want to delete all data from a table, you can use the truncate()
-function, or empty_table().
-
-$this->db->empty_table()
-========================
-
-Generates a delete SQL string and runs the
-query.::
-
- $this->db->empty_table('mytable'); // Produces: DELETE FROM mytable
-
-
-$this->db->truncate()
-=====================
-
-Generates a truncate SQL string and runs the query.
-
-::
-
- $this->db->from('mytable');
- $this->db->truncate();
-
- // or
-
- $this->db->truncate('mytable');
-
- // Produce:
- // TRUNCATE mytable
-
-.. note:: If the TRUNCATE command isn't available, truncate() will
- execute as "DELETE FROM table".
-
-$this->db->get_compiled_delete()
-================================
-This works exactly the same way as ``$this->db->get_compiled_insert()`` except
-that it produces a DELETE SQL string instead of an INSERT SQL string.
-
-For more information view documentation for `$this->db->get_compiled_insert()`_.
-
-***************
-Method Chaining
-***************
-
-Method chaining allows you to simplify your syntax by connecting
-multiple functions. Consider this example::
-
- $query = $this->db->select('title')
- ->where('id', $id)
- ->limit(10, 20)
- ->get('mytable');
-
-.. _ar-caching:
-
-*********************
-Active Record Caching
-*********************
-
-While not "true" caching, Active Record enables you to save (or "cache")
-certain parts of your queries for reuse at a later point in your
-script's execution. Normally, when an Active Record call is completed,
-all stored information is reset for the next call. With caching, you can
-prevent this reset, and reuse information easily.
-
-Cached calls are cumulative. If you make 2 cached select() calls, and
-then 2 uncached select() calls, this will result in 4 select() calls.
-There are three Caching functions available:
-
-$this->db->start_cache()
-========================
-
-This function must be called to begin caching. All Active Record queries
-of the correct type (see below for supported queries) are stored for
-later use.
-
-$this->db->stop_cache()
-=======================
-
-This function can be called to stop caching.
-
-$this->db->flush_cache()
-========================
-
-This function deletes all items from the Active Record cache.
-
-Here's a usage example::
-
- $this->db->start_cache();
- $this->db->select('field1');
- $this->db->stop_cache();
- $this->db->get('tablename');
- //Generates: SELECT `field1` FROM (`tablename`)
-
- $this->db->select('field2');
- $this->db->get('tablename');
- //Generates: SELECT `field1`, `field2` FROM (`tablename`)
-
- $this->db->flush_cache();
- $this->db->select('field2');
- $this->db->get('tablename');
- //Generates: SELECT `field2` FROM (`tablename`)
-
-
-.. note:: The following statements can be cached: select, from, join,
- where, like, group_by, having, order_by, set
-
-
-$this->db->reset_query()
-========================
-
-Resetting Active Record allows you to start fresh with your query without
-executing it first using a method like $this->db->get() or $this->db->insert().
-Just like the methods that execute a query, this will *not* reset items you've
-cached using `Active Record Caching`_.
-
-This is useful in situations where you are using Active Record to generate SQL
-(ex. ``$this->db->get_compiled_select()``) but then choose to, for instance,
-run the query::
-
- // Note that the second parameter of the get_compiled_select method is FALSE
- $sql = $this->db->select(array('field1','field2'))
- ->where('field3',5)
- ->get_compiled_select('mytable', FALSE);
-
- // ...
- // Do something crazy with the SQL code... like add it to a cron script for
- // later execution or something...
- // ...
-
- $data = $this->db->get()->result_array();
-
- // Would execute and return an array of results of the following query:
- // SELECT field1, field1 from mytable where field3 = 5;
diff --git a/user_guide_src/source/database/configuration.rst b/user_guide_src/source/database/configuration.rst
index 040e7e33f..953bbfbcb 100644
--- a/user_guide_src/source/database/configuration.rst
+++ b/user_guide_src/source/database/configuration.rst
@@ -106,18 +106,18 @@ Note: The name "test" is arbitrary. It can be anything you want. By
default we've used the word "default" for the primary connection, but it
too can be renamed to something more relevant to your project.
-Active Record
+Query Builder
-------------
-The :doc:`Active Record Class ` is globally enabled or
-disabled by setting the $active_record variable in the database
+The :doc:`Query Builder Class ` is globally enabled or
+disabled by setting the $query_builder variable in the database
configuration file to TRUE/FALSE (boolean). If you are not using the
-active record class, setting it to FALSE will utilize fewer resources
+query builder class, setting it to FALSE will utilize fewer resources
when the database classes are initialized.
::
- $active_record = TRUE;
+ $query_builder = TRUE;
.. note:: that some CodeIgniter classes such as Sessions require Active
Records be enabled to access certain functionality.
@@ -134,7 +134,7 @@ Explanation of Values:
**database** The name of the database you want to connect to.
**dbdriver** The database type. ie: mysql, postgres, odbc, etc. Must be specified in lower case.
**dbprefix** An optional table prefix which will added to the table name when running :doc:
- `Active Record ` queries. This permits multiple CodeIgniter installations
+ `Query Builder ` queries. This permits multiple CodeIgniter installations
to share one database.
**pconnect** TRUE/FALSE (boolean) - Whether to use a persistent connection.
**db_debug** TRUE/FALSE (boolean) - Whether database errors should be displayed.
diff --git a/user_guide_src/source/database/connecting.rst b/user_guide_src/source/database/connecting.rst
index a834cc0f7..4db038e1e 100644
--- a/user_guide_src/source/database/connecting.rst
+++ b/user_guide_src/source/database/connecting.rst
@@ -36,7 +36,7 @@ Available Parameters
string.
#. TRUE/FALSE (boolean). Whether to return the connection ID (see
Connecting to Multiple Databases below).
-#. TRUE/FALSE (boolean). Whether to enable the Active Record class. Set
+#. TRUE/FALSE (boolean). Whether to enable the Query Builder class. Set
to TRUE by default.
Manually Connecting to a Database
diff --git a/user_guide_src/source/database/examples.rst b/user_guide_src/source/database/examples.rst
index d1cd48837..8b3cc4701 100644
--- a/user_guide_src/source/database/examples.rst
+++ b/user_guide_src/source/database/examples.rst
@@ -104,10 +104,10 @@ Standard Insert
$this->db->query($sql);
echo $this->db->affected_rows();
-Active Record Query
+Query Builder Query
===================
-The :doc:`Active Record Pattern ` gives you a simplified
+The :doc:`Query Builder Pattern ` gives you a simplified
means of retrieving data::
$query = $this->db->get('table_name');
@@ -118,10 +118,10 @@ means of retrieving data::
}
The above get() function retrieves all the results from the supplied
-table. The :doc:`Active Record ` class contains a full
+table. The :doc:`Query Builder ` class contains a full
compliment of functions for working with data.
-Active Record Insert
+Query Builder Insert
====================
::
diff --git a/user_guide_src/source/database/index.rst b/user_guide_src/source/database/index.rst
index ab12b7cb7..7ccb8fb00 100644
--- a/user_guide_src/source/database/index.rst
+++ b/user_guide_src/source/database/index.rst
@@ -3,7 +3,7 @@ The Database Class
##################
CodeIgniter comes with a full-featured and very fast abstracted database
-class that supports both traditional structures and Active Record
+class that supports both traditional structures and Query Builder
patterns. The database functions offer clear, simple syntax.
.. toctree::
@@ -15,7 +15,7 @@ patterns. The database functions offer clear, simple syntax.
Running Queries
Generating Query Results
Query Helper Functions
- Active Record Class
+ Query Builder Class
Transactions
Table MetaData
Field MetaData
diff --git a/user_guide_src/source/database/queries.rst b/user_guide_src/source/database/queries.rst
index 971d5d61d..2ba3d3f4a 100644
--- a/user_guide_src/source/database/queries.rst
+++ b/user_guide_src/source/database/queries.rst
@@ -50,7 +50,7 @@ Protecting identifiers
**********************
In many databases it is advisable to protect table and field names - for
-example with backticks in MySQL. **Active Record queries are
+example with backticks in MySQL. **Query Builder queries are
automatically protected**, however if you need to manually protect an
identifier you can use::
diff --git a/user_guide_src/source/database/query_builder.rst b/user_guide_src/source/database/query_builder.rst
new file mode 100644
index 000000000..f55d8e2f7
--- /dev/null
+++ b/user_guide_src/source/database/query_builder.rst
@@ -0,0 +1,1008 @@
+###################
+Query Builder Class
+###################
+
+CodeIgniter gives you access to a Query Builder class. This pattern
+allows information to be retrieved, inserted, and updated in your
+database with minimal scripting. In some cases only one or two lines
+of code are necessary to perform a database action.
+CodeIgniter does not require that each database table be its own class
+file. It instead provides a more simplified interface.
+
+Beyond simplicity, a major benefit to using the Query Builder features
+is that it allows you to create database independent applications, since
+the query syntax is generated by each database adapter. It also allows
+for safer queries, since the values are escaped automatically by the
+system.
+
+.. note:: If you intend to write your own queries you can disable this
+ class in your database config file, allowing the core database library
+ and adapter to utilize fewer resources.
+
+.. contents:: Page Contents
+
+**************
+Selecting Data
+**************
+
+The following functions allow you to build SQL **SELECT** statements.
+
+$this->db->get()
+================
+
+Runs the selection query and returns the result. Can be used by itself
+to retrieve all records from a table::
+
+ $query = $this->db->get('mytable'); // Produces: SELECT * FROM mytable
+
+The second and third parameters enable you to set a limit and offset
+clause::
+
+ $query = $this->db->get('mytable', 10, 20);
+ // Produces: SELECT * FROM mytable LIMIT 20, 10 (in MySQL. Other databases have slightly different syntax)
+
+You'll notice that the above function is assigned to a variable named
+$query, which can be used to show the results::
+
+ $query = $this->db->get('mytable');
+
+ foreach ($query->result() as $row)
+ {
+ echo $row->title;
+ }
+
+Please visit the :doc:`result functions ` page for a full
+discussion regarding result generation.
+
+$this->db->get_compiled_select()
+================================
+
+Compiles the selection query just like `$this->db->get()`_ but does not *run*
+the query. This method simply returns the SQL query as a string.
+
+Example::
+
+ $sql = $this->db->get_compiled_select('mytable');
+ echo $sql;
+
+ // Produces string: SELECT * FROM mytable
+
+The second parameter enables you to set whether or not the query builder query
+will be reset (by default it will be—just like `$this->db->get()`)::
+
+ echo $this->db->limit(10,20)->get_compiled_select('mytable', FALSE);
+ // Produces string: SELECT * FROM mytable LIMIT 20, 10
+ // (in MySQL. Other databases have slightly different syntax)
+
+ echo $this->db->select('title, content, date')->get_compiled_select();
+
+ // Produces string: SELECT title, content, date FROM mytable
+
+The key thing to notice in the above example is that the second query did not
+utilize `$this->db->from()`_ and did not pass a table name into the first
+parameter. The reason for this outcome is because the query has not been
+executed using `$this->db->get()`_ which resets values or reset directly
+using `$this->db->reset_query()`_.
+
+
+$this->db->get_where()
+======================
+
+Identical to the above function except that it permits you to add a
+"where" clause in the second parameter, instead of using the db->where()
+function::
+
+ $query = $this->db->get_where('mytable', array('id' => $id), $limit, $offset);
+
+Please read the about the where function below for more information.
+
+.. note:: get_where() was formerly known as getwhere(), which has been removed
+
+$this->db->select()
+===================
+
+Permits you to write the SELECT portion of your query::
+
+ $this->db->select('title, content, date');
+ $query = $this->db->get('mytable'); // Produces: SELECT title, content, date FROM mytable
+
+
+.. note:: If you are selecting all (\*) from a table you do not need to
+ use this function. When omitted, CodeIgniter assumes you wish to SELECT *
+
+$this->db->select() accepts an optional second parameter. If you set it
+to FALSE, CodeIgniter will not try to protect your field or table names
+with backticks. This is useful if you need a compound select statement.
+
+::
+
+ $this->db->select('(SELECT SUM(payments.amount) FROM payments WHERE payments.invoice_id=4') AS amount_paid', FALSE);
+ $query = $this->db->get('mytable');
+
+
+$this->db->select_max()
+=======================
+
+Writes a "SELECT MAX(field)" portion for your query. You can optionally
+include a second parameter to rename the resulting field.
+
+::
+
+ $this->db->select_max('age');
+ $query = $this->db->get('members'); // Produces: SELECT MAX(age) as age FROM members
+
+ $this->db->select_max('age', 'member_age');
+ $query = $this->db->get('members'); // Produces: SELECT MAX(age) as member_age FROM members
+
+
+$this->db->select_min()
+=======================
+
+Writes a "SELECT MIN(field)" portion for your query. As with
+select_max(), You can optionally include a second parameter to rename
+the resulting field.
+
+::
+
+ $this->db->select_min('age');
+ $query = $this->db->get('members'); // Produces: SELECT MIN(age) as age FROM members
+
+
+$this->db->select_avg()
+=======================
+
+Writes a "SELECT AVG(field)" portion for your query. As with
+select_max(), You can optionally include a second parameter to rename
+the resulting field.
+
+::
+
+ $this->db->select_avg('age');
+ $query = $this->db->get('members'); // Produces: SELECT AVG(age) as age FROM members
+
+
+$this->db->select_sum()
+=======================
+
+Writes a "SELECT SUM(field)" portion for your query. As with
+select_max(), You can optionally include a second parameter to rename
+the resulting field.
+
+::
+
+ $this->db->select_sum('age');
+ $query = $this->db->get('members'); // Produces: SELECT SUM(age) as age FROM members
+
+
+$this->db->from()
+=================
+
+Permits you to write the FROM portion of your query::
+
+ $this->db->select('title, content, date');
+ $this->db->from('mytable');
+ $query = $this->db->get(); // Produces: SELECT title, content, date FROM mytable
+
+.. note:: As shown earlier, the FROM portion of your query can be specified
+ in the $this->db->get() function, so use whichever method you prefer.
+
+$this->db->join()
+=================
+
+Permits you to write the JOIN portion of your query::
+
+ $this->db->select('*');
+ $this->db->from('blogs');
+ $this->db->join('comments', 'comments.id = blogs.id');
+ $query = $this->db->get();
+
+ // Produces:
+ // SELECT * FROM blogs JOIN comments ON comments.id = blogs.id
+
+Multiple function calls can be made if you need several joins in one
+query.
+
+If you need a specific type of JOIN you can specify it via the third
+parameter of the function. Options are: left, right, outer, inner, left
+outer, and right outer.
+
+::
+
+ $this->db->join('comments', 'comments.id = blogs.id', 'left');
+ // Produces: LEFT JOIN comments ON comments.id = blogs.id
+
+$this->db->where()
+==================
+
+This function enables you to set **WHERE** clauses using one of four
+methods:
+
+.. note:: All values passed to this function are escaped automatically,
+ producing safer queries.
+
+#. **Simple key/value method:**
+
+ ::
+
+ $this->db->where('name', $name); // Produces: WHERE name = 'Joe'
+
+ Notice that the equal sign is added for you.
+
+ If you use multiple function calls they will be chained together with
+ AND between them:
+
+ ::
+
+ $this->db->where('name', $name);
+ $this->db->where('title', $title);
+ $this->db->where('status', $status);
+ // WHERE name = 'Joe' AND title = 'boss' AND status = 'active'
+
+#. **Custom key/value method:**
+ You can include an operator in the first parameter in order to
+ control the comparison:
+
+ ::
+
+ $this->db->where('name !=', $name);
+ $this->db->where('id <', $id); // Produces: WHERE name != 'Joe' AND id < 45
+
+#. **Associative array method:**
+
+ ::
+
+ $array = array('name' => $name, 'title' => $title, 'status' => $status);
+ $this->db->where($array);
+ // Produces: WHERE name = 'Joe' AND title = 'boss' AND status = 'active'
+
+ You can include your own operators using this method as well:
+
+ ::
+
+ $array = array('name !=' => $name, 'id <' => $id, 'date >' => $date);
+ $this->db->where($array);
+
+#. **Custom string:**
+ You can write your own clauses manually::
+
+ $where = "name='Joe' AND status='boss' OR status='active'";
+ $this->db->where($where);
+
+
+$this->db->where() accepts an optional third parameter. If you set it to
+FALSE, CodeIgniter will not try to protect your field or table names
+with backticks.
+
+::
+
+ $this->db->where('MATCH (field) AGAINST ("value")', NULL, FALSE);
+
+
+$this->db->or_where()
+=====================
+
+This function is identical to the one above, except that multiple
+instances are joined by OR::
+
+ $this->db->where('name !=', $name);
+ $this->db->or_where('id >', $id); // Produces: WHERE name != 'Joe' OR id > 50
+
+.. note:: or_where() was formerly known as orwhere(), which has been
+ removed.
+
+$this->db->where_in()
+=====================
+
+Generates a WHERE field IN ('item', 'item') SQL query joined with AND if
+appropriate
+
+::
+
+ $names = array('Frank', 'Todd', 'James');
+ $this->db->where_in('username', $names);
+ // Produces: WHERE username IN ('Frank', 'Todd', 'James')
+
+
+$this->db->or_where_in()
+========================
+
+Generates a WHERE field IN ('item', 'item') SQL query joined with OR if
+appropriate
+
+::
+
+ $names = array('Frank', 'Todd', 'James');
+ $this->db->or_where_in('username', $names);
+ // Produces: OR username IN ('Frank', 'Todd', 'James')
+
+
+$this->db->where_not_in()
+=========================
+
+Generates a WHERE field NOT IN ('item', 'item') SQL query joined with
+AND if appropriate
+
+::
+
+ $names = array('Frank', 'Todd', 'James');
+ $this->db->where_not_in('username', $names);
+ // Produces: WHERE username NOT IN ('Frank', 'Todd', 'James')
+
+
+$this->db->or_where_not_in()
+============================
+
+Generates a WHERE field NOT IN ('item', 'item') SQL query joined with OR
+if appropriate
+
+::
+
+ $names = array('Frank', 'Todd', 'James');
+ $this->db->or_where_not_in('username', $names);
+ // Produces: OR username NOT IN ('Frank', 'Todd', 'James')
+
+
+$this->db->like()
+=================
+
+This function enables you to generate **LIKE** clauses, useful for doing
+searches.
+
+.. note:: All values passed to this function are escaped automatically.
+
+#. **Simple key/value method:**
+
+ ::
+
+ $this->db->like('title', 'match'); // Produces: WHERE title LIKE '%match%'
+
+ If you use multiple function calls they will be chained together with
+ AND between them::
+
+ $this->db->like('title', 'match');
+ $this->db->like('body', 'match');
+ // WHERE title LIKE '%match%' AND body LIKE '%match%
+
+ If you want to control where the wildcard (%) is placed, you can use
+ an optional third argument. Your options are 'before', 'after' and
+ 'both' (which is the default).
+
+ ::
+
+ $this->db->like('title', 'match', 'before'); // Produces: WHERE title LIKE '%match'
+ $this->db->like('title', 'match', 'after'); // Produces: WHERE title LIKE 'match%'
+ $this->db->like('title', 'match', 'both'); // Produces: WHERE title LIKE '%match%'
+
+#. **Associative array method:**
+
+ ::
+
+ $array = array('title' => $match, 'page1' => $match, 'page2' => $match);
+ $this->db->like($array);
+ // WHERE title LIKE '%match%' AND page1 LIKE '%match%' AND page2 LIKE '%match%'
+
+
+$this->db->or_like()
+====================
+
+This function is identical to the one above, except that multiple
+instances are joined by OR::
+
+ $this->db->like('title', 'match'); $this->db->or_like('body', $match);
+ // WHERE title LIKE '%match%' OR body LIKE '%match%'
+
+.. note:: or_like() was formerly known as orlike(), which has been removed.
+
+$this->db->not_like()
+=====================
+
+This function is identical to **like()**, except that it generates NOT
+LIKE statements::
+
+ $this->db->not_like('title', 'match'); // WHERE title NOT LIKE '%match%
+
+$this->db->or_not_like()
+========================
+
+This function is identical to **not_like()**, except that multiple
+instances are joined by OR::
+
+ $this->db->like('title', 'match');
+ $this->db->or_not_like('body', 'match');
+ // WHERE title LIKE '%match% OR body NOT LIKE '%match%'
+
+$this->db->group_by()
+=====================
+
+Permits you to write the GROUP BY portion of your query::
+
+ $this->db->group_by("title"); // Produces: GROUP BY title
+
+You can also pass an array of multiple values as well::
+
+ $this->db->group_by(array("title", "date")); // Produces: GROUP BY title, date
+
+.. note:: group_by() was formerly known as groupby(), which has been
+ removed.
+
+$this->db->distinct()
+=====================
+
+Adds the "DISTINCT" keyword to a query
+
+::
+
+ $this->db->distinct();
+ $this->db->get('table'); // Produces: SELECT DISTINCT * FROM table
+
+
+$this->db->having()
+===================
+
+Permits you to write the HAVING portion of your query. There are 2
+possible syntaxes, 1 argument or 2::
+
+ $this->db->having('user_id = 45'); // Produces: HAVING user_id = 45
+ $this->db->having('user_id', 45); // Produces: HAVING user_id = 45
+
+You can also pass an array of multiple values as well::
+
+ $this->db->having(array('title =' => 'My Title', 'id <' => $id));
+ // Produces: HAVING title = 'My Title', id < 45
+
+
+If you are using a database that CodeIgniter escapes queries for, you
+can prevent escaping content by passing an optional third argument, and
+setting it to FALSE.
+
+::
+
+ $this->db->having('user_id', 45); // Produces: HAVING `user_id` = 45 in some databases such as MySQL
+ $this->db->having('user_id', 45, FALSE); // Produces: HAVING user_id = 45
+
+
+$this->db->or_having()
+======================
+
+Identical to having(), only separates multiple clauses with "OR".
+
+$this->db->order_by()
+=====================
+
+Lets you set an ORDER BY clause. The first parameter contains the name
+of the column you would like to order by. The second parameter lets you
+set the direction of the result. Options are asc or desc, or random.
+
+::
+
+ $this->db->order_by("title", "desc"); // Produces: ORDER BY title DESC
+
+You can also pass your own string in the first parameter::
+
+ $this->db->order_by('title desc, name asc'); // Produces: ORDER BY title DESC, name ASC
+
+Or multiple function calls can be made if you need multiple fields.
+
+::
+
+ $this->db->order_by("title", "desc");
+ $this->db->order_by("name", "asc"); // Produces: ORDER BY title DESC, name ASC
+
+
+.. note:: order_by() was formerly known as orderby(), which has been
+ removed.
+
+.. note:: random ordering is not currently supported in Oracle or MSSQL
+ drivers. These will default to 'ASC'.
+
+$this->db->limit()
+==================
+
+Lets you limit the number of rows you would like returned by the query::
+
+ $this->db->limit(10); // Produces: LIMIT 10
+
+The second parameter lets you set a result offset.
+
+::
+
+ $this->db->limit(10, 20); // Produces: LIMIT 20, 10 (in MySQL. Other databases have slightly different syntax)
+
+$this->db->count_all_results()
+==============================
+
+Permits you to determine the number of rows in a particular Active
+Record query. Queries will accept Query Builder restrictors such as
+where(), or_where(), like(), or_like(), etc. Example::
+
+ echo $this->db->count_all_results('my_table'); // Produces an integer, like 25
+ $this->db->like('title', 'match');
+ $this->db->from('my_table');
+ echo $this->db->count_all_results(); // Produces an integer, like 17
+
+$this->db->count_all()
+======================
+
+Permits you to determine the number of rows in a particular table.
+Submit the table name in the first parameter. Example::
+
+ echo $this->db->count_all('my_table'); // Produces an integer, like 25
+
+**************
+Query grouping
+**************
+
+Query grouping allows you to create groups of WHERE clauses by enclosing them in parentheses. This will allow
+you to create queries with complex WHERE clauses. Nested groups are supported. Example:
+
+ $this->db->select('*')->from('my_table')
+ ->group_start()
+ ->where('a', 'a')
+ ->or_group_start()
+ ->where('b', 'b')
+ ->where('c', 'c')
+ ->group_end()
+ ->group_end()
+ ->where('d', 'd')
+ ->get();
+
+ // Generates:
+ // SELECT * FROM (`my_table`) WHERE ( `a` = 'a' OR ( `b` = 'b' AND `c` = 'c' ) ) AND `d` = 'd'
+
+.. note:: groups need to be balanced, make sure every group_start() is matched by a group_end().
+
+$this->db->group_start()
+========================
+
+Starts a new group by adding an opening parenthesis to the WHERE clause of the query.
+
+$this->db->or_group_start()
+===========================
+
+Starts a new group by adding an opening parenthesis to the WHERE clause of the query, prefixing it with 'OR'.
+
+$this->db->not_group_start()
+============================
+
+Starts a new group by adding an opening parenthesis to the WHERE clause of the query, prefixing it with 'NOT'.
+
+$this->db->or_not_group_start()
+===============================
+
+Starts a new group by adding an opening parenthesis to the WHERE clause of the query, prefixing it with 'OR NOT'.
+
+$this->db->group_end()
+======================
+
+Ends the current group by adding an closing parenthesis to the WHERE clause of the query.
+
+**************
+Inserting Data
+**************
+
+$this->db->insert()
+===================
+
+Generates an insert string based on the data you supply, and runs the
+query. You can either pass an **array** or an **object** to the
+function. Here is an example using an array::
+
+ $data = array(
+ 'title' => 'My title',
+ 'name' => 'My Name',
+ 'date' => 'My date'
+ );
+
+ $this->db->insert('mytable', $data);
+ // Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')
+
+The first parameter will contain the table name, the second is an
+associative array of values.
+
+Here is an example using an object::
+
+ /*
+ class Myclass {
+ var $title = 'My Title';
+ var $content = 'My Content';
+ var $date = 'My Date';
+ }
+ */
+
+ $object = new Myclass;
+ $this->db->insert('mytable', $object);
+ // Produces: INSERT INTO mytable (title, content, date) VALUES ('My Title', 'My Content', 'My Date')
+
+The first parameter will contain the table name, the second is an
+object.
+
+.. note:: All values are escaped automatically producing safer queries.
+
+$this->db->get_compiled_insert()
+================================
+Compiles the insertion query just like `$this->db->insert()`_ but does not
+*run* the query. This method simply returns the SQL query as a string.
+
+Example::
+
+ $data = array(
+ 'title' => 'My title',
+ 'name' => 'My Name',
+ 'date' => 'My date'
+ );
+
+ $sql = $this->db->set($data)->get_compiled_insert('mytable');
+ echo $sql;
+
+ // Produces string: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')
+
+The second parameter enables you to set whether or not the query builder query
+will be reset (by default it will be--just like `$this->db->insert()`_)::
+
+ echo $this->db->set('title', 'My Title')->get_compiled_insert('mytable', FALSE);
+
+ // Produces string: INSERT INTO mytable (title) VALUES ('My Title')
+
+ echo $this->db->set('content', 'My Content')->get_compiled_insert();
+
+ // Produces string: INSERT INTO mytable (title, content) VALUES ('My Title', 'My Content')
+
+The key thing to notice in the above example is that the second query did not
+utlize `$this->db->from()`_ nor did it pass a table name into the first
+parameter. The reason this worked is because the query has not been executed
+using `$this->db->insert()`_ which resets values or reset directly using
+`$this->db->reset_query()`_.
+
+$this->db->insert_batch()
+=========================
+
+Generates an insert string based on the data you supply, and runs the
+query. You can either pass an **array** or an **object** to the
+function. Here is an example using an array::
+
+ $data = array(
+ array(
+ 'title' => 'My title',
+ 'name' => 'My Name',
+ 'date' => 'My date'
+ ),
+ array(
+ 'title' => 'Another title',
+ 'name' => 'Another Name',
+ 'date' => 'Another date'
+ )
+ );
+
+ $this->db->insert_batch('mytable', $data);
+ // Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date')
+
+The first parameter will contain the table name, the second is an
+associative array of values.
+
+.. note:: All values are escaped automatically producing safer queries.
+
+$this->db->set()
+================
+
+This function enables you to set values for inserts or updates.
+
+**It can be used instead of passing a data array directly to the insert
+or update functions:**
+
+::
+
+ $this->db->set('name', $name);
+ $this->db->insert('mytable'); // Produces: INSERT INTO mytable (name) VALUES ('{$name}')
+
+If you use multiple function called they will be assembled properly
+based on whether you are doing an insert or an update::
+
+ $this->db->set('name', $name);
+ $this->db->set('title', $title);
+ $this->db->set('status', $status);
+ $this->db->insert('mytable');
+
+**set()** will also accept an optional third parameter ($escape), that
+will prevent data from being escaped if set to FALSE. To illustrate the
+difference, here is set() used both with and without the escape
+parameter.
+
+::
+
+ $this->db->set('field', 'field+1', FALSE);
+ $this->db->insert('mytable'); // gives INSERT INTO mytable (field) VALUES (field+1)
+ $this->db->set('field', 'field+1');
+ $this->db->insert('mytable'); // gives INSERT INTO mytable (field) VALUES ('field+1')
+
+
+You can also pass an associative array to this function::
+
+ $array = array(
+ 'name' => $name,
+ 'title' => $title,
+ 'status' => $status
+ );
+
+ $this->db->set($array);
+ $this->db->insert('mytable');
+
+Or an object::
+
+ /*
+ class Myclass {
+ var $title = 'My Title';
+ var $content = 'My Content';
+ var $date = 'My Date';
+ }
+ */
+
+ $object = new Myclass;
+ $this->db->set($object);
+ $this->db->insert('mytable');
+
+
+*************
+Updating Data
+*************
+
+$this->db->update()
+===================
+
+Generates an update string and runs the query based on the data you
+supply. You can pass an **array** or an **object** to the function. Here
+is an example using an array::
+
+ $data = array(
+ 'title' => $title,
+ 'name' => $name,
+ 'date' => $date
+ );
+
+ $this->db->where('id', $id);
+ $this->db->update('mytable', $data);
+ // Produces: // UPDATE mytable // SET title = '{$title}', name = '{$name}', date = '{$date}' // WHERE id = $id
+
+Or you can supply an object::
+
+ /*
+ class Myclass {
+ var $title = 'My Title';
+ var $content = 'My Content';
+ var $date = 'My Date';
+ }
+ */
+
+ $object = new Myclass;
+ $this->db->where('id', $id);
+ $this->db->update('mytable', $object);
+ // Produces: // UPDATE mytable // SET title = '{$title}', name = '{$name}', date = '{$date}' // WHERE id = $id
+
+.. note:: All values are escaped automatically producing safer queries.
+
+You'll notice the use of the $this->db->where() function, enabling you
+to set the WHERE clause. You can optionally pass this information
+directly into the update function as a string::
+
+ $this->db->update('mytable', $data, "id = 4");
+
+Or as an array::
+
+ $this->db->update('mytable', $data, array('id' => $id));
+
+You may also use the $this->db->set() function described above when
+performing updates.
+
+$this->db->update_batch()
+=========================
+
+Generates an update string based on the data you supply, and runs the query.
+You can either pass an **array** or an **object** to the function.
+Here is an example using an array::
+
+ $data = array(
+ array(
+ 'title' => 'My title' ,
+ 'name' => 'My Name 2' ,
+ 'date' => 'My date 2'
+ ),
+ array(
+ 'title' => 'Another title' ,
+ 'name' => 'Another Name 2' ,
+ 'date' => 'Another date 2'
+ )
+ );
+
+ $this->db->update_batch('mytable', $data, 'title');
+
+ // Produces:
+ // UPDATE `mytable` SET `name` = CASE
+ // WHEN `title` = 'My title' THEN 'My Name 2'
+ // WHEN `title` = 'Another title' THEN 'Another Name 2'
+ // ELSE `name` END,
+ // `date` = CASE
+ // WHEN `title` = 'My title' THEN 'My date 2'
+ // WHEN `title` = 'Another title' THEN 'Another date 2'
+ // ELSE `date` END
+ // WHERE `title` IN ('My title','Another title')
+
+The first parameter will contain the table name, the second is an associative
+array of values, the third parameter is the where key.
+
+.. note:: All values are escaped automatically producing safer queries.
+
+$this->db->get_compiled_update()
+================================
+
+This works exactly the same way as ``$this->db->get_compiled_insert()`` except
+that it produces an UPDATE SQL string instead of an INSERT SQL string.
+
+For more information view documentation for `$this->db->get_compiled_insert()`_.
+
+
+*************
+Deleting Data
+*************
+
+$this->db->delete()
+===================
+
+Generates a delete SQL string and runs the query.
+
+::
+
+ $this->db->delete('mytable', array('id' => $id)); // Produces: // DELETE FROM mytable // WHERE id = $id
+
+The first parameter is the table name, the second is the where clause.
+You can also use the where() or or_where() functions instead of passing
+the data to the second parameter of the function::
+
+ $this->db->where('id', $id);
+ $this->db->delete('mytable');
+
+ // Produces:
+ // DELETE FROM mytable
+ // WHERE id = $id
+
+
+An array of table names can be passed into delete() if you would like to
+delete data from more than 1 table.
+
+::
+
+ $tables = array('table1', 'table2', 'table3');
+ $this->db->where('id', '5');
+ $this->db->delete($tables);
+
+
+If you want to delete all data from a table, you can use the truncate()
+function, or empty_table().
+
+$this->db->empty_table()
+========================
+
+Generates a delete SQL string and runs the
+query.::
+
+ $this->db->empty_table('mytable'); // Produces: DELETE FROM mytable
+
+
+$this->db->truncate()
+=====================
+
+Generates a truncate SQL string and runs the query.
+
+::
+
+ $this->db->from('mytable');
+ $this->db->truncate();
+
+ // or
+
+ $this->db->truncate('mytable');
+
+ // Produce:
+ // TRUNCATE mytable
+
+.. note:: If the TRUNCATE command isn't available, truncate() will
+ execute as "DELETE FROM table".
+
+$this->db->get_compiled_delete()
+================================
+This works exactly the same way as ``$this->db->get_compiled_insert()`` except
+that it produces a DELETE SQL string instead of an INSERT SQL string.
+
+For more information view documentation for `$this->db->get_compiled_insert()`_.
+
+***************
+Method Chaining
+***************
+
+Method chaining allows you to simplify your syntax by connecting
+multiple functions. Consider this example::
+
+ $query = $this->db->select('title')
+ ->where('id', $id)
+ ->limit(10, 20)
+ ->get('mytable');
+
+.. _ar-caching:
+
+*********************
+Query Builder Caching
+*********************
+
+While not "true" caching, Query Builder enables you to save (or "cache")
+certain parts of your queries for reuse at a later point in your
+script's execution. Normally, when an Query Builder call is completed,
+all stored information is reset for the next call. With caching, you can
+prevent this reset, and reuse information easily.
+
+Cached calls are cumulative. If you make 2 cached select() calls, and
+then 2 uncached select() calls, this will result in 4 select() calls.
+There are three Caching functions available:
+
+$this->db->start_cache()
+========================
+
+This function must be called to begin caching. All Query Builder queries
+of the correct type (see below for supported queries) are stored for
+later use.
+
+$this->db->stop_cache()
+=======================
+
+This function can be called to stop caching.
+
+$this->db->flush_cache()
+========================
+
+This function deletes all items from the Query Builder cache.
+
+Here's a usage example::
+
+ $this->db->start_cache();
+ $this->db->select('field1');
+ $this->db->stop_cache();
+ $this->db->get('tablename');
+ //Generates: SELECT `field1` FROM (`tablename`)
+
+ $this->db->select('field2');
+ $this->db->get('tablename');
+ //Generates: SELECT `field1`, `field2` FROM (`tablename`)
+
+ $this->db->flush_cache();
+ $this->db->select('field2');
+ $this->db->get('tablename');
+ //Generates: SELECT `field2` FROM (`tablename`)
+
+
+.. note:: The following statements can be cached: select, from, join,
+ where, like, group_by, having, order_by, set
+
+
+$this->db->reset_query()
+========================
+
+Resetting Query Builder allows you to start fresh with your query without
+executing it first using a method like $this->db->get() or $this->db->insert().
+Just like the methods that execute a query, this will *not* reset items you've
+cached using `Query Builder Caching`_.
+
+This is useful in situations where you are using Query Builder to generate SQL
+(ex. ``$this->db->get_compiled_select()``) but then choose to, for instance,
+run the query::
+
+ // Note that the second parameter of the get_compiled_select method is FALSE
+ $sql = $this->db->select(array('field1','field2'))
+ ->where('field3',5)
+ ->get_compiled_select('mytable', FALSE);
+
+ // ...
+ // Do something crazy with the SQL code... like add it to a cron script for
+ // later execution or something...
+ // ...
+
+ $data = $this->db->get()->result_array();
+
+ // Would execute and return an array of results of the following query:
+ // SELECT field1, field1 from mytable where field3 = 5;
diff --git a/user_guide_src/source/general/models.rst b/user_guide_src/source/general/models.rst
index b816f958a..0156b0460 100644
--- a/user_guide_src/source/general/models.rst
+++ b/user_guide_src/source/general/models.rst
@@ -55,7 +55,7 @@ model class might look like::
}
.. note:: The functions in the above example use the :doc:`Active
- Record <../database/active_record>` database functions.
+ Record <../database/query_builder>` database functions.
.. note:: For the sake of simplicity in this example we're using $_POST
directly. This is generally bad practice, and a more common approach
diff --git a/user_guide_src/source/helpers/directory_helper.rst b/user_guide_src/source/helpers/directory_helper.rst
index fd169886c..cf88732d3 100644
--- a/user_guide_src/source/helpers/directory_helper.rst
+++ b/user_guide_src/source/helpers/directory_helper.rst
@@ -59,7 +59,7 @@ be numerically indexed. Here is an example of a typical array::
[1] => config.html       Â
[database] => Array
( Â Â Â Â Â Â Â Â Â Â Â Â Â
- [0] => active_record.html             Â
+ [0] => query_builder.html             Â
[1] => binds.html             Â
[2] => configuration.html
[3] => connecting.html             Â
diff --git a/user_guide_src/source/overview/features.rst b/user_guide_src/source/overview/features.rst
index 44db08a94..8c27b1436 100644
--- a/user_guide_src/source/overview/features.rst
+++ b/user_guide_src/source/overview/features.rst
@@ -15,7 +15,7 @@ CodeIgniter's main features.
- Model-View-Controller Based System
- Extremely Light Weight
- Full Featured database classes with support for several platforms.
-- Active Record Database Support
+- Query Builder Database Support
- Form and Data Validation
- Security and XSS Filtering
- Session Management
diff --git a/user_guide_src/source/tutorial/create_news_items.rst b/user_guide_src/source/tutorial/create_news_items.rst
index 794b67eed..bfaf13537 100644
--- a/user_guide_src/source/tutorial/create_news_items.rst
+++ b/user_guide_src/source/tutorial/create_news_items.rst
@@ -94,7 +94,7 @@ Model
-----
The only thing that remains is writing a method that writes the data to
-the database. You'll use the Active Record class to insert the
+the database. You'll use the Query Builder class to insert the
information and use the input library to get the posted data. Open up
the model created earlier and add the following:
diff --git a/user_guide_src/source/tutorial/index.rst b/user_guide_src/source/tutorial/index.rst
index c959d04d2..b1ab331d1 100644
--- a/user_guide_src/source/tutorial/index.rst
+++ b/user_guide_src/source/tutorial/index.rst
@@ -16,7 +16,7 @@ This tutorial will primarily focus on:
- Model-View-Controller basics
- Routing basics
- Form validation
-- Performing basic database queries using "Active Record"
+- Performing basic database queries using "Query Builder"
The entire tutorial is split up over several pages, each explaining a
small part of the functionality of the CodeIgniter framework. You'll go
diff --git a/user_guide_src/source/tutorial/news_section.rst b/user_guide_src/source/tutorial/news_section.rst
index 38e4214ca..82b3e3b38 100644
--- a/user_guide_src/source/tutorial/news_section.rst
+++ b/user_guide_src/source/tutorial/news_section.rst
@@ -54,7 +54,7 @@ seed records.
Now that the database and a model have been set up, you'll need a method
to get all of our posts from our database. To do this, the database
abstraction layer that is included with CodeIgniter — `Active
-Record <../database/active_record.html>`_ — is used. This makes it
+Record <../database/query_builder.html>`_ — is used. This makes it
possible to write your 'queries' once and make them work on `all
supported database systems <../general/requirements.html>`_. Add the
following code to your model.
@@ -76,7 +76,7 @@ following code to your model.
With this code you can perform two different queries. You can get all
news records, or get a news item by its `slug <#>`_. You might have
noticed that the $slug variable wasn't sanitized before running the
-query; Active Record does this for you.
+query; Query Builder does this for you.
Display the news
----------------
--
cgit v1.2.3-24-g4f1b
From d48f30d1f28fb70d6e06bc4c9607993a991e4c42 Mon Sep 17 00:00:00 2001
From: Jamie Rumbelow
Date: Sun, 19 Feb 2012 12:39:03 +0000
Subject: Adding the change to the release notes
---
user_guide_src/source/changelog.rst | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index a4904fceb..5ad3c3cbc 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -42,7 +42,9 @@ Release Date: Not Released
- Database
- - Added new :doc:`Active Record ` methods that return
+ - Renamed the Active Record class to Query Builder to remove confusion with
+ the Active Record design pattern
+ - Added new :doc:`Query Builder ` methods that return
the SQL string of queries without executing them: get_compiled_select(),
get_compiled_insert(), get_compiled_update(), get_compiled_delete().
- Taking care of LIKE condition when used with MySQL UPDATE statement.
--
cgit v1.2.3-24-g4f1b
From ae123e0b3d749a13d8820d0a6b773ca25b0ed380 Mon Sep 17 00:00:00 2001
From: Jamie Rumbelow
Date: Tue, 21 Feb 2012 16:39:56 +0000
Subject: Fixing an error in #1061
---
system/database/DB_query_builder.php | 50 ++++++++++++++++++------------------
1 file changed, 25 insertions(+), 25 deletions(-)
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index b6ad0f3d8..fad879389 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -2103,8 +2103,8 @@ class CI_DB_query_builder extends CI_DB_driver {
foreach ($this->qb_cache_exists as $val)
{
- $qb_variable = 'ar_'.$val;
- $qb_cache_var = 'ar_cache_'.$val;
+ $qb_variable = 'qb_'.$val;
+ $qb_cache_var = 'qb_cache_'.$val;
if (count($this->$qb_cache_var) === 0)
{
@@ -2168,21 +2168,21 @@ class CI_DB_query_builder extends CI_DB_driver {
protected function _reset_select()
{
$this->_reset_run(array(
- 'ar_select' => array(),
- 'ar_from' => array(),
- 'ar_join' => array(),
- 'ar_where' => array(),
- 'ar_like' => array(),
- 'ar_groupby' => array(),
- 'ar_having' => array(),
- 'ar_orderby' => array(),
- 'ar_wherein' => array(),
- 'ar_aliased_tables' => array(),
- 'ar_no_escape' => array(),
- 'ar_distinct' => FALSE,
- 'ar_limit' => FALSE,
- 'ar_offset' => FALSE,
- 'ar_order' => FALSE
+ 'qb_select' => array(),
+ 'qb_from' => array(),
+ 'qb_join' => array(),
+ 'qb_where' => array(),
+ 'qb_like' => array(),
+ 'qb_groupby' => array(),
+ 'qb_having' => array(),
+ 'qb_orderby' => array(),
+ 'qb_wherein' => array(),
+ 'qb_aliased_tables' => array(),
+ 'qb_no_escape' => array(),
+ 'qb_distinct' => FALSE,
+ 'qb_limit' => FALSE,
+ 'qb_offset' => FALSE,
+ 'qb_order' => FALSE
)
);
}
@@ -2199,14 +2199,14 @@ class CI_DB_query_builder extends CI_DB_driver {
protected function _reset_write()
{
$this->_reset_run(array(
- 'ar_set' => array(),
- 'ar_from' => array(),
- 'ar_where' => array(),
- 'ar_like' => array(),
- 'ar_orderby' => array(),
- 'ar_keys' => array(),
- 'ar_limit' => FALSE,
- 'ar_order' => FALSE
+ 'qb_set' => array(),
+ 'qb_from' => array(),
+ 'qb_where' => array(),
+ 'qb_like' => array(),
+ 'qb_orderby' => array(),
+ 'qb_keys' => array(),
+ 'qb_limit' => FALSE,
+ 'qb_order' => FALSE
)
);
}
--
cgit v1.2.3-24-g4f1b
From ce383fa1a9702c1e04431a66c7a7e1fe5bc825cb Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Mon, 27 Feb 2012 23:28:48 +0200
Subject: Update the changelog
---
user_guide_src/source/changelog.rst | 1 +
1 file changed, 1 insertion(+)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index dc6b29516..8f7b3bc6c 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -108,6 +108,7 @@ Bug fixes for 3.0
- Fixed a possible bug in ``CI_Input::is_ajax_request()`` where some clients might not send the X-Requested-With HTTP header value exactly as 'XmlHttpRequest'.
- Fixed a bug (#1039) - MySQL's _backup() method failed due to a table name not being escaped.
- Fixed a bug (#1070) - CI_DB_driver::initialize() didn't set a character set if a database is not selected.
+- Fixed a bug (#611) - SQLSRV's _error_*() methods used to issue warnings when there's no actual error.
Version 2.1.0
=============
--
cgit v1.2.3-24-g4f1b
From 78b24bfdaaea0f208802f36730c032e7ec98eb56 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Wed, 29 Feb 2012 16:43:57 +0200
Subject: Fix ODBC num_rows() for subdrivers that return -1
---
system/database/drivers/odbc/odbc_result.php | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php
index 320b9327c..e7cbc7af5 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -43,7 +43,18 @@ class CI_DB_odbc_result extends CI_DB_result {
*/
public function num_rows()
{
- return @odbc_num_rows($this->result_id);
+ if ($this->num_rows > 0)
+ {
+ return $this->num_rows;
+ }
+
+ // Work-around for ODBC subdrivers that don't support num_rows()
+ if (($this->num_rows = @odbc_num_rows($this->result_id)) === -1)
+ {
+ return $this->num_rows = count($this->result_array());
+ }
+
+ return $this->num_rows;
}
/**
--
cgit v1.2.3-24-g4f1b
From 005700340b444f3cfee8df98f5bf30b32c4a5085 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Wed, 29 Feb 2012 16:48:28 +0200
Subject: Add a changelog entry for num_rows()
---
user_guide_src/source/changelog.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 890097039..369a89c62 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -114,7 +114,7 @@ Bug fixes for 3.0
- Fixed a bug (#1070) - CI_DB_driver::initialize() didn't set a character set if a database is not selected.
- Fixed a bug (#177) - CI_Form_validation::set_value() didn't set the default value if POST data is NULL.
- Fixed a bug (#81) - ODBC's list_field() and field_data() methods skipped the first column due to odbc_field_*() functions' index starting at 1 instead of 0.
-
+- Fixed a bug (#129) - ODBC's num_rows() returned -1 in some cases, due to not all subdrivers supporting the odbc_num_rows() function.
Version 2.1.1
=============
--
cgit v1.2.3-24-g4f1b
From a0c2785f91bc70fb4a0a02f1c9c28cb99c975457 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Fri, 2 Mar 2012 13:49:28 +0200
Subject: Change SQLite _execute() to use is_write_type()
---
system/database/drivers/sqlite/sqlite_driver.php | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index 20b05af0d..8116cfb18 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -154,13 +154,9 @@ class CI_DB_sqlite_driver extends CI_DB {
protected function _execute($sql)
{
$sql = $this->_prep_query($sql);
-
- if ( ! preg_match('/^(SELECT|EXPLAIN).+$/i', ltrim($sql)))
- {
- return @sqlite_exec($this->conn_id, $sql);
- }
-
- return @sqlite_query($this->conn_id, $sql);
+ return $this->is_write_type($sql)
+ ? @sqlite_exec($this->conn_id, $sql)
+ : @sqlite_query($this->conn_id, $sql);
}
// --------------------------------------------------------------------
--
cgit v1.2.3-24-g4f1b
From a6a1496b27c87718106645b6f1438023a18ad40c Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Sat, 3 Mar 2012 03:57:26 +0200
Subject: Remove pg_set_client_encoding() from db_connect(), db_pconnect()
---
system/database/drivers/postgre/postgre_driver.php | 16 ++--------------
1 file changed, 2 insertions(+), 14 deletions(-)
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index ce5dc96c3..d8b43695c 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -126,13 +126,7 @@ class CI_DB_postgre_driver extends CI_DB {
*/
public function db_connect()
{
- $ret = @pg_connect($this->dsn);
- if (is_resource($ret) && $this->char_set != '')
- {
- pg_set_client_encoding($ret, $this->char_set);
- }
-
- return $ret;
+ return @pg_connect($this->dsn);
}
// --------------------------------------------------------------------
@@ -144,13 +138,7 @@ class CI_DB_postgre_driver extends CI_DB {
*/
public function db_pconnect()
{
- $ret = @pg_pconnect($this->dsn);
- if (is_resource($ret) && $this->char_set != '')
- {
- pg_set_client_encoding($ret, $this->char_set);
- }
-
- return $ret;
+ return @pg_pconnect($this->dsn);
}
// --------------------------------------------------------------------
--
cgit v1.2.3-24-g4f1b
From 17c1bedbab426ce383138f2bc720a1134afbe475 Mon Sep 17 00:00:00 2001
From: Jamie Rumbelow
Date: Tue, 6 Mar 2012 21:30:38 +0000
Subject: Updating a couple more references to the AR class in documentation
[#1061]
---
system/database/DB_driver.php | 2 +-
system/database/DB_query_builder.php | 40 ++++++++++++++++++------------------
2 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index e379755ed..6a20c001a 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -1351,7 +1351,7 @@ class CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Dummy method that allows Active Record class to be disabled
+ * Dummy method that allows Query Builder class to be disabled
*
* This function is used extensively by every db driver.
*
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index ab59462b1..8cbe7d9f9 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -1058,7 +1058,7 @@ class CI_DB_query_builder extends CI_DB_driver {
*
* @access public
* @param string the table name to select from (optional)
- * @param boolean TRUE: resets AR values; FALSE: leave AR vaules alone
+ * @param boolean TRUE: resets QB values; FALSE: leave QB vaules alone
* @return string
*/
public function get_compiled_select($table = '', $reset = TRUE)
@@ -1286,7 +1286,7 @@ class CI_DB_query_builder extends CI_DB_driver {
*
* @access public
* @param string the table to insert into
- * @param boolean TRUE: reset AR values; FALSE: leave AR values alone
+ * @param boolean TRUE: reset QB values; FALSE: leave QB values alone
* @return string
*/
public function get_compiled_insert($table = '', $reset = TRUE)
@@ -1431,7 +1431,7 @@ class CI_DB_query_builder extends CI_DB_driver {
*
* @access public
* @param string the table to update
- * @param boolean TRUE: reset AR values; FALSE: leave AR values alone
+ * @param boolean TRUE: reset QB values; FALSE: leave QB values alone
* @return string
*/
public function get_compiled_update($table = '', $reset = TRUE)
@@ -1705,7 +1705,7 @@ class CI_DB_query_builder extends CI_DB_driver {
*
* @access public
* @param string the table to delete from
- * @param boolean TRUE: reset AR values; FALSE: leave AR values alone
+ * @param boolean TRUE: reset QB values; FALSE: leave QB values alone
* @return string
*/
public function get_compiled_delete($table = '', $reset = TRUE)
@@ -2039,7 +2039,7 @@ class CI_DB_query_builder extends CI_DB_driver {
/**
* Start Cache
*
- * Starts AR caching
+ * Starts QB caching
*
* @return void
*/
@@ -2053,7 +2053,7 @@ class CI_DB_query_builder extends CI_DB_driver {
/**
* Stop Cache
*
- * Stops AR caching
+ * Stops QB caching
*
* @return void
*/
@@ -2067,7 +2067,7 @@ class CI_DB_query_builder extends CI_DB_driver {
/**
* Flush Cache
*
- * Empties the AR cache
+ * Empties the QB cache
*
* @access public
* @return void
@@ -2075,17 +2075,17 @@ class CI_DB_query_builder extends CI_DB_driver {
public function flush_cache()
{
$this->_reset_run(array(
- 'ar_cache_select' => array(),
- 'ar_cache_from' => array(),
- 'ar_cache_join' => array(),
- 'ar_cache_where' => array(),
- 'ar_cache_like' => array(),
- 'ar_cache_groupby' => array(),
- 'ar_cache_having' => array(),
- 'ar_cache_orderby' => array(),
- 'ar_cache_set' => array(),
- 'ar_cache_exists' => array(),
- 'ar_cache_no_escape' => array()
+ 'qb_cache_select' => array(),
+ 'qb_cache_from' => array(),
+ 'qb_cache_join' => array(),
+ 'qb_cache_where' => array(),
+ 'qb_cache_like' => array(),
+ 'qb_cache_groupby' => array(),
+ 'qb_cache_having' => array(),
+ 'qb_cache_orderby' => array(),
+ 'qb_cache_set' => array(),
+ 'qb_cache_exists' => array(),
+ 'qb_cache_no_escape' => array()
));
}
@@ -2094,7 +2094,7 @@ class CI_DB_query_builder extends CI_DB_driver {
/**
* Merge Cache
*
- * When called, this function merges any cached AR arrays with
+ * When called, this function merges any cached QB arrays with
* locally called ones.
*
* @return void
@@ -2134,7 +2134,7 @@ class CI_DB_query_builder extends CI_DB_driver {
/**
* Reset Query Builder values.
*
- * Publicly-visible method to reset the AR values.
+ * Publicly-visible method to reset the QB values.
*
* @return void
*/
--
cgit v1.2.3-24-g4f1b
From 0c09299363bb27d6a115ee1377167a6bc71e09a7 Mon Sep 17 00:00:00 2001
From: Jamie Rumbelow
Date: Tue, 6 Mar 2012 22:05:16 +0000
Subject: accounting for the rename of protect_identifiers
---
system/database/DB_driver.php | 4 ++--
system/database/DB_query_builder.php | 44 ++++++++++++++++++------------------
2 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 6a20c001a..986916964 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -74,7 +74,7 @@ class CI_DB_driver {
public $cache_autodel = FALSE;
public $CACHE; // The cache class object
- protected $_protect_identifiers = TRUE;
+ protected $protect_identifiers = TRUE;
protected $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped
public function __construct($params)
@@ -1208,7 +1208,7 @@ class CI_DB_driver {
{
if ( ! is_bool($protect_identifiers))
{
- $protect_identifiers = $this->_protect_identifiers;
+ $protect_identifiers = $this->protect_identifiers;
}
if (is_array($item))
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index 8cbe7d9f9..7691d5eba 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -212,7 +212,7 @@ class CI_DB_query_builder extends CI_DB_driver {
$alias = $this->_create_alias_from_table(trim($select));
}
- $sql = $this->_protect_identifiers($type.'('.trim($select).')').' AS '.$this->_protect_identifiers(trim($alias));
+ $sql = $this->protect_identifiers($type.'('.trim($select).')').' AS '.$this->protect_identifiers(trim($alias));
$this->qb_select[] = $sql;
if ($this->qb_caching === TRUE)
@@ -280,7 +280,7 @@ class CI_DB_query_builder extends CI_DB_driver {
$v = trim($v);
$this->_track_aliases($v);
- $v = $this->qb_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
+ $v = $this->qb_from[] = $this->protect_identifiers($v, TRUE, NULL, FALSE);
if ($this->qb_caching === TRUE)
{
@@ -294,10 +294,10 @@ class CI_DB_query_builder extends CI_DB_driver {
$val = trim($val);
// Extract any aliases that might exist. We use this information
- // in the _protect_identifiers to know whether to add a table prefix
+ // in the protect_identifiers to know whether to add a table prefix
$this->_track_aliases($val);
- $this->qb_from[] = $val = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
+ $this->qb_from[] = $val = $this->protect_identifiers($val, TRUE, NULL, FALSE);
if ($this->qb_caching === TRUE)
{
@@ -339,7 +339,7 @@ class CI_DB_query_builder extends CI_DB_driver {
}
// Extract any aliases that might exist. We use this information
- // in the _protect_identifiers to know whether to add a table prefix
+ // in the protect_identifiers to know whether to add a table prefix
$this->_track_aliases($table);
// Strip apart the condition and protect the identifiers
@@ -349,7 +349,7 @@ class CI_DB_query_builder extends CI_DB_driver {
}
// Assemble the JOIN statement
- $this->qb_join[] = $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
+ $this->qb_join[] = $join = $type.'JOIN '.$this->protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
if ($this->qb_caching === TRUE)
{
@@ -418,7 +418,7 @@ class CI_DB_query_builder extends CI_DB_driver {
// If the escape value was not set will will base it on the global setting
if ( ! is_bool($escape))
{
- $escape = $this->_protect_identifiers;
+ $escape = $this->protect_identifiers;
}
foreach ($key as $k => $v)
@@ -564,7 +564,7 @@ class CI_DB_query_builder extends CI_DB_driver {
}
$prefix = (count($this->qb_where) === 0) ? '' : $type;
- $this->qb_where[] = $where_in = $prefix.$this->_protect_identifiers($key).$not.' IN ('.implode(', ', $this->qb_wherein).') ';
+ $this->qb_where[] = $where_in = $prefix.$this->protect_identifiers($key).$not.' IN ('.implode(', ', $this->qb_wherein).') ';
if ($this->qb_caching === TRUE)
{
@@ -668,7 +668,7 @@ class CI_DB_query_builder extends CI_DB_driver {
foreach ($field as $k => $v)
{
- $k = $this->_protect_identifiers($k);
+ $k = $this->protect_identifiers($k);
$prefix = (count($this->qb_like) === 0) ? '' : $type;
$v = $this->escape_like_str($v);
@@ -829,7 +829,7 @@ class CI_DB_query_builder extends CI_DB_driver {
if ($val != '')
{
- $this->qb_groupby[] = $val = $this->_protect_identifiers($val);
+ $this->qb_groupby[] = $val = $this->protect_identifiers($val);
if ($this->qb_caching === TRUE)
{
@@ -1038,11 +1038,11 @@ class CI_DB_query_builder extends CI_DB_driver {
{
if ($escape === FALSE)
{
- $this->qb_set[$this->_protect_identifiers($k)] = $v;
+ $this->qb_set[$this->protect_identifiers($k)] = $v;
}
else
{
- $this->qb_set[$this->_protect_identifiers($k, FALSE, TRUE)] = $this->escape($v);
+ $this->qb_set[$this->protect_identifiers($k, FALSE, TRUE)] = $this->escape($v);
}
}
@@ -1213,7 +1213,7 @@ class CI_DB_query_builder extends CI_DB_driver {
// Batch this baby
for ($i = 0, $total = count($this->qb_set); $i < $total; $i += 100)
{
- $this->query($this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->qb_keys, array_slice($this->qb_set, $i, 100)));
+ $this->query($this->_insert_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), $this->qb_keys, array_slice($this->qb_set, $i, 100)));
}
$this->_reset_write();
@@ -1271,7 +1271,7 @@ class CI_DB_query_builder extends CI_DB_driver {
foreach ($keys as $k)
{
- $this->qb_keys[] = $this->_protect_identifiers($k);
+ $this->qb_keys[] = $this->protect_identifiers($k);
}
return $this;
@@ -1297,7 +1297,7 @@ class CI_DB_query_builder extends CI_DB_driver {
}
$sql = $this->_insert(
- $this->_protect_identifiers(
+ $this->protect_identifiers(
$this->qb_from[0], TRUE, NULL, FALSE
),
array_keys($this->qb_set),
@@ -1337,7 +1337,7 @@ class CI_DB_query_builder extends CI_DB_driver {
}
$sql = $this->_insert(
- $this->_protect_identifiers(
+ $this->protect_identifiers(
$this->qb_from[0], TRUE, NULL, FALSE
),
array_keys($this->qb_set),
@@ -1416,7 +1416,7 @@ class CI_DB_query_builder extends CI_DB_driver {
$table = $this->qb_from[0];
}
- $sql = $this->_replace($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->qb_set), array_values($this->qb_set));
+ $sql = $this->_replace($this->protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->qb_set), array_values($this->qb_set));
$this->_reset_write();
return $this->query($sql);
@@ -1444,7 +1444,7 @@ class CI_DB_query_builder extends CI_DB_driver {
return FALSE;
}
- $sql = $this->_update($this->_protect_identifiers($this->qb_from[0], TRUE, NULL, FALSE), $this->qb_set, $this->qb_where, $this->qb_orderby, $this->qb_limit);
+ $sql = $this->_update($this->protect_identifiers($this->qb_from[0], TRUE, NULL, FALSE), $this->qb_set, $this->qb_where, $this->qb_orderby, $this->qb_limit);
if ($reset === TRUE)
{
@@ -1491,7 +1491,7 @@ class CI_DB_query_builder extends CI_DB_driver {
$this->limit($limit);
}
- $sql = $this->_update($this->_protect_identifiers($this->qb_from[0], TRUE, NULL, FALSE), $this->qb_set, $this->qb_where, $this->qb_orderby, $this->qb_limit, $this->qb_like);
+ $sql = $this->_update($this->protect_identifiers($this->qb_from[0], TRUE, NULL, FALSE), $this->qb_set, $this->qb_where, $this->qb_orderby, $this->qb_limit, $this->qb_like);
$this->_reset_write();
return $this->query($sql);
@@ -1577,7 +1577,7 @@ class CI_DB_query_builder extends CI_DB_driver {
// Batch this baby
for ($i = 0, $total = count($this->qb_set); $i < $total; $i += 100)
{
- $this->query($this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->qb_set, $i, 100), $this->_protect_identifiers($index), $this->qb_where));
+ $this->query($this->_update_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->qb_set, $i, 100), $this->protect_identifiers($index), $this->qb_where));
}
$this->_reset_write();
@@ -1898,7 +1898,7 @@ class CI_DB_query_builder extends CI_DB_driver {
foreach ($this->qb_select as $key => $val)
{
$no_escape = isset($this->qb_no_escape[$key]) ? $this->qb_no_escape[$key] : NULL;
- $this->qb_select[$key] = $this->_protect_identifiers($val, FALSE, $no_escape);
+ $this->qb_select[$key] = $this->protect_identifiers($val, FALSE, $no_escape);
}
$sql .= implode(', ', $this->qb_select);
@@ -2121,7 +2121,7 @@ class CI_DB_query_builder extends CI_DB_driver {
// If we are "protecting identifiers" we need to examine the "from"
// portion of the query to determine if there are any aliases
- if ($this->_protect_identifiers === TRUE AND count($this->qb_cache_from) > 0)
+ if ($this->protect_identifiers === TRUE AND count($this->qb_cache_from) > 0)
{
$this->_track_aliases($this->qb_from);
}
--
cgit v1.2.3-24-g4f1b
From 0cd8c798de4b99b5ad41bacdeef77a4a7b815a03 Mon Sep 17 00:00:00 2001
From: Jamie Rumbelow
Date: Thu, 8 Mar 2012 12:52:24 +0000
Subject: Just the method, not the property
---
system/database/DB_driver.php | 2 +-
system/database/DB_query_builder.php | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 986916964..9e1c605ec 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -1208,7 +1208,7 @@ class CI_DB_driver {
{
if ( ! is_bool($protect_identifiers))
{
- $protect_identifiers = $this->protect_identifiers;
+ $protect_identifiers = $this->_protect_identifiers;
}
if (is_array($item))
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index 7691d5eba..8979dc15b 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -418,7 +418,7 @@ class CI_DB_query_builder extends CI_DB_driver {
// If the escape value was not set will will base it on the global setting
if ( ! is_bool($escape))
{
- $escape = $this->protect_identifiers;
+ $escape = $this->_protect_identifiers;
}
foreach ($key as $k => $v)
@@ -2121,7 +2121,7 @@ class CI_DB_query_builder extends CI_DB_driver {
// If we are "protecting identifiers" we need to examine the "from"
// portion of the query to determine if there are any aliases
- if ($this->protect_identifiers === TRUE AND count($this->qb_cache_from) > 0)
+ if ($this->_protect_identifiers === TRUE AND count($this->qb_cache_from) > 0)
{
$this->_track_aliases($this->qb_from);
}
--
cgit v1.2.3-24-g4f1b
From bcee50ff3247dee71d83bf273e52bc10096cd48c Mon Sep 17 00:00:00 2001
From: Jamie Rumbelow
Date: Thu, 8 Mar 2012 13:00:15 +0000
Subject: missed one :bomb:
---
system/database/DB_driver.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 9e1c605ec..6a20c001a 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -74,7 +74,7 @@ class CI_DB_driver {
public $cache_autodel = FALSE;
public $CACHE; // The cache class object
- protected $protect_identifiers = TRUE;
+ protected $_protect_identifiers = TRUE;
protected $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped
public function __construct($params)
--
cgit v1.2.3-24-g4f1b
From 5e18e891a14400a96f9b4af36925457b79b62005 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Fri, 9 Mar 2012 14:25:00 +0200
Subject: Fix an eventual issue with LIKE escaping
---
system/database/drivers/odbc/odbc_driver.php | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index 01515221b..47d3a340b 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -232,14 +232,13 @@ class CI_DB_odbc_driver extends CI_DB {
return $str;
}
- // ODBC doesn't require escaping
$str = remove_invisible_characters($str);
// escape LIKE condition wildcards
if ($like === TRUE)
{
- return str_replace(array('%', '_', $this->_like_escape_chr),
- array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
+ return str_replace(array($this->_like_escape_chr, '%', '_'),
+ array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
$str);
}
--
cgit v1.2.3-24-g4f1b
From 75124a53cf54f2a8c094756f9189be9159957f28 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Tue, 13 Mar 2012 12:47:58 +0200
Subject: Some comments altered
---
system/helpers/smiley_helper.php | 5 -----
system/helpers/string_helper.php | 20 +++++++-------------
system/helpers/text_helper.php | 29 ++++++++++-------------------
3 files changed, 17 insertions(+), 37 deletions(-)
diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php
index 83fb863df..bc592f74f 100644
--- a/system/helpers/smiley_helper.php
+++ b/system/helpers/smiley_helper.php
@@ -43,7 +43,6 @@
* Returns the javascript required for the smiley insertion. Optionally takes
* an array of aliases to loosely couple the smiley array to the view.
*
- * @access public
* @param mixed alias name or array of alias->field_id pairs
* @param string field_id if alias name was passed in
* @return array
@@ -125,7 +124,6 @@ EOF;
* Returns an array of image tag links that can be clicked to be inserted
* into a form field.
*
- * @access public
* @param string the URL to the folder containing the smiley images
* @return array
*/
@@ -173,7 +171,6 @@ if ( ! function_exists('get_clickable_smileys'))
*
* Takes a string as input and swaps any contained smileys for the actual image
*
- * @access public
* @param string the text to be parsed
* @param string the URL to the folder containing the smiley images
* @return string
@@ -206,7 +203,6 @@ if ( ! function_exists('parse_smileys'))
*
* Fetches the config/smiley.php file
*
- * @access private
* @return mixed
*/
if ( ! function_exists('_get_smiley_array'))
@@ -235,7 +231,6 @@ if ( ! function_exists('_get_smiley_array'))
*
* DEPRECATED as of version 1.7.2, use smiley_js instead
*
- * @access public
* @param string form name
* @param string field name
* @return string
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php
index 6573b9a5d..a53d1b88e 100644
--- a/system/helpers/string_helper.php
+++ b/system/helpers/string_helper.php
@@ -48,7 +48,6 @@
*
* this/that/theother
*
- * @access public
* @param string
* @return string
*/
@@ -67,7 +66,6 @@ if ( ! function_exists('trim_slashes'))
*
* Removes slashes contained in a string or in an array
*
- * @access public
* @param mixed string or array
* @return mixed string or array
*/
@@ -96,7 +94,6 @@ if ( ! function_exists('strip_slashes'))
*
* Removes single and double quotes from a string
*
- * @access public
* @param string
* @return string
*/
@@ -115,7 +112,6 @@ if ( ! function_exists('strip_quotes'))
*
* Converts single and double quotes to entities
*
- * @access public
* @param string
* @return string
*/
@@ -141,7 +137,6 @@ if ( ! function_exists('quotes_to_entities'))
*
* http://www.some-site.com/index.php
*
- * @access public
* @param string
* @return string
*/
@@ -166,7 +161,6 @@ if ( ! function_exists('reduce_double_slashes'))
*
* Fred, Bill, Joe, Jimmy
*
- * @access public
* @param string
* @param string the character you wish to reduce
* @param bool TRUE/FALSE - whether to trim the character from the beginning/end
@@ -188,7 +182,6 @@ if ( ! function_exists('reduce_multiples'))
*
* Useful for generating passwords or hashes.
*
- * @access public
* @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1
* @param int number of characters
* @return string
@@ -219,7 +212,7 @@ if ( ! function_exists('random_string'))
$pool = '123456789';
break;
}
- return substr(str_shuffle(str_repeat($pool, ceil($len/strlen($pool)))),0,$len);
+ return substr(str_shuffle(str_repeat($pool, ceil($len / strlen($pool)))), 0, $len);
case 'unique':
case 'md5': return md5(uniqid(mt_rand()));
case 'encrypt':
@@ -241,10 +234,13 @@ if ( ! function_exists('random_string'))
* @param string $first Which number should be used for the first dupe increment
* @return string
*/
-function increment_string($str, $separator = '_', $first = 1)
+if ( ! function_exists('increment_string'))
{
- preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match);
- return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first;
+ function increment_string($str, $separator = '_', $first = 1)
+ {
+ preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match);
+ return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first;
+ }
}
// ------------------------------------------------------------------------
@@ -254,7 +250,6 @@ function increment_string($str, $separator = '_', $first = 1)
*
* Allows strings to be alternated. See docs...
*
- * @access public
* @param string (as many parameters as needed)
* @return string
*/
@@ -279,7 +274,6 @@ if ( ! function_exists('alternator'))
/**
* Repeater function
*
- * @access public
* @param string
* @param int number of repeats
* @return string
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index bddb112b2..9a56159d9 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -42,9 +42,8 @@
*
* Limits a string to X number of words.
*
- * @access public
* @param string
- * @param integer
+ * @param int
* @param string the end character. Usually an ellipsis
* @return string
*/
@@ -76,9 +75,8 @@ if ( ! function_exists('word_limiter'))
* Limits the string based on the character count. Preserves complete words
* so the character count may not be exactly as specified.
*
- * @access public
* @param string
- * @param integer
+ * @param int
* @param string the end character. Usually an ellipsis
* @return string
*/
@@ -119,7 +117,6 @@ if ( ! function_exists('character_limiter'))
*
* Converts High ascii text and MS Word special characters to character entities
*
- * @access public
* @param string
* @return string
*/
@@ -182,7 +179,6 @@ if ( ! function_exists('ascii_to_entities'))
*
* Converts character entities back to ASCII
*
- * @access public
* @param string
* @param bool
* @return string
@@ -238,7 +234,6 @@ if ( ! function_exists('entities_to_ascii'))
* matched words will be converted to #### or to the replacement
* word you've submitted.
*
- * @access public
* @param string the text string
* @param string the array of censoered words
* @param string the optional replacement value
@@ -284,7 +279,6 @@ if ( ! function_exists('word_censor'))
*
* Colorizes code strings
*
- * @access public
* @param string the text string
* @return string
*/
@@ -334,7 +328,6 @@ if ( ! function_exists('highlight_code'))
*
* Highlights a phrase within a text string
*
- * @access public
* @param string the text string
* @param string the phrase you'd like to highlight
* @param string the openging tag to precede the phrase with
@@ -364,7 +357,6 @@ if ( ! function_exists('highlight_phrase'))
/**
* Convert Accented Foreign Characters to ASCII
*
- * @access public
* @param string the text string
* @return string
*/
@@ -404,9 +396,8 @@ if ( ! function_exists('convert_accented_characters'))
* Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor
* will URLs.
*
- * @access public
* @param string the text string
- * @param integer the number of characters to wrap at
+ * @param int the number of characters to wrap at
* @return string
*/
if ( ! function_exists('word_wrap'))
@@ -467,8 +458,8 @@ if ( ! function_exists('word_wrap'))
}
// Trim the word down
- $temp .= substr($line, 0, $charlim-1);
- $line = substr($line, $charlim-1);
+ $temp .= substr($line, 0, $charlim - 1);
+ $line = substr($line, $charlim - 1);
}
// If $temp contains data it means we had to split up an over-length
@@ -504,11 +495,11 @@ if ( ! function_exists('word_wrap'))
*
* This function will strip tags from a string, split it at its max_length and ellipsize
*
- * @param string string to ellipsize
- * @param integer max length of string
- * @param mixed int (1|0) or float, .5, .2, etc for position to split
- * @param string ellipsis ; Default '...'
- * @return string ellipsized string
+ * @param string string to ellipsize
+ * @param int max length of string
+ * @param mixed int (1|0) or float, .5, .2, etc for position to split
+ * @param string ellipsis ; Default '...'
+ * @return string ellipsized string
*/
if ( ! function_exists('ellipsize'))
{
--
cgit v1.2.3-24-g4f1b
From fead0550fcef5681a8a031433232c03b9cc1218d Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Tue, 20 Mar 2012 15:23:06 +0200
Subject: Remove EOF newlines
---
system/database/drivers/cubrid/cubrid_forge.php | 2 +-
system/database/drivers/cubrid/cubrid_result.php | 2 +-
system/database/drivers/cubrid/cubrid_utility.php | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php
index f0d9804cc..6b8097370 100644
--- a/system/database/drivers/cubrid/cubrid_forge.php
+++ b/system/database/drivers/cubrid/cubrid_forge.php
@@ -254,4 +254,4 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
}
/* End of file cubrid_forge.php */
-/* Location: ./system/database/drivers/cubrid/cubrid_forge.php */
+/* Location: ./system/database/drivers/cubrid/cubrid_forge.php */
\ No newline at end of file
diff --git a/system/database/drivers/cubrid/cubrid_result.php b/system/database/drivers/cubrid/cubrid_result.php
index b954345c3..f891968d7 100644
--- a/system/database/drivers/cubrid/cubrid_result.php
+++ b/system/database/drivers/cubrid/cubrid_result.php
@@ -167,4 +167,4 @@ class CI_DB_cubrid_result extends CI_DB_result {
}
/* End of file cubrid_result.php */
-/* Location: ./system/database/drivers/cubrid/cubrid_result.php */
+/* Location: ./system/database/drivers/cubrid/cubrid_result.php */
\ No newline at end of file
diff --git a/system/database/drivers/cubrid/cubrid_utility.php b/system/database/drivers/cubrid/cubrid_utility.php
index c7c02a518..ead54f094 100644
--- a/system/database/drivers/cubrid/cubrid_utility.php
+++ b/system/database/drivers/cubrid/cubrid_utility.php
@@ -99,4 +99,4 @@ class CI_DB_cubrid_utility extends CI_DB_utility {
}
/* End of file cubrid_utility.php */
-/* Location: ./system/database/drivers/cubrid/cubrid_utility.php */
+/* Location: ./system/database/drivers/cubrid/cubrid_utility.php */
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 135efb258559114bccd43a5f486efc3d14797fda Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Tue, 20 Mar 2012 15:30:56 +0200
Subject: Remove EOF newlines
---
system/database/drivers/postgre/postgre_driver.php | 2 +-
system/database/drivers/postgre/postgre_forge.php | 2 +-
system/database/drivers/postgre/postgre_result.php | 2 +-
system/database/drivers/postgre/postgre_utility.php | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index ab561add4..9680b3d96 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -686,4 +686,4 @@ class CI_DB_postgre_driver extends CI_DB {
}
/* End of file postgre_driver.php */
-/* Location: ./system/database/drivers/postgre/postgre_driver.php */
+/* Location: ./system/database/drivers/postgre/postgre_driver.php */
\ No newline at end of file
diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php
index c98116ab6..ab9c95b89 100644
--- a/system/database/drivers/postgre/postgre_forge.php
+++ b/system/database/drivers/postgre/postgre_forge.php
@@ -273,4 +273,4 @@ class CI_DB_postgre_forge extends CI_DB_forge {
}
/* End of file postgre_forge.php */
-/* Location: ./system/database/drivers/postgre/postgre_forge.php */
+/* Location: ./system/database/drivers/postgre/postgre_forge.php */
\ No newline at end of file
diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php
index 20c575fd8..394b8b6fd 100644
--- a/system/database/drivers/postgre/postgre_result.php
+++ b/system/database/drivers/postgre/postgre_result.php
@@ -166,4 +166,4 @@ class CI_DB_postgre_result extends CI_DB_result {
}
/* End of file postgre_result.php */
-/* Location: ./system/database/drivers/postgre/postgre_result.php */
+/* Location: ./system/database/drivers/postgre/postgre_result.php */
\ No newline at end of file
diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php
index d2c0079c6..cf29201ff 100644
--- a/system/database/drivers/postgre/postgre_utility.php
+++ b/system/database/drivers/postgre/postgre_utility.php
@@ -86,4 +86,4 @@ class CI_DB_postgre_utility extends CI_DB_utility {
}
/* End of file postgre_utility.php */
-/* Location: ./system/database/drivers/postgre/postgre_utility.php */
+/* Location: ./system/database/drivers/postgre/postgre_utility.php */
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 19aee036c7b9ebc8919dd4d076dfd60fd50bd26f Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Tue, 20 Mar 2012 15:31:42 +0200
Subject: Remove EOF newlines
---
system/database/drivers/odbc/odbc_driver.php | 2 +-
system/database/drivers/odbc/odbc_forge.php | 2 +-
system/database/drivers/odbc/odbc_result.php | 2 +-
system/database/drivers/odbc/odbc_utility.php | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index d0ad5a832..a7da487b8 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -549,4 +549,4 @@ class CI_DB_odbc_driver extends CI_DB {
}
/* End of file odbc_driver.php */
-/* Location: ./system/database/drivers/odbc/odbc_driver.php */
+/* Location: ./system/database/drivers/odbc/odbc_driver.php */
\ No newline at end of file
diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php
index 162cef48c..26ff9a0fb 100644
--- a/system/database/drivers/odbc/odbc_forge.php
+++ b/system/database/drivers/odbc/odbc_forge.php
@@ -206,4 +206,4 @@ class CI_DB_odbc_forge extends CI_DB_forge {
}
/* End of file odbc_forge.php */
-/* Location: ./system/database/drivers/odbc/odbc_forge.php */
+/* Location: ./system/database/drivers/odbc/odbc_forge.php */
\ No newline at end of file
diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php
index 04a7463a4..36473fc7e 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -313,4 +313,4 @@ class CI_DB_odbc_result extends CI_DB_result {
}
/* End of file odbc_result.php */
-/* Location: ./system/database/drivers/odbc/odbc_result.php */
+/* Location: ./system/database/drivers/odbc/odbc_result.php */
\ No newline at end of file
diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php
index eab636122..f57ebdc9a 100644
--- a/system/database/drivers/odbc/odbc_utility.php
+++ b/system/database/drivers/odbc/odbc_utility.php
@@ -94,4 +94,4 @@ class CI_DB_odbc_utility extends CI_DB_utility {
}
/* End of file odbc_utility.php */
-/* Location: ./system/database/drivers/odbc/odbc_utility.php */
+/* Location: ./system/database/drivers/odbc/odbc_utility.php */
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From e79a3b134bb5268106d550934808dd9e404ca515 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Tue, 20 Mar 2012 15:41:22 +0200
Subject: Remove EOF newlines
---
system/helpers/smiley_helper.php | 2 +-
system/helpers/string_helper.php | 2 +-
system/helpers/text_helper.php | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php
index bc592f74f..638100e9c 100644
--- a/system/helpers/smiley_helper.php
+++ b/system/helpers/smiley_helper.php
@@ -251,4 +251,4 @@ EOF;
}
/* End of file smiley_helper.php */
-/* Location: ./system/helpers/smiley_helper.php */
+/* Location: ./system/helpers/smiley_helper.php */
\ No newline at end of file
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php
index a53d1b88e..e570d5d01 100644
--- a/system/helpers/string_helper.php
+++ b/system/helpers/string_helper.php
@@ -287,4 +287,4 @@ if ( ! function_exists('repeater'))
}
/* End of file string_helper.php */
-/* Location: ./system/helpers/string_helper.php */
+/* Location: ./system/helpers/string_helper.php */
\ No newline at end of file
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 9a56159d9..daf31c3d6 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -531,4 +531,4 @@ if ( ! function_exists('ellipsize'))
}
/* End of file text_helper.php */
-/* Location: ./system/helpers/text_helper.php */
+/* Location: ./system/helpers/text_helper.php */
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 7fd46308949522f1c7c8853381c2ce7cea093c9a Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Fri, 23 Mar 2012 15:59:38 +0200
Subject: Remove an accidently added newline at foreign_chars.php EOF
---
application/config/foreign_chars.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/application/config/foreign_chars.php b/application/config/foreign_chars.php
index fc349ff0b..d3713fe98 100644
--- a/application/config/foreign_chars.php
+++ b/application/config/foreign_chars.php
@@ -87,4 +87,4 @@ $foreign_characters = array(
);
/* End of file foreign_chars.php */
-/* Location: ./application/config/foreign_chars.php */
+/* Location: ./application/config/foreign_chars.php */
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 6a96bf7ece4da23e2a802f48c408fa240da776f0 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Wed, 4 Apr 2012 19:13:03 +0700
Subject: Include PDO code coverage, remove unnecessary line on phpunit xml
---
.travis.yml | 9 ++++++---
tests/travis/mysql.phpunit.xml | 5 -----
tests/travis/pdo/mysql.phpunit.xml | 32 ++++++++++++++++++++++++++++++++
tests/travis/pdo/pgsql.phpunit.xml | 32 ++++++++++++++++++++++++++++++++
tests/travis/pdo/sqlite.phpunit.xml | 32 ++++++++++++++++++++++++++++++++
tests/travis/pgsql.phpunit.xml | 5 -----
tests/travis/sqlite.phpunit.xml | 5 -----
7 files changed, 102 insertions(+), 18 deletions(-)
create mode 100644 tests/travis/pdo/mysql.phpunit.xml
create mode 100644 tests/travis/pdo/pgsql.phpunit.xml
create mode 100644 tests/travis/pdo/sqlite.phpunit.xml
diff --git a/.travis.yml b/.travis.yml
index 84029b964..033fd6ab0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,14 +8,17 @@ env:
- DB=mysql
- DB=pgsql
- DB=sqlite
+ - DB=pdo/mysql
+ - DB=pdo/pgsql
+ - DB=pdo/sqlite
before_script:
- pyrus channel-discover pear.php-tools.net
- pyrus install http://pear.php-tools.net/get/vfsStream-0.11.2.tgz
- phpenv rehash
- - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'DROP DATABASE IF EXISTS ci_test;' -U postgres; fi"
- - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'create database ci_test;' -U postgres; fi"
- - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS ci_test;'; fi"
+ - sh -c "if [ '$DB' = 'pgsql' | '$DB' = 'pdo/pgsql' ]; then psql -c 'DROP DATABASE IF EXISTS ci_test;' -U postgres; fi"
+ - sh -c "if [ '$DB' = 'pgsql' | '$DB' = 'pdo/pgsql' ]; then psql -c 'create database ci_test;' -U postgres; fi"
+ - sh -c "if [ '$DB' = 'mysql' | '$DB' = 'pdo/mysql' ]; then mysql -e 'create database IF NOT EXISTS ci_test;'; fi"
script: phpunit --configuration tests/travis/$DB.phpunit.xml
diff --git a/tests/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml
index 44d6d6ed9..e9556f758 100644
--- a/tests/travis/mysql.phpunit.xml
+++ b/tests/travis/mysql.phpunit.xml
@@ -28,10 +28,5 @@
PROJECT_BASE.'tests''../../system/core/CodeIgniter.php'
-
-
-
\ No newline at end of file
diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml
new file mode 100644
index 000000000..eb650fa1e
--- /dev/null
+++ b/tests/travis/pdo/mysql.phpunit.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+ ../../codeigniter/Setup_test.php
+ ../../codeigniter/core
+ ../../codeigniter/helpers
+ ../../codeigniter/libraries
+ ../../codeigniter/database
+
+
+
+
+ PEAR_INSTALL_DIR
+ PHP_LIBDIR
+ PROJECT_BASE.'tests'
+ '../../../system/core/CodeIgniter.php'
+
+
+
\ No newline at end of file
diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml
new file mode 100644
index 000000000..351f690d5
--- /dev/null
+++ b/tests/travis/pdo/pgsql.phpunit.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+ ../../codeigniter/Setup_test.php
+ ../../codeigniter/core
+ ../../codeigniter/helpers
+ ../../codeigniter/libraries
+ ../../codeigniter/database
+
+
+
+
+ PEAR_INSTALL_DIR
+ PHP_LIBDIR
+ PROJECT_BASE.'tests'
+ '../../../system/core/CodeIgniter.php'
+
+
+
\ No newline at end of file
diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml
new file mode 100644
index 000000000..ae139b7a9
--- /dev/null
+++ b/tests/travis/pdo/sqlite.phpunit.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+ ../../codeigniter/Setup_test.php
+ ../../codeigniter/core
+ ../../codeigniter/helpers
+ ../../codeigniter/libraries
+ ../../codeigniter/database
+
+
+
+
+ PEAR_INSTALL_DIR
+ PHP_LIBDIR
+ PROJECT_BASE.'tests'
+ '../../../system/core/CodeIgniter.php'
+
+
+
\ No newline at end of file
diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml
index 9f52b40ae..ad8aeded2 100644
--- a/tests/travis/pgsql.phpunit.xml
+++ b/tests/travis/pgsql.phpunit.xml
@@ -28,10 +28,5 @@
PROJECT_BASE.'tests''../../system/core/CodeIgniter.php'
-
-
-
\ No newline at end of file
diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml
index 74ebb482b..628370e93 100644
--- a/tests/travis/sqlite.phpunit.xml
+++ b/tests/travis/sqlite.phpunit.xml
@@ -28,10 +28,5 @@
PROJECT_BASE.'tests''../../system/core/CodeIgniter.php'
-
-
-
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 44015c8d91ecea78ee4a10de579c36a859c2fcb6 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Wed, 4 Apr 2012 19:38:16 +0700
Subject: Set up PDO constant and configuration
---
.travis.yml | 6 ++---
tests/mocks/database/config/pdo/mysql.php | 37 ++++++++++++++++++++++++++++++
tests/mocks/database/config/pdo/pgsql.php | 37 ++++++++++++++++++++++++++++++
tests/mocks/database/config/pdo/sqlite.php | 22 ++++++++++++++++++
tests/mocks/database/config/sqlite.php | 7 +++---
tests/travis/pdo/mysql.phpunit.xml | 2 +-
tests/travis/pdo/pgsql.phpunit.xml | 2 +-
tests/travis/pdo/sqlite.phpunit.xml | 2 +-
8 files changed, 105 insertions(+), 10 deletions(-)
create mode 100644 tests/mocks/database/config/pdo/mysql.php
create mode 100644 tests/mocks/database/config/pdo/pgsql.php
create mode 100644 tests/mocks/database/config/pdo/sqlite.php
diff --git a/.travis.yml b/.travis.yml
index 033fd6ab0..97ea0422d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -16,9 +16,9 @@ before_script:
- pyrus channel-discover pear.php-tools.net
- pyrus install http://pear.php-tools.net/get/vfsStream-0.11.2.tgz
- phpenv rehash
- - sh -c "if [ '$DB' = 'pgsql' | '$DB' = 'pdo/pgsql' ]; then psql -c 'DROP DATABASE IF EXISTS ci_test;' -U postgres; fi"
- - sh -c "if [ '$DB' = 'pgsql' | '$DB' = 'pdo/pgsql' ]; then psql -c 'create database ci_test;' -U postgres; fi"
- - sh -c "if [ '$DB' = 'mysql' | '$DB' = 'pdo/mysql' ]; then mysql -e 'create database IF NOT EXISTS ci_test;'; fi"
+ - sh -c "if [ '$DB' = 'pgsql' ] || [ '$DB' = 'pdo/pgsql' ]; then psql -c 'DROP DATABASE IF EXISTS ci_test;' -U postgres; fi"
+ - sh -c "if [ '$DB' = 'pgsql' ] || [ '$DB' = 'pdo/pgsql' ]; then psql -c 'create database ci_test;' -U postgres; fi"
+ - sh -c "if [ '$DB' = 'mysql' ] || [ '$DB' = 'pdo/mysql' ]; then mysql -e 'create database IF NOT EXISTS ci_test;'; fi"
script: phpunit --configuration tests/travis/$DB.phpunit.xml
diff --git a/tests/mocks/database/config/pdo/mysql.php b/tests/mocks/database/config/pdo/mysql.php
new file mode 100644
index 000000000..cefb6b008
--- /dev/null
+++ b/tests/mocks/database/config/pdo/mysql.php
@@ -0,0 +1,37 @@
+ array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'travis',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'pdo',
+ 'pdodriver' => 'mysql',
+ ),
+
+ // Database configuration with failover
+ 'pdo/mysql_failover' => array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'not_travis',
+ 'password' => 'wrong password',
+ 'database' => 'not_ci_test',
+ 'dbdriver' => 'pdo',
+ 'pdodriver' => 'mysql',
+ 'failover' => array(
+ array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'travis',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'pdo',
+ 'pdodriver' => 'mysql',
+ ),
+ ),
+ ),
+);
\ No newline at end of file
diff --git a/tests/mocks/database/config/pdo/pgsql.php b/tests/mocks/database/config/pdo/pgsql.php
new file mode 100644
index 000000000..b2f409d8d
--- /dev/null
+++ b/tests/mocks/database/config/pdo/pgsql.php
@@ -0,0 +1,37 @@
+ array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'postgres',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'pdo',
+ 'pdodriver' => 'pgsql',
+ ),
+
+ // Database configuration with failover
+ 'pdo/pgsql_failover' => array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'not_travis',
+ 'password' => 'wrong password',
+ 'database' => 'not_ci_test',
+ 'dbdriver' => 'pdo',
+ 'pdodriver' => 'pgsql',
+ 'failover' => array(
+ array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'postgres',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'pdo',
+ 'pdodriver' => 'pgsql',
+ ),
+ ),
+ ),
+);
\ No newline at end of file
diff --git a/tests/mocks/database/config/pdo/sqlite.php b/tests/mocks/database/config/pdo/sqlite.php
new file mode 100644
index 000000000..c6827b41c
--- /dev/null
+++ b/tests/mocks/database/config/pdo/sqlite.php
@@ -0,0 +1,22 @@
+ array(
+ 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite',
+ 'dbdriver' => 'pdo',
+ ),
+
+ // Database configuration with failover
+ 'pdo/sqlite_failover' => array(
+ 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/not_exists.sqlite',
+ 'dbdriver' => 'pdo',
+ 'failover' => array(
+ array(
+ 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite',
+ 'dbdriver' => 'pdo',
+ ),
+ ),
+ ),
+);
\ No newline at end of file
diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php
index 8665e208d..c70986e7c 100644
--- a/tests/mocks/database/config/sqlite.php
+++ b/tests/mocks/database/config/sqlite.php
@@ -1,5 +1,4 @@
'sqlite',
'password' => 'sqlite',
'database' => realpath(__DIR__.'/..').'/ci_test.sqlite',
- 'dbdriver' => $dbdriver,
+ 'dbdriver' => is_php('5.4') ? 'sqlite3' : 'sqlite',
),
// Database configuration with failover
@@ -20,7 +19,7 @@ return array(
'username' => 'sqlite',
'password' => 'sqlite',
'database' => '../not_exists.sqlite',
- 'dbdriver' => $dbdriver,
+ 'dbdriver' => is_php('5.4') ? 'sqlite3' : 'sqlite',
'failover' => array(
array(
'dsn' => '',
@@ -28,7 +27,7 @@ return array(
'username' => 'sqlite',
'password' => 'sqlite',
'database' => realpath(__DIR__.'/..').'/ci_testf.sqlite',
- 'dbdriver' => $dbdriver,
+ 'dbdriver' => is_php('5.4') ? 'sqlite3' : 'sqlite',
),
),
),
diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml
index eb650fa1e..69eece24f 100644
--- a/tests/travis/pdo/mysql.phpunit.xml
+++ b/tests/travis/pdo/mysql.phpunit.xml
@@ -10,7 +10,7 @@
stopOnIncomplete="false"
stopOnSkipped="false">
-
+
diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml
index 351f690d5..e68c3e028 100644
--- a/tests/travis/pdo/pgsql.phpunit.xml
+++ b/tests/travis/pdo/pgsql.phpunit.xml
@@ -10,7 +10,7 @@
stopOnIncomplete="false"
stopOnSkipped="false">
-
+
diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml
index ae139b7a9..1871f6221 100644
--- a/tests/travis/pdo/sqlite.phpunit.xml
+++ b/tests/travis/pdo/sqlite.phpunit.xml
@@ -10,7 +10,7 @@
stopOnIncomplete="false"
stopOnSkipped="false">
-
+
--
cgit v1.2.3-24-g4f1b
From f4c6c9b3061b464c959b6409f962228959f35287 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Wed, 4 Apr 2012 23:24:09 +0700
Subject: DB Drivers test
---
tests/codeigniter/database/DB_driver_test.php | 36 +++++++++++++++++++++++++++
tests/mocks/autoloader.php | 15 +++++++++--
tests/mocks/database/config/ci_test.sqlite | 0
tests/mocks/database/config/pdo/sqlite.php | 3 +++
tests/mocks/database/db.php | 6 +++++
tests/mocks/database/db/driver.php | 36 +++++++++++++++++++++++++++
tests/mocks/database/drivers/mysql.php | 16 ++++++++++++
tests/mocks/database/drivers/pdo.php | 16 ++++++++++++
tests/mocks/database/drivers/postgre.php | 16 ++++++++++++
tests/mocks/database/drivers/sqlite.php | 16 ++++++++++++
10 files changed, 158 insertions(+), 2 deletions(-)
create mode 100644 tests/codeigniter/database/DB_driver_test.php
create mode 100644 tests/mocks/database/config/ci_test.sqlite
create mode 100644 tests/mocks/database/db/driver.php
create mode 100644 tests/mocks/database/drivers/mysql.php
create mode 100644 tests/mocks/database/drivers/pdo.php
create mode 100644 tests/mocks/database/drivers/postgre.php
create mode 100644 tests/mocks/database/drivers/sqlite.php
diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php
new file mode 100644
index 000000000..fb40f0608
--- /dev/null
+++ b/tests/codeigniter/database/DB_driver_test.php
@@ -0,0 +1,36 @@
+$driver_name($config[DB_DRIVER]);
+
+ $this->assertTrue($driver->initialize());
+ }
+
+ protected function pdo($config)
+ {
+ return new Mock_Database_Drivers_PDO($config);
+ }
+
+ protected function mysql($config)
+ {
+ return new Mock_Database_Drivers_Mysql($config);
+ }
+
+ protected function sqlite($config)
+ {
+ return new Mock_Database_Drivers_Sqlite($config);
+ }
+
+ protected function pgsql($config)
+ {
+ return new Mock_Database_Drivers_Postgre($config);
+ }
+
+}
\ No newline at end of file
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php
index dd5929206..22448139e 100644
--- a/tests/mocks/autoloader.php
+++ b/tests/mocks/autoloader.php
@@ -53,13 +53,24 @@ function autoload($class)
$dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR;
$class = $subclass;
}
+ elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) == 3)
+ {
+ $driver_path = BASEPATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR;
+ $dir = $driver_path.$m[1].DIRECTORY_SEPARATOR;
+ $file = $dir.$m[1].'_'.$m[2].'.php';
+ }
+ elseif (strpos($class, 'CI_DB') === 0)
+ {
+ $dir = BASEPATH.'database'.DIRECTORY_SEPARATOR;
+ $file = $dir.str_replace('CI_DB', 'DB', $subclass).'.php';
+ }
else
{
$class = strtolower($class);
}
}
- $file = $dir.$class.'.php';
+ $file = (isset($file)) ? $file : $dir.$class.'.php';
if ( ! file_exists($file))
{
@@ -71,7 +82,7 @@ function autoload($class)
{
return FALSE;
}
-
+ var_dump($file);
throw new InvalidArgumentException("Unable to load $class.");
}
diff --git a/tests/mocks/database/config/ci_test.sqlite b/tests/mocks/database/config/ci_test.sqlite
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/mocks/database/config/pdo/sqlite.php b/tests/mocks/database/config/pdo/sqlite.php
index c6827b41c..1e5043b00 100644
--- a/tests/mocks/database/config/pdo/sqlite.php
+++ b/tests/mocks/database/config/pdo/sqlite.php
@@ -6,16 +6,19 @@ return array(
'pdo/sqlite' => array(
'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite',
'dbdriver' => 'pdo',
+ 'pdodriver' => 'sqlite',
),
// Database configuration with failover
'pdo/sqlite_failover' => array(
'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/not_exists.sqlite',
'dbdriver' => 'pdo',
+ 'pdodriver' => 'sqlite',
'failover' => array(
array(
'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite',
'dbdriver' => 'pdo',
+ 'pdodriver' => 'sqlite',
),
),
),
diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php
index 43a0d391f..c30e6d2e6 100644
--- a/tests/mocks/database/db.php
+++ b/tests/mocks/database/db.php
@@ -45,6 +45,8 @@ class Mock_Database_DB {
);
$config = array_merge($this->config[$group], $params);
+ $pdodriver = ( ! empty($config['pdodriver'])) ? $config['pdodriver'] : FALSE;
+ $failover = ( ! empty($config['failover'])) ? $config['failover'] : FALSE;
if ( ! empty($config['dsn']))
{
@@ -57,7 +59,11 @@ class Mock_Database_DB {
}
+ // Build the parameter
$other_params = array_slice($config, 6);
+ $other_params['dsn'] = $dsn;
+ if ($pdodriver) $other_params['pdodriver'] = $pdodriver;
+ if ($failover) $other_params['failover'] = $failover;
return $dsn.'?'.http_build_query($other_params);
}
diff --git a/tests/mocks/database/db/driver.php b/tests/mocks/database/db/driver.php
new file mode 100644
index 000000000..9bf5231e3
--- /dev/null
+++ b/tests/mocks/database/db/driver.php
@@ -0,0 +1,36 @@
+ci_db_driver = new $driver_class($config);
+ }
+
+ /**
+ * Overloading method, emulate the actual driver method (multiple inheritance workaround)
+ */
+ public function __call($method, $arguments)
+ {
+ if ( ! is_callable(array($this->ci_db_driver, $method)))
+ {
+ throw new BadMethodCallException($method. ' not exists or not implemented');
+ }
+
+ return call_user_func_array(array($this->ci_db_driver, $method), $arguments);
+ }
+}
+
+class CI_DB extends CI_DB_Driver {}
\ No newline at end of file
diff --git a/tests/mocks/database/drivers/mysql.php b/tests/mocks/database/drivers/mysql.php
new file mode 100644
index 000000000..34a74e2bf
--- /dev/null
+++ b/tests/mocks/database/drivers/mysql.php
@@ -0,0 +1,16 @@
+
Date: Wed, 4 Apr 2012 23:46:23 +0700
Subject: Fix sqlite issue on PHP 5.4 both for native and PDO driver
---
not_exists.sqlite | 0
tests/mocks/database/config/ci_test.sqlite | 0
tests/mocks/database/config/pdo/sqlite.php | 20 ++++++++++++++++----
tests/mocks/database/db.php | 13 +++----------
4 files changed, 19 insertions(+), 14 deletions(-)
create mode 100644 not_exists.sqlite
delete mode 100644 tests/mocks/database/config/ci_test.sqlite
diff --git a/not_exists.sqlite b/not_exists.sqlite
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/mocks/database/config/ci_test.sqlite b/tests/mocks/database/config/ci_test.sqlite
deleted file mode 100644
index e69de29bb..000000000
diff --git a/tests/mocks/database/config/pdo/sqlite.php b/tests/mocks/database/config/pdo/sqlite.php
index 1e5043b00..c68b4b213 100644
--- a/tests/mocks/database/config/pdo/sqlite.php
+++ b/tests/mocks/database/config/pdo/sqlite.php
@@ -4,20 +4,32 @@ return array(
// Typical Database configuration
'pdo/sqlite' => array(
- 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite',
+ 'dsn' => 'sqlite:/'.realpath(__DIR__.'/../..').'/ci_test.sqlite',
+ 'hostname' => 'localhost',
+ 'username' => 'sqlite',
+ 'password' => 'sqlite',
+ 'database' => 'sqlite',
'dbdriver' => 'pdo',
'pdodriver' => 'sqlite',
),
// Database configuration with failover
'pdo/sqlite_failover' => array(
- 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/not_exists.sqlite',
+ 'dsn' => 'sqlite:not_exists.sqlite',
+ 'hostname' => 'localhost',
+ 'username' => 'sqlite',
+ 'password' => 'sqlite',
+ 'database' => 'sqlite',
'dbdriver' => 'pdo',
'pdodriver' => 'sqlite',
'failover' => array(
array(
- 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite',
- 'dbdriver' => 'pdo',
+ 'dsn' => 'sqlite:/'.realpath(__DIR__.'/../..').'/ci_test.sqlite',
+ 'hostname' => 'localhost',
+ 'username' => 'sqlite',
+ 'password' => 'sqlite',
+ 'database' => 'sqlite',
+ 'dbdriver' => 'pdo',
'pdodriver' => 'sqlite',
),
),
diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php
index c30e6d2e6..59028ed9c 100644
--- a/tests/mocks/database/db.php
+++ b/tests/mocks/database/db.php
@@ -45,23 +45,16 @@ class Mock_Database_DB {
);
$config = array_merge($this->config[$group], $params);
+ $dsnstring = ( ! empty($config['dsn'])) ? $config['dsn'] : FALSE;
$pdodriver = ( ! empty($config['pdodriver'])) ? $config['pdodriver'] : FALSE;
$failover = ( ! empty($config['failover'])) ? $config['failover'] : FALSE;
- if ( ! empty($config['dsn']))
- {
- $dsn = $config['dsn'];
- }
- else
- {
- $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password']
+ $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password']
.'@'.$config['hostname'].'/'.$config['database'];
- }
-
// Build the parameter
$other_params = array_slice($config, 6);
- $other_params['dsn'] = $dsn;
+ if ($dsnstring) $other_params['dsn'] = $dsnstring;
if ($pdodriver) $other_params['pdodriver'] = $pdodriver;
if ($failover) $other_params['failover'] = $failover;
--
cgit v1.2.3-24-g4f1b
From ffd7a0bcedbbac497c9987a3c9299b2edaa7c717 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Wed, 4 Apr 2012 23:47:40 +0700
Subject: Remove testing db
---
not_exists.sqlite | 0
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 not_exists.sqlite
diff --git a/not_exists.sqlite b/not_exists.sqlite
deleted file mode 100644
index e69de29bb..000000000
--
cgit v1.2.3-24-g4f1b
From 26490e37f4bdb267b71431abd79782549cbbadda Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Wed, 4 Apr 2012 23:50:00 +0700
Subject: Add branch to travis list
---
.travis.yml | 3 ++-
tests/mocks/database/drivers/sqlite.php | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 97ea0422d..971f62f38 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,4 +25,5 @@ script: phpunit --configuration tests/travis/$DB.phpunit.xml
branches:
only:
- develop
- - master
\ No newline at end of file
+ - master
+ - db-tests
\ No newline at end of file
diff --git a/tests/mocks/database/drivers/sqlite.php b/tests/mocks/database/drivers/sqlite.php
index 49c68c50f..76a182cbf 100644
--- a/tests/mocks/database/drivers/sqlite.php
+++ b/tests/mocks/database/drivers/sqlite.php
@@ -11,6 +11,6 @@ class Mock_Database_Drivers_Sqlite extends Mock_Database_DB_Driver {
*/
public function __construct($config = array())
{
- parent::__construct('CI_DB_sqlite_driver', $config);
+ parent::__construct('CI_DB_sqlite3_driver', $config);
}
}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 61ff054fb905f0514b942bf3e70a6c882bd64f7a Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Thu, 5 Apr 2012 01:23:56 +0700
Subject: Adding schema and initial Query Builder code coverage
---
tests/codeigniter/database/query_builder/.gitkeep | 0
tests/mocks/autoloader.php | 4 ++--
tests/mocks/database/ci_test.sqlite | Bin 17408 -> 17408 bytes
tests/mocks/database/config/sqlite.php | 6 +++---
tests/mocks/database/db/driver.php | 2 +-
tests/mocks/database/schema/.gitkeep | 0
6 files changed, 6 insertions(+), 6 deletions(-)
delete mode 100644 tests/codeigniter/database/query_builder/.gitkeep
delete mode 100644 tests/mocks/database/schema/.gitkeep
diff --git a/tests/codeigniter/database/query_builder/.gitkeep b/tests/codeigniter/database/query_builder/.gitkeep
deleted file mode 100644
index e69de29bb..000000000
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php
index 22448139e..f1bdb5d6f 100644
--- a/tests/mocks/autoloader.php
+++ b/tests/mocks/autoloader.php
@@ -62,7 +62,7 @@ function autoload($class)
elseif (strpos($class, 'CI_DB') === 0)
{
$dir = BASEPATH.'database'.DIRECTORY_SEPARATOR;
- $file = $dir.str_replace('CI_DB', 'DB', $subclass).'.php';
+ $file = $dir.str_replace(array('CI_DB','active_record'), array('DB', 'active_rec'), $subclass).'.php';
}
else
{
@@ -82,7 +82,7 @@ function autoload($class)
{
return FALSE;
}
- var_dump($file);
+
throw new InvalidArgumentException("Unable to load $class.");
}
diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite
index 37ce4f870..86d868af2 100755
Binary files a/tests/mocks/database/ci_test.sqlite and b/tests/mocks/database/ci_test.sqlite differ
diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php
index c70986e7c..75fdacd96 100644
--- a/tests/mocks/database/config/sqlite.php
+++ b/tests/mocks/database/config/sqlite.php
@@ -9,7 +9,7 @@ return array(
'username' => 'sqlite',
'password' => 'sqlite',
'database' => realpath(__DIR__.'/..').'/ci_test.sqlite',
- 'dbdriver' => is_php('5.4') ? 'sqlite3' : 'sqlite',
+ 'dbdriver' => 'sqlite3',
),
// Database configuration with failover
@@ -19,7 +19,7 @@ return array(
'username' => 'sqlite',
'password' => 'sqlite',
'database' => '../not_exists.sqlite',
- 'dbdriver' => is_php('5.4') ? 'sqlite3' : 'sqlite',
+ 'dbdriver' => 'sqlite3',
'failover' => array(
array(
'dsn' => '',
@@ -27,7 +27,7 @@ return array(
'username' => 'sqlite',
'password' => 'sqlite',
'database' => realpath(__DIR__.'/..').'/ci_testf.sqlite',
- 'dbdriver' => is_php('5.4') ? 'sqlite3' : 'sqlite',
+ 'dbdriver' => 'sqlite3',
),
),
),
diff --git a/tests/mocks/database/db/driver.php b/tests/mocks/database/db/driver.php
index 9bf5231e3..cb1820277 100644
--- a/tests/mocks/database/db/driver.php
+++ b/tests/mocks/database/db/driver.php
@@ -33,4 +33,4 @@ class Mock_Database_DB_Driver extends CI_DB_driver {
}
}
-class CI_DB extends CI_DB_Driver {}
\ No newline at end of file
+class CI_DB extends Mock_Database_DB_QueryBuilder {}
\ No newline at end of file
diff --git a/tests/mocks/database/schema/.gitkeep b/tests/mocks/database/schema/.gitkeep
deleted file mode 100644
index e69de29bb..000000000
--
cgit v1.2.3-24-g4f1b
From 5b421665bac7609192917f7b0f34838534be099e Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Thu, 5 Apr 2012 01:24:50 +0700
Subject: Simple query builder tests
---
.../database/query_builder/get_test.php | 48 ++++++++++++++++
tests/mocks/database/db/querybuilder.php | 10 ++++
tests/mocks/database/schema/skeleton.php | 65 ++++++++++++++++++++++
3 files changed, 123 insertions(+)
create mode 100644 tests/codeigniter/database/query_builder/get_test.php
create mode 100644 tests/mocks/database/db/querybuilder.php
create mode 100644 tests/mocks/database/schema/skeleton.php
diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php
new file mode 100644
index 000000000..6f98ded4f
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/get_test.php
@@ -0,0 +1,48 @@
+set_dsn(DB_DRIVER), TRUE);
+
+ $this->ci_instance_var('db', $db);
+
+ $loader = new Mock_Core_Loader();
+ $loader->dbforge();
+
+ $forge = $this->ci_instance->dbforge;
+
+ Mock_Database_Schema_Skeleton::create_tables($forge);
+ Mock_Database_Schema_Skeleton::create_data($db);
+
+ $this->query_builder = $db;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_get_simple()
+ {
+ $jobs = $this->query_builder->get('job')->result_array();
+
+ // Dummy jobs contain 4 rows
+ $this->assertCount(4, $jobs);
+
+ // Check rows item
+ $this->assertEquals('Developer', $jobs[0]['name']);
+ $this->assertEquals('Politician', $jobs[1]['name']);
+ $this->assertEquals('Accountant', $jobs[2]['name']);
+ $this->assertEquals('Musician', $jobs[3]['name']);
+ }
+
+}
\ No newline at end of file
diff --git a/tests/mocks/database/db/querybuilder.php b/tests/mocks/database/db/querybuilder.php
new file mode 100644
index 000000000..1b95c92af
--- /dev/null
+++ b/tests/mocks/database/db/querybuilder.php
@@ -0,0 +1,10 @@
+add_field(array(
+ 'id' => array(
+ 'type' => 'INT',
+ 'constraint' => 3,
+ ),
+ 'name' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40,
+ ),
+ 'description' => array(
+ 'type' => 'TEXT',
+ 'constraint' => 0,
+ ),
+ ));
+ $forge->add_key('id', TRUE);
+ $forge->create_table('job', TRUE);
+ }
+
+ /**
+ * Create the dummy datas
+ *
+ * @return void
+ */
+ public static function create_data($db)
+ {
+ // Job Data
+ $data = array(
+ 'job' => array(
+ array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'),
+ array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'),
+ array('id' => 3, 'name' => 'Accountant', 'description' => 'Boring job, but you will get free snack at lunch'),
+ array('id' => 4, 'name' => 'Musician', 'description' => 'Only Coldplay can actually called Musician'),
+ ),
+ );
+
+ foreach ($data as $table => $dummy_data)
+ {
+ $db->truncate($table);
+
+ if (strpos(DB_DRIVER, 'sqlite') === FALSE)
+ {
+ $db->insert_batch($table, $dummy_data);
+ }
+ else
+ {
+ foreach ($dummy_data as $single_dummy_data)
+ {
+ $db->insert($table, $single_dummy_data);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 55f804239cb0141fdac748607d8cdfa143efac92 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Thu, 5 Apr 2012 01:48:52 +0700
Subject: Add dsn to pgsql
---
tests/mocks/database/config/pdo/pgsql.php | 4 ++--
tests/mocks/database/config/sqlite.php | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/mocks/database/config/pdo/pgsql.php b/tests/mocks/database/config/pdo/pgsql.php
index b2f409d8d..5196e9ad9 100644
--- a/tests/mocks/database/config/pdo/pgsql.php
+++ b/tests/mocks/database/config/pdo/pgsql.php
@@ -4,7 +4,7 @@ return array(
// Typical Database configuration
'pdo/pgsql' => array(
- 'dsn' => '',
+ 'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;',
'hostname' => 'localhost',
'username' => 'postgres',
'password' => '',
@@ -24,7 +24,7 @@ return array(
'pdodriver' => 'pgsql',
'failover' => array(
array(
- 'dsn' => '',
+ 'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;',
'hostname' => 'localhost',
'username' => 'postgres',
'password' => '',
diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php
index 75fdacd96..755ce2a3a 100644
--- a/tests/mocks/database/config/sqlite.php
+++ b/tests/mocks/database/config/sqlite.php
@@ -26,7 +26,7 @@ return array(
'hostname' => 'localhost',
'username' => 'sqlite',
'password' => 'sqlite',
- 'database' => realpath(__DIR__.'/..').'/ci_testf.sqlite',
+ 'database' => realpath(__DIR__.'/..').'/ci_test.sqlite',
'dbdriver' => 'sqlite3',
),
),
--
cgit v1.2.3-24-g4f1b
From 024098d05d00383bf82165e1f8bbadb53cbcaa9b Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Thu, 5 Apr 2012 01:51:57 +0700
Subject: Use more user-friendly method for dummy create data
---
tests/mocks/database/schema/skeleton.php | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
index bf9e75b45..53df73bdd 100644
--- a/tests/mocks/database/schema/skeleton.php
+++ b/tests/mocks/database/schema/skeleton.php
@@ -48,17 +48,10 @@ class Mock_Database_Schema_Skeleton {
foreach ($data as $table => $dummy_data)
{
$db->truncate($table);
-
- if (strpos(DB_DRIVER, 'sqlite') === FALSE)
- {
- $db->insert_batch($table, $dummy_data);
- }
- else
+
+ foreach ($dummy_data as $single_dummy_data)
{
- foreach ($dummy_data as $single_dummy_data)
- {
- $db->insert($table, $single_dummy_data);
- }
+ $db->insert($table, $single_dummy_data);
}
}
}
--
cgit v1.2.3-24-g4f1b
From 1bfc0d9a2b47be1a2a0b8efda60ebdd9d7a303dd Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Thu, 5 Apr 2012 02:25:25 +0700
Subject: Fix postgre table datatype
---
tests/mocks/database/schema/skeleton.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
index 53df73bdd..47e8bfd35 100644
--- a/tests/mocks/database/schema/skeleton.php
+++ b/tests/mocks/database/schema/skeleton.php
@@ -12,7 +12,7 @@ class Mock_Database_Schema_Skeleton {
// Job Table
$forge->add_field(array(
'id' => array(
- 'type' => 'INT',
+ 'type' => 'INTEGER',
'constraint' => 3,
),
'name' => array(
@@ -21,11 +21,11 @@ class Mock_Database_Schema_Skeleton {
),
'description' => array(
'type' => 'TEXT',
- 'constraint' => 0,
),
));
$forge->add_key('id', TRUE);
- $forge->create_table('job', TRUE);
+ $res = $forge->create_table('job');
+ var_dump($res);
}
/**
--
cgit v1.2.3-24-g4f1b
From b0703b0bee89ab0eae83bae78daad5c5a3504043 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Thu, 5 Apr 2012 02:31:52 +0700
Subject: Resolve postgres issue on create table
---
tests/mocks/database/schema/skeleton.php | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
index 47e8bfd35..6610d6b59 100644
--- a/tests/mocks/database/schema/skeleton.php
+++ b/tests/mocks/database/schema/skeleton.php
@@ -7,7 +7,7 @@ class Mock_Database_Schema_Skeleton {
*
* @return void
*/
- public static function create_tables($forge)
+ public static function create_tables($forge, $driver)
{
// Job Table
$forge->add_field(array(
@@ -24,8 +24,7 @@ class Mock_Database_Schema_Skeleton {
),
));
$forge->add_key('id', TRUE);
- $res = $forge->create_table('job');
- var_dump($res);
+ $forge->create_table('job', (strpos($driver, 'pgsql') === FALSE));
}
/**
--
cgit v1.2.3-24-g4f1b
From 333ce0db32865d1e6d6a96207e5c9306bd40c676 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Thu, 5 Apr 2012 02:34:06 +0700
Subject: Fixed schema
---
tests/codeigniter/database/query_builder/get_test.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php
index 6f98ded4f..e6fe319c5 100644
--- a/tests/codeigniter/database/query_builder/get_test.php
+++ b/tests/codeigniter/database/query_builder/get_test.php
@@ -20,7 +20,7 @@ class Get_test extends CI_TestCase {
$forge = $this->ci_instance->dbforge;
- Mock_Database_Schema_Skeleton::create_tables($forge);
+ Mock_Database_Schema_Skeleton::create_tables($forge, DB_DRIVER);
Mock_Database_Schema_Skeleton::create_data($db);
$this->query_builder = $db;
--
cgit v1.2.3-24-g4f1b
From fd24fa614885d6c89e19aecb09ae97f95dd3db57 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Thu, 5 Apr 2012 02:42:46 +0700
Subject: Remove temporary line
---
.travis.yml | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 971f62f38..97ea0422d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,5 +25,4 @@ script: phpunit --configuration tests/travis/$DB.phpunit.xml
branches:
only:
- develop
- - master
- - db-tests
\ No newline at end of file
+ - master
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 36897fba4c825e612e3e7d772174c95093aa7f96 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Thu, 5 Apr 2012 18:28:27 +0700
Subject: Test last upstream/develop
---
.travis.yml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index 97ea0422d..a56f7b687 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,4 +25,5 @@ script: phpunit --configuration tests/travis/$DB.phpunit.xml
branches:
only:
- develop
- - master
\ No newline at end of file
+ - master
+ - db-tests
--
cgit v1.2.3-24-g4f1b
From 55f622f76371949ae615ccdff76ed1e4bab55170 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Thu, 5 Apr 2012 19:01:34 +0700
Subject: Add select clause test
---
.../database/query_builder/get_test.php | 31 +++++++-----
.../database/query_builder/select_test.php | 37 +++++++++++++++
tests/mocks/database/schema/skeleton.php | 55 +++++++++++++++++++---
3 files changed, 104 insertions(+), 19 deletions(-)
create mode 100644 tests/codeigniter/database/query_builder/select_test.php
diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php
index e6fe319c5..dd946a40c 100644
--- a/tests/codeigniter/database/query_builder/get_test.php
+++ b/tests/codeigniter/database/query_builder/get_test.php
@@ -9,19 +9,10 @@ class Get_test extends CI_TestCase {
public function set_up()
{
- $config = Mock_Database_DB::config(DB_DRIVER);
- $connection = new Mock_Database_DB($config);
- $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER), TRUE);
+ $db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
- $this->ci_instance_var('db', $db);
-
- $loader = new Mock_Core_Loader();
- $loader->dbforge();
-
- $forge = $this->ci_instance->dbforge;
-
- Mock_Database_Schema_Skeleton::create_tables($forge, DB_DRIVER);
- Mock_Database_Schema_Skeleton::create_data($db);
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
$this->query_builder = $db;
}
@@ -44,5 +35,21 @@ class Get_test extends CI_TestCase {
$this->assertEquals('Accountant', $jobs[2]['name']);
$this->assertEquals('Musician', $jobs[3]['name']);
}
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_get_where()
+ {
+ $job1 = $this->query_builder->get('job', array('id' => 1))->result_array();
+
+ // Dummy jobs contain 1 rows
+ $this->assertCount(1, $job1);
+
+ // Check rows item
+ $this->assertEquals('Developer', $job1[0]['name']);
+ }
}
\ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php
new file mode 100644
index 000000000..ba2f21b64
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/select_test.php
@@ -0,0 +1,37 @@
+query_builder = $db;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_select_only_one_collumn()
+ {
+ $jobs_name = $this->query_builder->select('name')
+ ->get('job')
+ ->result_array();
+
+ // Check rows item
+ $this->assertArrayHasKey('name',$jobs_name[0]);
+ $this->assertFalse(array_key_exists('id', $jobs_name[0]));
+ $this->assertFalse(array_key_exists('description', $jobs_name[0]));
+ }
+
+}
\ No newline at end of file
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
index 6610d6b59..a3d5bac65 100644
--- a/tests/mocks/database/schema/skeleton.php
+++ b/tests/mocks/database/schema/skeleton.php
@@ -1,16 +1,57 @@
set_dsn($driver), TRUE);
+
+ CI_TestCase::instance()->ci_instance_var('db', $db);
+
+ $loader = new Mock_Core_Loader();
+ $loader->dbforge();
+ $forge = CI_TestCase::instance()->ci_instance_var('dbforge');
+
+ static::$db = $db;
+ static::$forge = $forge;
+ static::$driver = $driver;
+ }
+
+ return static::$db;
+ }
+
/**
* Create the dummy tables
*
* @return void
*/
- public static function create_tables($forge, $driver)
+ public static function create_tables()
{
// Job Table
- $forge->add_field(array(
+ static::$forge->add_field(array(
'id' => array(
'type' => 'INTEGER',
'constraint' => 3,
@@ -23,8 +64,8 @@ class Mock_Database_Schema_Skeleton {
'type' => 'TEXT',
),
));
- $forge->add_key('id', TRUE);
- $forge->create_table('job', (strpos($driver, 'pgsql') === FALSE));
+ static::$forge->add_key('id', TRUE);
+ static::$forge->create_table('job', (strpos(static::$driver, 'pgsql') === FALSE));
}
/**
@@ -32,7 +73,7 @@ class Mock_Database_Schema_Skeleton {
*
* @return void
*/
- public static function create_data($db)
+ public static function create_data()
{
// Job Data
$data = array(
@@ -46,11 +87,11 @@ class Mock_Database_Schema_Skeleton {
foreach ($data as $table => $dummy_data)
{
- $db->truncate($table);
+ static::$db->truncate($table);
foreach ($dummy_data as $single_dummy_data)
{
- $db->insert($table, $single_dummy_data);
+ static::$db->insert($table, $single_dummy_data);
}
}
}
--
cgit v1.2.3-24-g4f1b
From fdc0ea8802c48a5f74df97c013f683d4b264218a Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Thu, 5 Apr 2012 19:08:00 +0700
Subject: Min, Max, Avg and Sum
---
.../database/query_builder/select_test.php | 60 ++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php
index ba2f21b64..50a062c9f 100644
--- a/tests/codeigniter/database/query_builder/select_test.php
+++ b/tests/codeigniter/database/query_builder/select_test.php
@@ -33,5 +33,65 @@ class Select_test extends CI_TestCase {
$this->assertFalse(array_key_exists('id', $jobs_name[0]));
$this->assertFalse(array_key_exists('description', $jobs_name[0]));
}
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_select_min()
+ {
+ $job_min = $this->query_builder->select_min('id')
+ ->get('job')
+ ->result_array();
+
+ // Minimum id was 1
+ $this->assertEquals('1', $job_min[0]['id']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_select_max()
+ {
+ $job_max = $this->query_builder->select_max('id')
+ ->get('job')
+ ->result_array();
+
+ // Maximum id was 4
+ $this->assertEquals('4', $job_max[0]['id']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_select_avg()
+ {
+ $job_avg = $this->query_builder->select_avg('id')
+ ->get('job')
+ ->result_array();
+
+ // Average should be 2.5
+ $this->assertEquals('2.5', $job_avg[0]['id']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_select_sum()
+ {
+ $job_sum = $this->query_builder->select_sum('id')
+ ->get('job')
+ ->result_array();
+
+ // Sum of ids should be 10
+ $this->assertEquals('10', $job_sum[0]['id']);
+ }
}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From bf0ce689fae71a22abfaf1854c954f7a3b467d20 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Thu, 5 Apr 2012 19:09:29 +0700
Subject: Remove temporary branch from travis yml
---
.travis.yml | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index a56f7b687..97ea0422d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,5 +25,4 @@ script: phpunit --configuration tests/travis/$DB.phpunit.xml
branches:
only:
- develop
- - master
- - db-tests
+ - master
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 0793b1c918a0146920b1a03323f055521c4a9c66 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Thu, 5 Apr 2012 21:47:53 +0700
Subject: Rename to db, for more familiar naming convention
---
.../database/query_builder/get_test.php | 10 +++---
.../database/query_builder/select_test.php | 36 ++++++++++------------
2 files changed, 21 insertions(+), 25 deletions(-)
diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php
index dd946a40c..0751c9332 100644
--- a/tests/codeigniter/database/query_builder/get_test.php
+++ b/tests/codeigniter/database/query_builder/get_test.php
@@ -5,16 +5,14 @@ class Get_test extends CI_TestCase {
/**
* @var object Database/Query Builder holder
*/
- protected $query_builder;
+ protected $db;
public function set_up()
{
- $db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
Mock_Database_Schema_Skeleton::create_tables();
Mock_Database_Schema_Skeleton::create_data();
-
- $this->query_builder = $db;
}
// ------------------------------------------------------------------------
@@ -24,7 +22,7 @@ class Get_test extends CI_TestCase {
*/
public function test_get_simple()
{
- $jobs = $this->query_builder->get('job')->result_array();
+ $jobs = $this->db->get('job')->result_array();
// Dummy jobs contain 4 rows
$this->assertCount(4, $jobs);
@@ -43,7 +41,7 @@ class Get_test extends CI_TestCase {
*/
public function test_get_where()
{
- $job1 = $this->query_builder->get('job', array('id' => 1))->result_array();
+ $job1 = $this->db->get('job', array('id' => 1))->result_array();
// Dummy jobs contain 1 rows
$this->assertCount(1, $job1);
diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php
index 50a062c9f..dbf432a7c 100644
--- a/tests/codeigniter/database/query_builder/select_test.php
+++ b/tests/codeigniter/database/query_builder/select_test.php
@@ -5,16 +5,14 @@ class Select_test extends CI_TestCase {
/**
* @var object Database/Query Builder holder
*/
- protected $query_builder;
+ protected $db;
public function set_up()
{
- $db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
Mock_Database_Schema_Skeleton::create_tables();
Mock_Database_Schema_Skeleton::create_data();
-
- $this->query_builder = $db;
}
// ------------------------------------------------------------------------
@@ -24,9 +22,9 @@ class Select_test extends CI_TestCase {
*/
public function test_select_only_one_collumn()
{
- $jobs_name = $this->query_builder->select('name')
- ->get('job')
- ->result_array();
+ $jobs_name = $this->db->select('name')
+ ->get('job')
+ ->result_array();
// Check rows item
$this->assertArrayHasKey('name',$jobs_name[0]);
@@ -41,9 +39,9 @@ class Select_test extends CI_TestCase {
*/
public function test_select_min()
{
- $job_min = $this->query_builder->select_min('id')
- ->get('job')
- ->result_array();
+ $job_min = $this->db->select_min('id')
+ ->get('job')
+ ->result_array();
// Minimum id was 1
$this->assertEquals('1', $job_min[0]['id']);
@@ -56,9 +54,9 @@ class Select_test extends CI_TestCase {
*/
public function test_select_max()
{
- $job_max = $this->query_builder->select_max('id')
- ->get('job')
- ->result_array();
+ $job_max = $this->db->select_max('id')
+ ->get('job')
+ ->result_array();
// Maximum id was 4
$this->assertEquals('4', $job_max[0]['id']);
@@ -71,9 +69,9 @@ class Select_test extends CI_TestCase {
*/
public function test_select_avg()
{
- $job_avg = $this->query_builder->select_avg('id')
- ->get('job')
- ->result_array();
+ $job_avg = $this->db->select_avg('id')
+ ->get('job')
+ ->result_array();
// Average should be 2.5
$this->assertEquals('2.5', $job_avg[0]['id']);
@@ -86,9 +84,9 @@ class Select_test extends CI_TestCase {
*/
public function test_select_sum()
{
- $job_sum = $this->query_builder->select_sum('id')
- ->get('job')
- ->result_array();
+ $job_sum = $this->db->select_sum('id')
+ ->get('job')
+ ->result_array();
// Sum of ids should be 10
$this->assertEquals('10', $job_sum[0]['id']);
--
cgit v1.2.3-24-g4f1b
From c0df5a231a28c6038f0a8ab702e090ce0e12b5a5 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Fri, 6 Apr 2012 17:35:12 +0700
Subject: Include insert test
---
.travis.yml | 3 +-
.../database/query_builder/insert_test.php | 47 ++++++++++++++++++++++
2 files changed, 49 insertions(+), 1 deletion(-)
create mode 100644 tests/codeigniter/database/query_builder/insert_test.php
diff --git a/.travis.yml b/.travis.yml
index 97ea0422d..971f62f38 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,4 +25,5 @@ script: phpunit --configuration tests/travis/$DB.phpunit.xml
branches:
only:
- develop
- - master
\ No newline at end of file
+ - master
+ - db-tests
\ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php
new file mode 100644
index 000000000..5607e8ce1
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/insert_test.php
@@ -0,0 +1,47 @@
+db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_insert()
+ {
+ $job_data = array('name' => 'Grocery Sales', 'description' => 'Discount!');
+
+ // Do normal insert
+ $this->assertTrue($this->db->insert('job', $job_data));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_insert_batch()
+ {
+ $job_datas = array(
+ array('name' => 'Commedian', 'description' => 'Theres something in your teeth'),
+ array('name' => 'Cab Driver', 'description' => 'Iam yellow'),
+ );
+
+ // Do insert batch
+ $this->assertTrue($this->db->insert_batch('job', $job_datas));
+ }
+
+}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 4d759fbb102b0754d7ff915458e27600bdc99d1d Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Fri, 6 Apr 2012 17:44:40 +0700
Subject: Remove temporary branch from build list
---
.travis.yml | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 971f62f38..97ea0422d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,5 +25,4 @@ script: phpunit --configuration tests/travis/$DB.phpunit.xml
branches:
only:
- develop
- - master
- - db-tests
\ No newline at end of file
+ - master
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 81b6b5d4ea2e63159c443bae19880a78f6ac2f9f Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Fri, 6 Apr 2012 17:58:22 +0700
Subject: Insert test
---
.travis.yml | 3 ++-
tests/codeigniter/database/query_builder/insert_test.php | 7 +++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 97ea0422d..971f62f38 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,4 +25,5 @@ script: phpunit --configuration tests/travis/$DB.phpunit.xml
branches:
only:
- develop
- - master
\ No newline at end of file
+ - master
+ - db-tests
\ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php
index 5607e8ce1..80073b9ba 100644
--- a/tests/codeigniter/database/query_builder/insert_test.php
+++ b/tests/codeigniter/database/query_builder/insert_test.php
@@ -12,7 +12,6 @@ class Insert_test extends CI_TestCase {
$this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
Mock_Database_Schema_Skeleton::create_tables();
- Mock_Database_Schema_Skeleton::create_data();
}
// ------------------------------------------------------------------------
@@ -22,7 +21,7 @@ class Insert_test extends CI_TestCase {
*/
public function test_insert()
{
- $job_data = array('name' => 'Grocery Sales', 'description' => 'Discount!');
+ $job_data = array('id' => 1, 'name' => 'Grocery Sales', 'description' => 'Discount!');
// Do normal insert
$this->assertTrue($this->db->insert('job', $job_data));
@@ -36,8 +35,8 @@ class Insert_test extends CI_TestCase {
public function test_insert_batch()
{
$job_datas = array(
- array('name' => 'Commedian', 'description' => 'Theres something in your teeth'),
- array('name' => 'Cab Driver', 'description' => 'Iam yellow'),
+ array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'),
+ array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'),
);
// Do insert batch
--
cgit v1.2.3-24-g4f1b
From fc92fc2e4f262a3607898ca7cd8b361d95f09136 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Fri, 6 Apr 2012 18:00:55 +0700
Subject: Add truncate
---
tests/codeigniter/database/query_builder/insert_test.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php
index 80073b9ba..78587d2e9 100644
--- a/tests/codeigniter/database/query_builder/insert_test.php
+++ b/tests/codeigniter/database/query_builder/insert_test.php
@@ -4,6 +4,7 @@ class Insert_test extends CI_TestCase {
/**
* @var object Database/Query Builder holder
+ * @see ./mocks/schema/skeleton.php
*/
protected $db;
@@ -12,6 +13,9 @@ class Insert_test extends CI_TestCase {
$this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
Mock_Database_Schema_Skeleton::create_tables();
+
+ // Truncate the current datas
+ $this->db->truncate('job');
}
// ------------------------------------------------------------------------
--
cgit v1.2.3-24-g4f1b
From c0dd3986b5cf45dcf9de42d761b9641836bc6c93 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Fri, 6 Apr 2012 18:05:10 +0700
Subject: Remove temporary branch from build list
---
.travis.yml | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 971f62f38..97ea0422d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,5 +25,4 @@ script: phpunit --configuration tests/travis/$DB.phpunit.xml
branches:
only:
- develop
- - master
- - db-tests
\ No newline at end of file
+ - master
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 80c0e3df5998a2a4b2376a6361f4690b783446df Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Sat, 7 Apr 2012 01:15:53 +0700
Subject: Check the insert result
---
tests/codeigniter/database/query_builder/insert_test.php | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php
index 78587d2e9..5dfccce82 100644
--- a/tests/codeigniter/database/query_builder/insert_test.php
+++ b/tests/codeigniter/database/query_builder/insert_test.php
@@ -29,6 +29,12 @@ class Insert_test extends CI_TestCase {
// Do normal insert
$this->assertTrue($this->db->insert('job', $job_data));
+
+ $job_1 = $this->db->get('job')->row();
+
+ // Check the result
+ $this->assertEquals('Grocery Sales', $job_1->name);
+
}
// ------------------------------------------------------------------------
@@ -45,6 +51,11 @@ class Insert_test extends CI_TestCase {
// Do insert batch
$this->assertTrue($this->db->insert_batch('job', $job_datas));
+
+ $job_2 = $this->db->get_where('job', array('id' => 2))->row();
+
+ // Check the result
+ $this->assertEquals('Commedian', $job_2->name);
}
}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 82e88b9b3031163d2f86f8e53450c1d779a08d8f Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Fri, 6 Apr 2012 21:18:59 +0300
Subject: Update _delete() and _update() with removal of unsupported LIMIT and
ORDER BY
---
system/database/drivers/postgre/postgre_driver.php | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index a5e296718..707aaaebe 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -493,11 +493,9 @@ class CI_DB_postgre_driver extends CI_DB {
* @param string the table name
* @param array the update data
* @param array the where clause
- * @param array the orderby clause
- * @param array the limit clause
* @return string
*/
- protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ protected function _update($table, $values, $where)
{
foreach ($values as $key => $val)
{
@@ -505,9 +503,7 @@ class CI_DB_postgre_driver extends CI_DB {
}
return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
- .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '')
- .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '')
- .( ! $limit ? '' : ' LIMIT '.$limit);
+ .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '');
}
// --------------------------------------------------------------------
@@ -519,10 +515,9 @@ class CI_DB_postgre_driver extends CI_DB {
*
* @param string the table name
* @param array the where clause
- * @param string the limit clause
* @return string
*/
- protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array())
{
if (count($where) > 0 OR count($like) > 0)
{
@@ -539,6 +534,7 @@ class CI_DB_postgre_driver extends CI_DB {
}
// --------------------------------------------------------------------
+
/**
* Limit string
*
--
cgit v1.2.3-24-g4f1b
From 8e160e471259ad01c0e994e7ce5797c2a51afd7a Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Fri, 6 Apr 2012 21:27:38 +0300
Subject: Fix changelog
---
user_guide_src/source/changelog.rst | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 665eba2a8..db3a57a4b 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -80,9 +80,6 @@ Release Date: Not Released
- db_set_charset() now only requires one parameter (collation was only needed due to legacy support for MySQL versions prior to 5.1).
- Added DSN string support for CUBRID.
- Added persistent connections support for CUBRID.
-<<<<<<< HEAD
- - CUBRID driver's utility class now overrides list_databases() in order to use cubrid_list_dbs().
-=======
- Added random ordering support for MSSQL.
- Added random ordering support for SQLSRV.
- Added support for SQLite3 database driver.
@@ -95,7 +92,7 @@ Release Date: Not Released
- num_rows() is now only called explicitly by the developer and no longer re-executes statements.
- Added replace() support for SQLite.
- Renamed internal method _escape_identifiers() to escape_identifiers().
->>>>>>> ea09a8a5552f2aacdeab0c88a605fe44047ebd0a
+ - CUBRID driver's utility class now overrides list_databases() in order to use cubrid_list_dbs().
- Libraries
--
cgit v1.2.3-24-g4f1b
From 9c9591c9b4a1d7ac412f7a85aeb5c92f50aa3490 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Fri, 6 Apr 2012 21:47:49 +0300
Subject: Fix erroneous merge
---
tests/mocks/autoloader.php | 79 ++++++++++++++
tests/mocks/ci_testcase.php | 196 +++++++++++++++++++++++++++++++++++
tests/mocks/core/common.php | 132 +++++++++++++++++++++++
tests/mocks/core/loader.php | 30 ++++++
tests/mocks/core/uri.php | 25 +++++
tests/mocks/libraries/parser.php | 3 +
tests/mocks/libraries/table.php | 15 +++
tests/mocks/libraries/typography.php | 3 +
tests/mocks/libraries/useragent.php | 3 +
9 files changed, 486 insertions(+)
create mode 100644 tests/mocks/autoloader.php
create mode 100644 tests/mocks/ci_testcase.php
create mode 100644 tests/mocks/core/common.php
create mode 100644 tests/mocks/core/loader.php
create mode 100644 tests/mocks/core/uri.php
create mode 100644 tests/mocks/libraries/parser.php
create mode 100644 tests/mocks/libraries/table.php
create mode 100644 tests/mocks/libraries/typography.php
create mode 100644 tests/mocks/libraries/useragent.php
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php
new file mode 100644
index 000000000..dd5929206
--- /dev/null
+++ b/tests/mocks/autoloader.php
@@ -0,0 +1,79 @@
+ 'bm',
+ 'config' => 'cfg',
+ 'hooks' => 'ext',
+ 'utf8' => 'uni',
+ 'router' => 'rtr',
+ 'output' => 'out',
+ 'security' => 'sec',
+ 'input' => 'in',
+ 'lang' => 'lang',
+ 'loader' => 'load',
+ 'model' => 'model'
+ );
+
+ // --------------------------------------------------------------------
+
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->ci_config = array();
+ }
+
+ // --------------------------------------------------------------------
+
+ public function setUp()
+ {
+ if (method_exists($this, 'set_up'))
+ {
+ $this->set_up();
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function tearDown()
+ {
+ if (method_exists($this, 'tear_down'))
+ {
+ $this->tear_down();
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public static function instance()
+ {
+ return self::$ci_test_instance;
+ }
+
+ // --------------------------------------------------------------------
+
+ function ci_set_config($key, $val = '')
+ {
+ if (is_array($key))
+ {
+ $this->ci_config = $key;
+ }
+ else
+ {
+ $this->ci_config[$key] = $val;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ function ci_get_config()
+ {
+ return $this->ci_config;
+ }
+
+ // --------------------------------------------------------------------
+
+ function ci_instance($obj = FALSE)
+ {
+ if ( ! is_object($obj))
+ {
+ return $this->ci_instance;
+ }
+
+ $this->ci_instance = $obj;
+ }
+
+ // --------------------------------------------------------------------
+
+ function ci_instance_var($name, $obj = FALSE)
+ {
+ if ( ! is_object($obj))
+ {
+ return $this->ci_instance->$name;
+ }
+
+ $this->ci_instance->$name =& $obj;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Grab a core class
+ *
+ * Loads the correct core class without extensions
+ * and returns a reference to the class name in the
+ * globals array with the correct key. This way the
+ * test can modify the variable it assigns to and
+ * still maintain the global.
+ */
+ function &ci_core_class($name)
+ {
+ $name = strtolower($name);
+
+ if (isset($this->global_map[$name]))
+ {
+ $class_name = ucfirst($name);
+ $global_name = $this->global_map[$name];
+ }
+ elseif (in_array($name, $this->global_map))
+ {
+ $class_name = ucfirst(array_search($name, $this->global_map));
+ $global_name = $name;
+ }
+ else
+ {
+ throw new Exception('Not a valid core class.');
+ }
+
+ if ( ! class_exists('CI_'.$class_name))
+ {
+ require_once BASEPATH.'core/'.$class_name.'.php';
+ }
+
+ $GLOBALS[strtoupper($global_name)] = 'CI_'.$class_name;
+ return $GLOBALS[strtoupper($global_name)];
+ }
+
+ // --------------------------------------------------------------------
+
+ // convenience function for global mocks
+ function ci_set_core_class($name, $obj)
+ {
+ $orig =& $this->ci_core_class($name);
+ $orig = $obj;
+ }
+
+ // --------------------------------------------------------------------
+ // Internals
+ // --------------------------------------------------------------------
+
+ /**
+ * Overwrite runBare
+ *
+ * PHPUnit instantiates the test classes before
+ * running them individually. So right before a test
+ * runs we set our instance. Normally this step would
+ * happen in setUp, but someone is bound to forget to
+ * call the parent method and debugging this is no fun.
+ */
+ public function runBare()
+ {
+ self::$ci_test_instance = $this;
+ parent::runBare();
+ }
+
+ // --------------------------------------------------------------------
+
+ function helper($name)
+ {
+ require_once(BASEPATH.'helpers/'.$name.'_helper.php');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * This overload is useful to create a stub, that need to have a specific method.
+ */
+ function __call($method, $args)
+ {
+ if ($this->{$method} instanceof Closure)
+ {
+ return call_user_func_array($this->{$method},$args);
+ }
+ else
+ {
+ return parent::__call($method, $args);
+ }
+ }
+}
+
+// EOF
\ No newline at end of file
diff --git a/tests/mocks/core/common.php b/tests/mocks/core/common.php
new file mode 100644
index 000000000..fc94d7fff
--- /dev/null
+++ b/tests/mocks/core/common.php
@@ -0,0 +1,132 @@
+ci_instance();
+ return $instance;
+}
+
+// --------------------------------------------------------------------
+
+function &get_config() {
+ $test = CI_TestCase::instance();
+ $config = $test->ci_get_config();
+
+ return $config;
+}
+
+function config_item($item)
+{
+ $config =& get_config();
+
+ if ( ! isset($config[$item]))
+ {
+ return FALSE;
+ }
+
+ return $config[$item];
+}
+
+// --------------------------------------------------------------------
+
+function load_class($class, $directory = 'libraries', $prefix = 'CI_')
+{
+ if ($directory != 'core' OR $prefix != 'CI_')
+ {
+ throw new Exception('Not Implemented: Non-core load_class()');
+ }
+
+ $test = CI_TestCase::instance();
+
+ $obj =& $test->ci_core_class($class);
+
+ if (is_string($obj))
+ {
+ throw new Exception('Bad Isolation: Use ci_set_core_class to set '.$class.'');
+ }
+
+ return $obj;
+}
+
+// This is sort of meh. Should probably be mocked up with
+// controllable output, so that we can test some of our
+// security code. The function itself will be tested in the
+// bootstrap testsuite.
+// --------------------------------------------------------------------
+
+function remove_invisible_characters($str, $url_encoded = TRUE)
+{
+ $non_displayables = array();
+
+ // every control character except newline (dec 10)
+ // carriage return (dec 13), and horizontal tab (dec 09)
+
+ if ($url_encoded)
+ {
+ $non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15
+ $non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31
+ }
+
+ $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127
+
+ do
+ {
+ $str = preg_replace($non_displayables, '', $str, -1, $count);
+ }
+ while ($count);
+
+ return $str;
+}
+
+
+// Clean up error messages
+// --------------------------------------------------------------------
+
+function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
+{
+ throw new RuntimeException('CI Error: '.$message);
+}
+
+function show_404($page = '', $log_error = TRUE)
+{
+ throw new RuntimeException('CI Error: 404');
+}
+
+function _exception_handler($severity, $message, $filepath, $line)
+{
+ throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line);
+}
+
+
+// We assume a few things about our environment ...
+// --------------------------------------------------------------------
+
+function is_php($version = '5.0.0')
+{
+ return ! (version_compare(PHP_VERSION, $version) < 0);
+}
+
+function is_really_writable($file)
+{
+ return is_writable($file);
+}
+
+function is_loaded()
+{
+ throw new Exception('Bad Isolation: mock up environment');
+}
+
+function log_message($level = 'error', $message, $php_error = FALSE)
+{
+ return TRUE;
+}
+
+function set_status_header($code = 200, $text = '')
+{
+ return TRUE;
+}
+
+// EOF
\ No newline at end of file
diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php
new file mode 100644
index 000000000..d4b29bb3d
--- /dev/null
+++ b/tests/mocks/core/loader.php
@@ -0,0 +1,30 @@
+models_dir = vfsStream::newDirectory('models')->at(vfsStreamWrapper::getRoot());
+ $this->libs_dir = vfsStream::newDirectory('libraries')->at(vfsStreamWrapper::getRoot());
+ $this->helpers_dir = vfsStream::newDirectory('helpers')->at(vfsStreamWrapper::getRoot());
+ $this->views_dir = vfsStream::newDirectory('views')->at(vfsStreamWrapper::getRoot());
+
+ $this->_ci_ob_level = ob_get_level();
+ $this->_ci_library_paths = array(vfsStream::url('application').'/', BASEPATH);
+ $this->_ci_helper_paths = array(vfsStream::url('application').'/', BASEPATH);
+ $this->_ci_model_paths = array(vfsStream::url('application').'/');
+ $this->_ci_view_paths = array(vfsStream::url('application').'/views/' => TRUE);
+ }
+}
\ No newline at end of file
diff --git a/tests/mocks/core/uri.php b/tests/mocks/core/uri.php
new file mode 100644
index 000000000..b6946091e
--- /dev/null
+++ b/tests/mocks/core/uri.php
@@ -0,0 +1,25 @@
+ci_core_class('cfg');
+
+ // set predictable config values
+ $test->ci_set_config(array(
+ 'index_page' => 'index.php',
+ 'base_url' => 'http://example.com/',
+ 'subclass_prefix' => 'MY_'
+ ));
+
+ $this->config = new $cls;
+
+ }
+
+ protected function _is_cli_request()
+ {
+ return FALSE;
+ }
+}
\ No newline at end of file
diff --git a/tests/mocks/libraries/parser.php b/tests/mocks/libraries/parser.php
new file mode 100644
index 000000000..81dcfb37e
--- /dev/null
+++ b/tests/mocks/libraries/parser.php
@@ -0,0 +1,3 @@
+
Date: Sat, 7 Apr 2012 02:09:11 +0700
Subject: Update reference and do the tests
---
.travis.yml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index 97ea0422d..971f62f38 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,4 +25,5 @@ script: phpunit --configuration tests/travis/$DB.phpunit.xml
branches:
only:
- develop
- - master
\ No newline at end of file
+ - master
+ - db-tests
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From d489747059db6a91d5532f35437a812a81f2b98b Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Sat, 7 Apr 2012 03:16:25 +0700
Subject: Remove batch test from sqlite
---
.../database/query_builder/insert_test.php | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php
index 5dfccce82..b86feeb74 100644
--- a/tests/codeigniter/database/query_builder/insert_test.php
+++ b/tests/codeigniter/database/query_builder/insert_test.php
@@ -30,10 +30,11 @@ class Insert_test extends CI_TestCase {
// Do normal insert
$this->assertTrue($this->db->insert('job', $job_data));
- $job_1 = $this->db->get('job')->row();
+ $jobs = $this->db->get('job')->result_array();
+ $job1 = $jobs[0];
// Check the result
- $this->assertEquals('Grocery Sales', $job_1->name);
+ $this->assertEquals('Grocery Sales', $job1['name']);
}
@@ -49,13 +50,18 @@ class Insert_test extends CI_TestCase {
array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'),
);
- // Do insert batch
- $this->assertTrue($this->db->insert_batch('job', $job_datas));
+ // Do insert batch except for sqlite driver
+ if (strpos(DB_DRIVER, 'sqlite') === FALSE)
+ {
+ $this->assertTrue($this->db->insert('job', $job_datas[0]));
- $job_2 = $this->db->get_where('job', array('id' => 2))->row();
+ $job_2 = $this->db->where('id', 2)->get('job')->row();
+ $job_3 = $this->db->where('id', 3)->get('job')->row();
- // Check the result
- $this->assertEquals('Commedian', $job_2->name);
+ // Check the result
+ $this->assertEquals('Commedian', $job_2->name);
+ $this->assertEquals('Cab Driver', $job_3->name);
+ }
}
}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 5ce26c912f11fb859e661a43a6667fba5a5a3ca2 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Sat, 7 Apr 2012 03:19:35 +0700
Subject: Typo
---
tests/codeigniter/database/query_builder/insert_test.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php
index b86feeb74..53ce23c19 100644
--- a/tests/codeigniter/database/query_builder/insert_test.php
+++ b/tests/codeigniter/database/query_builder/insert_test.php
@@ -53,7 +53,7 @@ class Insert_test extends CI_TestCase {
// Do insert batch except for sqlite driver
if (strpos(DB_DRIVER, 'sqlite') === FALSE)
{
- $this->assertTrue($this->db->insert('job', $job_datas[0]));
+ $this->assertTrue($this->db->insert_batch('job', $job_datas));
$job_2 = $this->db->where('id', 2)->get('job')->row();
$job_3 = $this->db->where('id', 3)->get('job')->row();
--
cgit v1.2.3-24-g4f1b
From d115f8327a8f16d957cc4e0876225037bb2f5868 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Sat, 7 Apr 2012 03:22:39 +0700
Subject: Remove temporary branch from build list
---
.travis.yml | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 971f62f38..97ea0422d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,5 +25,4 @@ script: phpunit --configuration tests/travis/$DB.phpunit.xml
branches:
only:
- develop
- - master
- - db-tests
\ No newline at end of file
+ - master
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 416f360a19118c4692e430f0a1f5d12f81876ee7 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Mon, 9 Apr 2012 16:32:25 +0300
Subject: Fix changelog merge conflict
---
user_guide_src/source/changelog.rst | 4 ----
1 file changed, 4 deletions(-)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 6b47437d6..8146a5139 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -90,15 +90,11 @@ Release Date: Not Released
- num_rows() is now only called explicitly by the developer and no longer re-executes statements.
- Added replace() support for SQLite.
- Renamed internal method _escape_identifiers() to escape_identifiers().
-<<<<<<< HEAD
- - CUBRID driver's utility class now overrides list_databases() in order to use cubrid_list_dbs().
-=======
- Added SQLite support for drop_table() in :doc:`Database Forge `.
- Added ODBC support for create_database(), drop_database() and drop_table() in :doc:`Database Forge `.
- Added PDO support for create_database(), drop_database and drop_table() in :doc:`Database Forge `.
- Added MSSQL, SQLSRV support for optimize_table() in :doc:`Database Utility `.
- Improved CUBRID support for list_databases() in :doc:`Database Utility ` (until now only the currently used database was returned).
->>>>>>> 918be7963f6fa3461d612ea7ca4c9774c12f9da5
- Libraries
--
cgit v1.2.3-24-g4f1b
From fb61edcf8fb31f91cf53527604446be7dd5bd4be Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Tue, 10 Apr 2012 14:04:12 +0300
Subject: Add back an unused argument to _delete() due to CI_DB_driver being
abstract
---
system/database/drivers/postgre/postgre_driver.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 2a842848c..93d4c6bf5 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -528,7 +528,7 @@ class CI_DB_postgre_driver extends CI_DB {
* @param string the limit clause (ignored)
* @return string
*/
- protected function _delete($table, $where = array(), $like = array())
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = array();
--
cgit v1.2.3-24-g4f1b
From 3684d349d1f5239ad9703c07f14ae77389818daf Mon Sep 17 00:00:00 2001
From: Korri
Date: Tue, 17 Apr 2012 00:35:08 -0400
Subject: Adding a package adds configuration folder to the end of the list.
---
system/core/Loader.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/system/core/Loader.php b/system/core/Loader.php
index 027ed20e5..a4039c6f0 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -673,7 +673,7 @@ class CI_Loader {
// Add config file path
$config =& $this->_ci_get_component('config');
- array_unshift($config->_config_paths, $path);
+ array_push($config->_config_paths, $path);
}
// --------------------------------------------------------------------
@@ -713,7 +713,7 @@ class CI_Loader {
array_shift($this->_ci_model_paths);
array_shift($this->_ci_helper_paths);
array_shift($this->_ci_view_paths);
- array_shift($config->_config_paths);
+ array_pop($config->_config_paths);
}
else
{
--
cgit v1.2.3-24-g4f1b
From ad4750509885ad5bb368fc308f86d8c06d45b15c Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Thu, 19 Apr 2012 13:21:06 -0400
Subject: Normalize comments in core files
---
system/core/CodeIgniter.php | 7 +
system/core/Common.php | 341 ++++++++++++++++++++++----------------------
system/core/Config.php | 1 -
system/core/Controller.php | 13 ++
system/core/Exceptions.php | 9 +-
system/core/Lang.php | 3 +
system/core/Loader.php | 2 -
system/core/Model.php | 3 +
system/core/Output.php | 10 ++
system/core/Router.php | 1 -
system/core/Security.php | 11 +-
11 files changed, 217 insertions(+), 184 deletions(-)
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index 4885f310c..9714d095c 100755
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
@@ -230,6 +230,13 @@
// Load the base controller class
require BASEPATH.'core/Controller.php';
+ /**
+ * Reference to the CI_Controller method.
+ *
+ * Returns current CI instance object
+ *
+ * @return object
+ */
function &get_instance()
{
return CI_Controller::get_instance();
diff --git a/system/core/Common.php b/system/core/Common.php
index aeb784bbe..075b221bd 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -39,17 +39,18 @@
// ------------------------------------------------------------------------
-/**
- * Determines if the current version of PHP is greater then the supplied value
- *
- * Since there are a few places where we conditionally test for PHP > 5
- * we'll set a static variable.
- *
- * @param string
- * @return bool TRUE if the current version is $version or higher
- */
+
if ( ! function_exists('is_php'))
{
+ /**
+ * Determines if the current version of PHP is greater then the supplied value
+ *
+ * Since there are a few places where we conditionally test for PHP > 5
+ * we'll set a static variable.
+ *
+ * @param string
+ * @return bool TRUE if the current version is $version or higher
+ */
function is_php($version = '5.0.0')
{
static $_is_php;
@@ -66,18 +67,18 @@ if ( ! function_exists('is_php'))
// ------------------------------------------------------------------------
-/**
- * Tests for file writability
- *
- * is_writable() returns TRUE on Windows servers when you really can't write to
- * the file, based on the read-only attribute. is_writable() is also unreliable
- * on Unix servers if safe_mode is on.
- *
- * @param string
- * @return void
- */
if ( ! function_exists('is_really_writable'))
{
+ /**
+ * Tests for file writability
+ *
+ * is_writable() returns TRUE on Windows servers when you really can't write to
+ * the file, based on the read-only attribute. is_writable() is also unreliable
+ * on Unix servers if safe_mode is on.
+ *
+ * @param string
+ * @return void
+ */
function is_really_writable($file)
{
// If we're on a Unix server with safe_mode off we call is_writable
@@ -114,20 +115,20 @@ if ( ! function_exists('is_really_writable'))
// ------------------------------------------------------------------------
-/**
- * Class registry
- *
- * This function acts as a singleton. If the requested class does not
- * exist it is instantiated and set to a static variable. If it has
- * previously been instantiated the variable is returned.
- *
- * @param string the class name being requested
- * @param string the directory where the class should be found
- * @param string the class name prefix
- * @return object
- */
if ( ! function_exists('load_class'))
{
+ /**
+ * Class registry
+ *
+ * This function acts as a singleton. If the requested class does not
+ * exist it is instantiated and set to a static variable. If it has
+ * previously been instantiated the variable is returned.
+ *
+ * @param string the class name being requested
+ * @param string the directory where the class should be found
+ * @param string the class name prefix
+ * @return object
+ */
function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
{
static $_classes = array();
@@ -187,15 +188,15 @@ if ( ! function_exists('load_class'))
// --------------------------------------------------------------------
-/**
- * Keeps track of which libraries have been loaded. This function is
- * called by the load_class() function above
- *
- * @param string
- * @return array
- */
if ( ! function_exists('is_loaded'))
{
+ /**
+ * Keeps track of which libraries have been loaded. This function is
+ * called by the load_class() function above
+ *
+ * @param string
+ * @return array
+ */
function &is_loaded($class = '')
{
static $_is_loaded = array();
@@ -211,17 +212,17 @@ if ( ! function_exists('is_loaded'))
// ------------------------------------------------------------------------
-/**
- * Loads the main config.php file
- *
- * This function lets us grab the config file even if the Config class
- * hasn't been instantiated yet
- *
- * @param array
- * @return array
- */
if ( ! function_exists('get_config'))
{
+ /**
+ * Loads the main config.php file
+ *
+ * This function lets us grab the config file even if the Config class
+ * hasn't been instantiated yet
+ *
+ * @param array
+ * @return array
+ */
function &get_config($replace = array())
{
static $_config;
@@ -271,14 +272,14 @@ if ( ! function_exists('get_config'))
// ------------------------------------------------------------------------
-/**
- * Returns the specified config item
- *
- * @param string
- * @return mixed
- */
if ( ! function_exists('config_item'))
{
+ /**
+ * Returns the specified config item
+ *
+ * @param string
+ * @return mixed
+ */
function config_item($item)
{
static $_config_item = array();
@@ -300,22 +301,22 @@ if ( ! function_exists('config_item'))
// ------------------------------------------------------------------------
-/**
- * Error Handler
- *
- * This function lets us invoke the exception class and
- * display errors using the standard error template located
- * in application/errors/errors.php
- * This function will send the error page directly to the
- * browser and exit.
- *
- * @param string
- * @param int
- * @param string
- * @return void
- */
if ( ! function_exists('show_error'))
{
+ /**
+ * Error Handler
+ *
+ * This function lets us invoke the exception class and
+ * display errors using the standard error template located
+ * in application/errors/errors.php
+ * This function will send the error page directly to the
+ * browser and exit.
+ *
+ * @param string
+ * @param int
+ * @param string
+ * @return void
+ */
function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
{
$_error =& load_class('Exceptions', 'core');
@@ -326,19 +327,19 @@ if ( ! function_exists('show_error'))
// ------------------------------------------------------------------------
-/**
- * 404 Page Handler
- *
- * This function is similar to the show_error() function above
- * However, instead of the standard error template it displays
- * 404 errors.
- *
- * @param string
- * @param bool
- * @return void
- */
if ( ! function_exists('show_404'))
{
+ /**
+ * 404 Page Handler
+ *
+ * This function is similar to the show_error() function above
+ * However, instead of the standard error template it displays
+ * 404 errors.
+ *
+ * @param string
+ * @param bool
+ * @return void
+ */
function show_404($page = '', $log_error = TRUE)
{
$_error =& load_class('Exceptions', 'core');
@@ -349,19 +350,19 @@ if ( ! function_exists('show_404'))
// ------------------------------------------------------------------------
-/**
- * Error Logging Interface
- *
- * We use this as a simple mechanism to access the logging
- * class and send messages to be logged.
- *
- * @param string
- * @param string
- * @param bool
- * @return void
- */
if ( ! function_exists('log_message'))
{
+ /**
+ * Error Logging Interface
+ *
+ * We use this as a simple mechanism to access the logging
+ * class and send messages to be logged.
+ *
+ * @param string
+ * @param string
+ * @param bool
+ * @return void
+ */
function log_message($level = 'error', $message, $php_error = FALSE)
{
static $_log;
@@ -378,59 +379,59 @@ if ( ! function_exists('log_message'))
// ------------------------------------------------------------------------
-/**
- * Set HTTP Status Header
- *
- * @param int the status code
- * @param string
- * @return void
- */
if ( ! function_exists('set_status_header'))
{
+ /**
+ * Set HTTP Status Header
+ *
+ * @param int the status code
+ * @param string
+ * @return void
+ */
function set_status_header($code = 200, $text = '')
{
$stati = array(
- 200 => 'OK',
- 201 => 'Created',
- 202 => 'Accepted',
- 203 => 'Non-Authoritative Information',
- 204 => 'No Content',
- 205 => 'Reset Content',
- 206 => 'Partial Content',
-
- 300 => 'Multiple Choices',
- 301 => 'Moved Permanently',
- 302 => 'Found',
- 304 => 'Not Modified',
- 305 => 'Use Proxy',
- 307 => 'Temporary Redirect',
-
- 400 => 'Bad Request',
- 401 => 'Unauthorized',
- 403 => 'Forbidden',
- 404 => 'Not Found',
- 405 => 'Method Not Allowed',
- 406 => 'Not Acceptable',
- 407 => 'Proxy Authentication Required',
- 408 => 'Request Timeout',
- 409 => 'Conflict',
- 410 => 'Gone',
- 411 => 'Length Required',
- 412 => 'Precondition Failed',
- 413 => 'Request Entity Too Large',
- 414 => 'Request-URI Too Long',
- 415 => 'Unsupported Media Type',
- 416 => 'Requested Range Not Satisfiable',
- 417 => 'Expectation Failed',
- 422 => 'Unprocessable Entity',
-
- 500 => 'Internal Server Error',
- 501 => 'Not Implemented',
- 502 => 'Bad Gateway',
- 503 => 'Service Unavailable',
- 504 => 'Gateway Timeout',
- 505 => 'HTTP Version Not Supported'
- );
+ 200 => 'OK',
+ 201 => 'Created',
+ 202 => 'Accepted',
+ 203 => 'Non-Authoritative Information',
+ 204 => 'No Content',
+ 205 => 'Reset Content',
+ 206 => 'Partial Content',
+
+ 300 => 'Multiple Choices',
+ 301 => 'Moved Permanently',
+ 302 => 'Found',
+ 304 => 'Not Modified',
+ 305 => 'Use Proxy',
+ 307 => 'Temporary Redirect',
+
+ 400 => 'Bad Request',
+ 401 => 'Unauthorized',
+ 403 => 'Forbidden',
+ 404 => 'Not Found',
+ 405 => 'Method Not Allowed',
+ 406 => 'Not Acceptable',
+ 407 => 'Proxy Authentication Required',
+ 408 => 'Request Timeout',
+ 409 => 'Conflict',
+ 410 => 'Gone',
+ 411 => 'Length Required',
+ 412 => 'Precondition Failed',
+ 413 => 'Request Entity Too Large',
+ 414 => 'Request-URI Too Long',
+ 415 => 'Unsupported Media Type',
+ 416 => 'Requested Range Not Satisfiable',
+ 417 => 'Expectation Failed',
+ 422 => 'Unprocessable Entity',
+
+ 500 => 'Internal Server Error',
+ 501 => 'Not Implemented',
+ 502 => 'Bad Gateway',
+ 503 => 'Service Unavailable',
+ 504 => 'Gateway Timeout',
+ 505 => 'HTTP Version Not Supported'
+ );
if ($code == '' OR ! is_numeric($code))
{
@@ -466,25 +467,25 @@ if ( ! function_exists('set_status_header'))
// --------------------------------------------------------------------
-/**
- * Exception Handler
- *
- * This is the custom exception handler that is declaired at the top
- * of Codeigniter.php. The main reason we use this is to permit
- * PHP errors to be logged in our own log files since the user may
- * not have access to server logs. Since this function
- * effectively intercepts PHP errors, however, we also need
- * to display errors based on the current error_reporting level.
- * We do that with the use of a PHP error template.
- *
- * @param int
- * @param string
- * @param string
- * @param int
- * @return void
- */
if ( ! function_exists('_exception_handler'))
{
+ /**
+ * Exception Handler
+ *
+ * This is the custom exception handler that is declaired at the top
+ * of Codeigniter.php. The main reason we use this is to permit
+ * PHP errors to be logged in our own log files since the user may
+ * not have access to server logs. Since this function
+ * effectively intercepts PHP errors, however, we also need
+ * to display errors based on the current error_reporting level.
+ * We do that with the use of a PHP error template.
+ *
+ * @param int
+ * @param string
+ * @param string
+ * @param int
+ * @return void
+ */
function _exception_handler($severity, $message, $filepath, $line)
{
// We don't bother with "strict" notices since they tend to fill up
@@ -518,18 +519,18 @@ if ( ! function_exists('_exception_handler'))
// --------------------------------------------------------------------
-/**
- * Remove Invisible Characters
- *
- * This prevents sandwiching null characters
- * between ascii characters, like Java\0script.
- *
- * @param string
- * @param bool
- * @return string
- */
if ( ! function_exists('remove_invisible_characters'))
{
+ /**
+ * Remove Invisible Characters
+ *
+ * This prevents sandwiching null characters
+ * between ascii characters, like Java\0script.
+ *
+ * @param string
+ * @param bool
+ * @return string
+ */
function remove_invisible_characters($str, $url_encoded = TRUE)
{
$non_displayables = array();
@@ -556,14 +557,14 @@ if ( ! function_exists('remove_invisible_characters'))
// ------------------------------------------------------------------------
-/**
- * Returns HTML escaped variable
- *
- * @param mixed
- * @return mixed
- */
if ( ! function_exists('html_escape'))
{
+ /**
+ * Returns HTML escaped variable
+ *
+ * @param mixed
+ * @return mixed
+ */
function html_escape($var)
{
return is_array($var)
diff --git a/system/core/Config.php b/system/core/Config.php
index 91826bd41..e94362912 100755
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -188,7 +188,6 @@ class CI_Config {
/**
* Fetch a config file item
*
- *
* @param string the config item name
* @param string the index name
* @param bool
diff --git a/system/core/Controller.php b/system/core/Controller.php
index 05e1bf5bf..e73e887a0 100644
--- a/system/core/Controller.php
+++ b/system/core/Controller.php
@@ -41,8 +41,16 @@
*/
class CI_Controller {
+ /**
+ * Reference to the global CI instance
+ *
+ * @var object
+ */
private static $instance;
+ /**
+ * Set up controller properties and methods
+ */
public function __construct()
{
self::$instance =& $this;
@@ -60,6 +68,11 @@ class CI_Controller {
log_message('debug', 'Controller Class Initialized');
}
+ /**
+ * Return the CI object
+ *
+ * @return object
+ */
public static function &get_instance()
{
return self::$instance;
diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php
index f36b31598..dd5841333 100755
--- a/system/core/Exceptions.php
+++ b/system/core/Exceptions.php
@@ -36,12 +36,6 @@
*/
class CI_Exceptions {
- public $action;
- public $severity;
- public $message;
- public $filename;
- public $line;
-
/**
* Nesting level of the output buffering mechanism
*
@@ -69,6 +63,9 @@ class CI_Exceptions {
E_STRICT => 'Runtime Notice'
);
+ /**
+ * Initialize execption class
+ */
public function __construct()
{
$this->ob_level = ob_get_level();
diff --git a/system/core/Lang.php b/system/core/Lang.php
index 9ef76f4d6..82013844c 100755
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
@@ -51,6 +51,9 @@ class CI_Lang {
*/
public $is_loaded = array();
+ /**
+ * Initialize language class
+ */
public function __construct()
{
log_message('debug', 'Language Class Initialized');
diff --git a/system/core/Loader.php b/system/core/Loader.php
index 027ed20e5..e1531843a 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -138,7 +138,6 @@ class CI_Loader {
*
* This method is called once in CI_Controller.
*
- * @param array
* @return object
*/
public function initialize()
@@ -1123,7 +1122,6 @@ class CI_Loader {
* The config/autoload.php file contains an array that permits sub-systems,
* libraries, and helpers to be loaded automatically.
*
- * @param array
* @return void
*/
protected function _ci_autoloader()
diff --git a/system/core/Model.php b/system/core/Model.php
index 49b8d34e4..3855d49e7 100755
--- a/system/core/Model.php
+++ b/system/core/Model.php
@@ -38,6 +38,9 @@
*/
class CI_Model {
+ /**
+ * Initialize CI_Model Class
+ */
public function __construct()
{
log_message('debug', 'Model Class Initialized');
diff --git a/system/core/Output.php b/system/core/Output.php
index 3cb40626a..671303094 100755
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -44,42 +44,49 @@ class CI_Output {
* @var string
*/
public $final_output;
+
/**
* Cache expiration time
*
* @var int
*/
public $cache_expiration = 0;
+
/**
* List of server headers
*
* @var array
*/
public $headers = array();
+
/**
* List of mime types
*
* @var array
*/
public $mime_types = array();
+
/**
* Determines wether profiler is enabled
*
* @var book
*/
public $enable_profiler = FALSE;
+
/**
* Determines if output compression is enabled
*
* @var bool
*/
protected $_zlib_oc = FALSE;
+
/**
* List of profiler sections
*
* @var array
*/
protected $_profiler_sections = array();
+
/**
* Whether or not to parse variables like {elapsed_time} and {memory_usage}
*
@@ -87,6 +94,9 @@ class CI_Output {
*/
public $parse_exec_vars = TRUE;
+ /**
+ * Set up Output class
+ */
public function __construct()
{
$this->_zlib_oc = @ini_get('zlib.output_compression');
diff --git a/system/core/Router.php b/system/core/Router.php
index 5477fed5d..b34911859 100755
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -211,7 +211,6 @@ class CI_Router {
* input, and sets the current class/method
*
* @param array
- * @param bool
* @return void
*/
protected function _set_request($segments = array())
diff --git a/system/core/Security.php b/system/core/Security.php
index ac39ce97b..8d81babf2 100755
--- a/system/core/Security.php
+++ b/system/core/Security.php
@@ -102,6 +102,9 @@ class CI_Security {
'Redirect\s+302'
);
+ /**
+ * Initialize security class
+ */
public function __construct()
{
// Is CSRF protection enabled?
@@ -558,8 +561,8 @@ class CI_Security {
* Callback function for xss_clean() to remove whitespace from
* things like j a v a s c r i p t
*
- * @param type
- * @return type
+ * @param array
+ * @return string
*/
protected function _compact_exploded_words($matches)
{
@@ -568,8 +571,8 @@ class CI_Security {
// --------------------------------------------------------------------
- /*
- * Remove Evil HTML Attributes (like evenhandlers and style)
+ /**
+ * Remove Evil HTML Attributes (like event handlers and style)
*
* It removes the evil attribute and either:
* - Everything up until a space
--
cgit v1.2.3-24-g4f1b
From 40403d21274d5e0792c7ab816ad984d6387d5c20 Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Thu, 19 Apr 2012 16:38:50 -0400
Subject: Additional formatting fixes
---
system/core/Config.php | 4 +-
system/core/Controller.php | 4 +-
system/core/Exceptions.php | 26 +++---
system/core/Hooks.php | 6 +-
system/core/Input.php | 221 +++++++++++++++++++++++++--------------------
system/core/Lang.php | 9 +-
system/core/Loader.php | 39 +++++---
system/core/Model.php | 4 +-
system/core/Output.php | 12 +--
system/core/Router.php | 16 +++-
system/core/Security.php | 84 ++++++++---------
system/core/URI.php | 18 ++--
system/core/Utf8.php | 4 +-
13 files changed, 243 insertions(+), 204 deletions(-)
diff --git a/system/core/Config.php b/system/core/Config.php
index e94362912..fc6183444 100755
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -46,12 +46,14 @@ class CI_Config {
* @var array
*/
public $config = array();
+
/**
* List of all loaded config files
*
* @var array
*/
public $is_loaded = array();
+
/**
* List of paths to search when trying to load a config file.
* This must be public as it's used by the Loader class.
@@ -353,4 +355,4 @@ class CI_Config {
}
/* End of file Config.php */
-/* Location: ./system/core/Config.php */
+/* Location: ./system/core/Config.php */
\ No newline at end of file
diff --git a/system/core/Controller.php b/system/core/Controller.php
index e73e887a0..0c6c47183 100644
--- a/system/core/Controller.php
+++ b/system/core/Controller.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Application Controller Class
*
@@ -80,4 +78,4 @@ class CI_Controller {
}
/* End of file Controller.php */
-/* Location: ./system/core/Controller.php */
+/* Location: ./system/core/Controller.php */
\ No newline at end of file
diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php
index dd5841333..f55f9fcba 100755
--- a/system/core/Exceptions.php
+++ b/system/core/Exceptions.php
@@ -49,19 +49,19 @@ class CI_Exceptions {
* @var array
*/
public $levels = array(
- E_ERROR => 'Error',
- E_WARNING => 'Warning',
- E_PARSE => 'Parsing Error',
- E_NOTICE => 'Notice',
- E_CORE_ERROR => 'Core Error',
- E_CORE_WARNING => 'Core Warning',
- E_COMPILE_ERROR => 'Compile Error',
- E_COMPILE_WARNING => 'Compile Warning',
- E_USER_ERROR => 'User Error',
- E_USER_WARNING => 'User Warning',
- E_USER_NOTICE => 'User Notice',
- E_STRICT => 'Runtime Notice'
- );
+ E_ERROR => 'Error',
+ E_WARNING => 'Warning',
+ E_PARSE => 'Parsing Error',
+ E_NOTICE => 'Notice',
+ E_CORE_ERROR => 'Core Error',
+ E_CORE_WARNING => 'Core Warning',
+ E_COMPILE_ERROR => 'Compile Error',
+ E_COMPILE_WARNING => 'Compile Warning',
+ E_USER_ERROR => 'User Error',
+ E_USER_WARNING => 'User Warning',
+ E_USER_NOTICE => 'User Notice',
+ E_STRICT => 'Runtime Notice'
+ );
/**
* Initialize execption class
diff --git a/system/core/Hooks.php b/system/core/Hooks.php
index 68e30ef0f..672fe29dd 100755
--- a/system/core/Hooks.php
+++ b/system/core/Hooks.php
@@ -43,13 +43,15 @@ class CI_Hooks {
*
* @var bool
*/
- public $enabled = FALSE;
+ public $enabled = FALSE;
+
/**
* List of all hooks set in config/hooks.php
*
* @var array
*/
- public $hooks = array();
+ public $hooks = array();
+
/**
* Determines wether hook is in progress, used to prevent infinte loops
*
diff --git a/system/core/Input.php b/system/core/Input.php
index 6e6885992..049935632 100755
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -43,45 +43,51 @@ class CI_Input {
*
* @var string
*/
- public $ip_address = FALSE;
+ public $ip_address = FALSE;
+
/**
* user agent (web browser) being used by the current user
*
* @var string
*/
- public $user_agent = FALSE;
+ public $user_agent = FALSE;
+
/**
* If FALSE, then $_GET will be set to an empty array
*
* @var bool
*/
- protected $_allow_get_array = TRUE;
+ protected $_allow_get_array = TRUE;
+
/**
* If TRUE, then newlines are standardized
*
* @var bool
*/
- protected $_standardize_newlines = TRUE;
+ protected $_standardize_newlines = TRUE;
+
/**
* Determines whether the XSS filter is always active when GET, POST or COOKIE data is encountered
* Set automatically based on config setting
*
* @var bool
*/
- protected $_enable_xss = FALSE;
+ protected $_enable_xss = FALSE;
+
/**
* Enables a CSRF cookie token to be set.
* Set automatically based on config setting
*
* @var bool
*/
- protected $_enable_csrf = FALSE;
+ protected $_enable_csrf = FALSE;
+
/**
* List of all HTTP request headers
*
* @var array
*/
- protected $headers = array();
+ protected $headers = array();
/**
* Constructor
@@ -141,12 +147,12 @@ class CI_Input {
// --------------------------------------------------------------------
/**
- * Fetch an item from the GET array
- *
- * @param string
- * @param bool
- * @return string
- */
+ * Fetch an item from the GET array
+ *
+ * @param string
+ * @param bool
+ * @return string
+ */
public function get($index = NULL, $xss_clean = FALSE)
{
// Check if a field has been provided
@@ -168,12 +174,12 @@ class CI_Input {
// --------------------------------------------------------------------
/**
- * Fetch an item from the POST array
- *
- * @param string
- * @param bool
- * @return string
- */
+ * Fetch an item from the POST array
+ *
+ * @param string
+ * @param bool
+ * @return string
+ */
public function post($index = NULL, $xss_clean = FALSE)
{
// Check if a field has been provided
@@ -196,12 +202,12 @@ class CI_Input {
// --------------------------------------------------------------------
/**
- * Fetch an item from either the GET array or the POST
- *
- * @param string The index key
- * @param bool XSS cleaning
- * @return string
- */
+ * Fetch an item from either the GET array or the POST
+ *
+ * @param string The index key
+ * @param bool XSS cleaning
+ * @return string
+ */
public function get_post($index = '', $xss_clean = FALSE)
{
return isset($_POST[$index])
@@ -212,12 +218,12 @@ class CI_Input {
// --------------------------------------------------------------------
/**
- * Fetch an item from the COOKIE array
- *
- * @param string
- * @param bool
- * @return string
- */
+ * Fetch an item from the COOKIE array
+ *
+ * @param string
+ * @param bool
+ * @return string
+ */
public function cookie($index = '', $xss_clean = FALSE)
{
return $this->_fetch_from_array($_COOKIE, $index, $xss_clean);
@@ -226,21 +232,21 @@ class CI_Input {
// ------------------------------------------------------------------------
/**
- * Set cookie
- *
- * Accepts seven parameters, or you can submit an associative
- * array in the first parameter containing all the values.
- *
- * @param mixed
- * @param string the value of the cookie
- * @param string the number of seconds until expiration
- * @param string the cookie domain. Usually: .yourdomain.com
- * @param string the cookie path
- * @param string the cookie prefix
- * @param bool true makes the cookie secure
- * @param bool true makes the cookie accessible via http(s) only (no javascript)
- * @return void
- */
+ * Set cookie
+ *
+ * Accepts seven parameters, or you can submit an associative
+ * array in the first parameter containing all the values.
+ *
+ * @param mixed
+ * @param string the value of the cookie
+ * @param string the number of seconds until expiration
+ * @param string the cookie domain. Usually: .yourdomain.com
+ * @param string the cookie path
+ * @param string the cookie prefix
+ * @param bool true makes the cookie secure
+ * @param bool true makes the cookie accessible via http(s) only (no javascript)
+ * @return void
+ */
public function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE, $httponly = FALSE)
{
if (is_array($name))
@@ -291,12 +297,12 @@ class CI_Input {
// --------------------------------------------------------------------
/**
- * Fetch an item from the SERVER array
- *
- * @param string
- * @param bool
- * @return string
- */
+ * Fetch an item from the SERVER array
+ *
+ * @param string
+ * @param bool
+ * @return string
+ */
public function server($index = '', $xss_clean = FALSE)
{
return $this->_fetch_from_array($_SERVER, $index, $xss_clean);
@@ -305,10 +311,10 @@ class CI_Input {
// --------------------------------------------------------------------
/**
- * Fetch the IP Address
- *
- * @return string
- */
+ * Fetch the IP Address
+ *
+ * @return string
+ */
public function ip_address()
{
if ($this->ip_address !== FALSE)
@@ -362,13 +368,13 @@ class CI_Input {
// --------------------------------------------------------------------
/**
- * Validate IP Address
- *
- * Updated version suggested by Geert De Deckere
- *
- * @param string
- * @return bool
- */
+ * Validate IP Address
+ *
+ * Updated version suggested by Geert De Deckere
+ *
+ * @param string
+ * @return bool
+ */
public function valid_ip($ip)
{
return (bool) filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
@@ -377,10 +383,10 @@ class CI_Input {
// --------------------------------------------------------------------
/**
- * User Agent
- *
- * @return string
- */
+ * User Agent
+ *
+ * @return string
+ */
public function user_agent()
{
if ($this->user_agent !== FALSE)
@@ -394,24 +400,39 @@ class CI_Input {
// --------------------------------------------------------------------
/**
- * Sanitize Globals
- *
- * This function does the following:
- *
- * - Unsets $_GET data (if query strings are not enabled)
- * - Unsets all globals if register_globals is enabled
- * - Standardizes newline characters to \n
- *
- * @return void
- */
+ * Sanitize Globals
+ *
+ * This function does the following:
+ *
+ * - Unsets $_GET data (if query strings are not enabled)
+ * - Unsets all globals if register_globals is enabled
+ * - Standardizes newline characters to \n
+ *
+ * @return void
+ */
protected function _sanitize_globals()
{
// It would be "wrong" to unset any of these GLOBALS.
- $protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST',
- '_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA',
- 'system_folder', 'application_folder', 'BM', 'EXT',
- 'CFG', 'URI', 'RTR', 'OUT', 'IN'
- );
+ $protected = array(
+ '_SERVER',
+ '_GET',
+ '_POST',
+ '_FILES',
+ '_REQUEST',
+ '_SESSION',
+ '_ENV',
+ 'GLOBALS',
+ 'HTTP_RAW_POST_DATA',
+ 'system_folder',
+ 'application_folder',
+ 'BM',
+ 'EXT',
+ 'CFG',
+ 'URI',
+ 'RTR',
+ 'OUT'
+ 'IN'
+ );
// Unset globals for securiy.
// This is effectively the same as register_globals = off
@@ -493,14 +514,14 @@ class CI_Input {
// --------------------------------------------------------------------
/**
- * Clean Input Data
- *
- * This is a helper function. It escapes data and
- * standardizes newline characters to \n
- *
- * @param string
- * @return string
- */
+ * Clean Input Data
+ *
+ * This is a helper function. It escapes data and
+ * standardizes newline characters to \n
+ *
+ * @param string
+ * @return string
+ */
protected function _clean_input_data($str)
{
if (is_array($str))
@@ -550,15 +571,15 @@ class CI_Input {
// --------------------------------------------------------------------
/**
- * Clean Keys
- *
- * This is a helper function. To prevent malicious users
- * from trying to exploit keys we make sure that keys are
- * only named with alpha-numeric text and a few other items.
- *
- * @param string
- * @return string
- */
+ * Clean Keys
+ *
+ * This is a helper function. To prevent malicious users
+ * from trying to exploit keys we make sure that keys are
+ * only named with alpha-numeric text and a few other items.
+ *
+ * @param string
+ * @return string
+ */
protected function _clean_input_keys($str)
{
if ( ! preg_match('/^[a-z0-9:_\/-]+$/i', $str))
@@ -695,4 +716,4 @@ class CI_Input {
}
/* End of file Input.php */
-/* Location: ./system/core/Input.php */
+/* Location: ./system/core/Input.php */
\ No newline at end of file
diff --git a/system/core/Lang.php b/system/core/Lang.php
index 82013844c..7abdc6102 100755
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Language Class
*
@@ -43,13 +41,14 @@ class CI_Lang {
*
* @var array
*/
- public $language = array();
+ public $language = array();
+
/**
* List of loaded language files
*
* @var array
*/
- public $is_loaded = array();
+ public $is_loaded = array();
/**
* Initialize language class
@@ -164,4 +163,4 @@ class CI_Lang {
}
/* End of file Lang.php */
-/* Location: ./system/core/Lang.php */
+/* Location: ./system/core/Lang.php */
\ No newline at end of file
diff --git a/system/core/Loader.php b/system/core/Loader.php
index e1531843a..b99ce6964 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -45,75 +45,86 @@ class CI_Loader {
* @var int
*/
protected $_ci_ob_level;
+
/**
* List of paths to load views from
*
* @var array
*/
- protected $_ci_view_paths = array();
+ protected $_ci_view_paths = array();
+
/**
* List of paths to load libraries from
*
* @var array
*/
- protected $_ci_library_paths = array();
+ protected $_ci_library_paths = array();
+
/**
* List of paths to load models from
*
* @var array
*/
- protected $_ci_model_paths = array();
+ protected $_ci_model_paths = array();
+
/**
* List of paths to load helpers from
*
* @var array
*/
- protected $_ci_helper_paths = array();
+ protected $_ci_helper_paths = array();
+
/**
* List of loaded base classes
*
* @var array
*/
- protected $_base_classes = array(); // Set by the controller class
+ protected $_base_classes = array(); // Set by the controller class
+
/**
* List of cached variables
*
* @var array
*/
- protected $_ci_cached_vars = array();
+ protected $_ci_cached_vars = array();
+
/**
* List of loaded classes
*
* @var array
*/
- protected $_ci_classes = array();
+ protected $_ci_classes = array();
+
/**
* List of loaded files
*
* @var array
*/
- protected $_ci_loaded_files = array();
+ protected $_ci_loaded_files = array();
+
/**
* List of loaded models
*
* @var array
*/
- protected $_ci_models = array();
+ protected $_ci_models = array();
+
/**
* List of loaded helpers
*
* @var array
*/
- protected $_ci_helpers = array();
+ protected $_ci_helpers = array();
+
/**
* List of class name mappings
*
* @var array
*/
- protected $_ci_varmap = array(
- 'unit_test' => 'unit',
- 'user_agent' => 'agent'
- );
+ protected $_ci_varmap = array(
+ 'unit_test' => 'unit',
+ 'user_agent' => 'agent'
+ );
/**
* Constructor
diff --git a/system/core/Model.php b/system/core/Model.php
index 3855d49e7..7c9971970 100755
--- a/system/core/Model.php
+++ b/system/core/Model.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Model Class
*
@@ -62,4 +60,4 @@ class CI_Model {
}
/* End of file Model.php */
-/* Location: ./system/core/Model.php */
+/* Location: ./system/core/Model.php */
\ No newline at end of file
diff --git a/system/core/Output.php b/system/core/Output.php
index 671303094..0683539c9 100755
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -50,35 +50,35 @@ class CI_Output {
*
* @var int
*/
- public $cache_expiration = 0;
+ public $cache_expiration = 0;
/**
* List of server headers
*
* @var array
*/
- public $headers = array();
+ public $headers = array();
/**
* List of mime types
*
* @var array
*/
- public $mime_types = array();
+ public $mime_types = array();
/**
* Determines wether profiler is enabled
*
* @var book
*/
- public $enable_profiler = FALSE;
+ public $enable_profiler = FALSE;
/**
* Determines if output compression is enabled
*
* @var bool
*/
- protected $_zlib_oc = FALSE;
+ protected $_zlib_oc = FALSE;
/**
* List of profiler sections
@@ -92,7 +92,7 @@ class CI_Output {
*
* @var bool
*/
- public $parse_exec_vars = TRUE;
+ public $parse_exec_vars = TRUE;
/**
* Set up Output class
diff --git a/system/core/Router.php b/system/core/Router.php
index b34911859..b5c200214 100755
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -44,36 +44,42 @@ class CI_Router {
* @var object
*/
public $config;
+
/**
* List of routes
*
* @var array
*/
- public $routes = array();
+ public $routes = array();
+
/**
* List of error routes
*
* @var array
*/
- public $error_routes = array();
+ public $error_routes = array();
+
/**
* Current class name
*
* @var string
*/
- public $class = '';
+ public $class = '';
+
/**
* Current method name
*
* @var string
*/
- public $method = 'index';
+ public $method = 'index';
+
/**
* Sub-directory that contains the requested controller class
*
* @var string
*/
- public $directory = '';
+ public $directory = '';
+
/**
* Default controller (and method if specific)
*
diff --git a/system/core/Security.php b/system/core/Security.php
index 8d81babf2..139511661 100755
--- a/system/core/Security.php
+++ b/system/core/Security.php
@@ -41,14 +41,14 @@ class CI_Security {
*
* @var string
*/
- protected $_xss_hash = '';
+ protected $_xss_hash = '';
/**
* Random Hash for Cross Site Request Forgery Protection Cookie
*
* @var string
*/
- protected $_csrf_hash = '';
+ protected $_csrf_hash = '';
/**
* Expiration time for Cross Site Request Forgery Protection Cookie
@@ -56,21 +56,21 @@ class CI_Security {
*
* @var int
*/
- protected $_csrf_expire = 7200;
+ protected $_csrf_expire = 7200;
/**
* Token name for Cross Site Request Forgery Protection Cookie
*
* @var string
*/
- protected $_csrf_token_name = 'ci_csrf_token';
+ protected $_csrf_token_name = 'ci_csrf_token';
/**
* Cookie name for Cross Site Request Forgery Protection Cookie
*
* @var string
*/
- protected $_csrf_cookie_name = 'ci_csrf_token';
+ protected $_csrf_cookie_name = 'ci_csrf_token';
/**
* List of never allowed strings
@@ -78,17 +78,17 @@ class CI_Security {
* @var array
*/
protected $_never_allowed_str = array(
- 'document.cookie' => '[removed]',
- 'document.write' => '[removed]',
- '.parentNode' => '[removed]',
- '.innerHTML' => '[removed]',
- 'window.location' => '[removed]',
- '-moz-binding' => '[removed]',
- '' => '-->',
- ' '<![CDATA[',
- '' => '<comment>'
- );
+ 'document.cookie' => '[removed]',
+ 'document.write' => '[removed]',
+ '.parentNode' => '[removed]',
+ '.innerHTML' => '[removed]',
+ 'window.location' => '[removed]',
+ '-moz-binding' => '[removed]',
+ '' => '-->',
+ ' '<![CDATA[',
+ '' => '<comment>'
+ );
/**
* List of never allowed regex replacement
@@ -96,11 +96,11 @@ class CI_Security {
* @var array
*/
protected $_never_allowed_regex = array(
- 'javascript\s*:',
- 'expression\s*(\(|&\#40;)', // CSS and IE
- 'vbscript\s*:', // IE, surprise!
- 'Redirect\s+302'
- );
+ 'javascript\s*:',
+ 'expression\s*(\(|&\#40;)', // CSS and IE
+ 'vbscript\s*:', // IE, surprise!
+ 'Redirect\s+302'
+ );
/**
* Initialize security class
@@ -365,9 +365,9 @@ class CI_Security {
* These words are compacted back to their correct state.
*/
$words = array(
- 'javascript', 'expression', 'vbscript', 'script',
- 'applet', 'alert', 'document', 'write', 'cookie', 'window'
- );
+ 'javascript', 'expression', 'vbscript', 'script',
+ 'applet', 'alert', 'document', 'write', 'cookie', 'window'
+ );
foreach ($words as $word)
{
@@ -525,23 +525,23 @@ class CI_Security {
public function sanitize_filename($str, $relative_path = FALSE)
{
$bad = array(
- '../', '', '<', '>',
- "'", '"', '&', '$', '#',
- '{', '}', '[', ']', '=',
- ';', '?', '%20', '%22',
- '%3c', // <
- '%253c', // <
- '%3e', // >
- '%0e', // >
- '%28', // (
- '%29', // )
- '%2528', // (
- '%26', // &
- '%24', // $
- '%3f', // ?
- '%3b', // ;
- '%3d' // =
- );
+ '../', '', '<', '>',
+ "'", '"', '&', '$', '#',
+ '{', '}', '[', ']', '=',
+ ';', '?', '%20', '%22',
+ '%3c', // <
+ '%253c', // <
+ '%3e', // >
+ '%0e', // >
+ '%28', // (
+ '%29', // )
+ '%2528', // (
+ '%26', // &
+ '%24', // $
+ '%3f', // ?
+ '%3b', // ;
+ '%3d' // =
+ );
if ( ! $relative_path)
{
@@ -841,4 +841,4 @@ class CI_Security {
}
/* End of file Security.php */
-/* Location: ./system/core/Security.php */
+/* Location: ./system/core/Security.php */
\ No newline at end of file
diff --git a/system/core/URI.php b/system/core/URI.php
index 48bb7ae3c..140295338 100755
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -24,8 +24,6 @@
* @since Version 1.0
*/
-// ------------------------------------------------------------------------
-
/**
* URI Class
*
@@ -44,26 +42,29 @@ class CI_URI {
*
* @var array
*/
- public $keyval = array();
+ public $keyval = array();
+
/**
* Current uri string
*
* @var string
*/
public $uri_string;
+
/**
* List of uri segments
*
* @var array
*/
- public $segments = array();
+ public $segments = array();
+
/**
* Re-indexed list of uri segments
* Starts at 1 instead of 0
*
* @var array
*/
- public $rsegments = array();
+ public $rsegments = array();
/**
* Constructor
@@ -326,6 +327,7 @@ class CI_URI {
}
// --------------------------------------------------------------------
+
/**
* Re-index Segments
*
@@ -406,6 +408,9 @@ class CI_URI {
{
return $this->_uri_to_assoc($n, $default, 'segment');
}
+
+ // --------------------------------------------------------------------
+
/**
* Identical to above only it uses the re-routed segment array
*
@@ -501,7 +506,6 @@ class CI_URI {
/**
* Generate a URI string from an associative array
*
- *
* @param array an associative array of key/values
* @return array
*/
@@ -647,4 +651,4 @@ class CI_URI {
}
/* End of file URI.php */
-/* Location: ./system/core/URI.php */
+/* Location: ./system/core/URI.php */
\ No newline at end of file
diff --git a/system/core/Utf8.php b/system/core/Utf8.php
index ba3567453..122020aea 100644
--- a/system/core/Utf8.php
+++ b/system/core/Utf8.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Utf8 Class
*
@@ -161,4 +159,4 @@ class CI_Utf8 {
}
/* End of file Utf8.php */
-/* Location: ./system/core/Utf8.php */
+/* Location: ./system/core/Utf8.php */
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 67cb3eef37fa826f56f61cfd2ac597052d9051f9 Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Thu, 19 Apr 2012 16:41:52 -0400
Subject: Fix syntax error
---
system/core/Input.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/core/Input.php b/system/core/Input.php
index 049935632..7ee8f3685 100755
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -430,7 +430,7 @@ class CI_Input {
'CFG',
'URI',
'RTR',
- 'OUT'
+ 'OUT',
'IN'
);
--
cgit v1.2.3-24-g4f1b
From 0688ac9ad88a03f1c56cfcd9e3c475b83301344d Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Fri, 20 Apr 2012 10:25:04 -0400
Subject: Start comment cleanup of libraries
---
system/libraries/Cache/Cache.php | 48 ++++++---
system/libraries/Cache/drivers/Cache_apc.php | 2 +-
system/libraries/Cache/drivers/Cache_dummy.php | 2 +-
system/libraries/Cache/drivers/Cache_file.php | 16 ++-
system/libraries/Cache/drivers/Cache_memcached.php | 24 +++--
system/libraries/Cache/drivers/Cache_wincache.php | 2 +-
system/libraries/Driver.php | 45 +++++++-
system/libraries/Encrypt.php | 35 +++++-
system/libraries/Form_validation.php | 83 +++++++++++++-
system/libraries/Profiler.php | 44 ++++++--
system/libraries/Typography.php | 36 +++++--
system/libraries/User_agent.php | 120 ++++++++++++++++++---
system/libraries/Xmlrpc.php | 36 +++----
system/libraries/Xmlrpcs.php | 37 ++++++-
14 files changed, 440 insertions(+), 90 deletions(-)
diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php
index f98241617..409323def 100644
--- a/system/libraries/Cache/Cache.php
+++ b/system/libraries/Cache/Cache.php
@@ -36,16 +36,38 @@
*/
class CI_Cache extends CI_Driver_Library {
- protected $valid_drivers = array(
- 'cache_apc',
- 'cache_file',
- 'cache_memcached',
- 'cache_dummy',
- 'cache_wincache'
- );
-
- protected $_cache_path = NULL; // Path of cache files (if file-based cache)
- protected $_adapter = 'dummy';
+ /**
+ * Valid cache drivers
+ *
+ * @var array
+ */
+ protected $valid_drivers = array(
+ 'cache_apc',
+ 'cache_file',
+ 'cache_memcached',
+ 'cache_dummy',
+ 'cache_wincache'
+ );
+
+ /**
+ * Path of cache files (if file-based cache)
+ *
+ * @var string
+ */
+ protected $_cache_path = NULL;
+
+ /**
+ * Reference to the driver
+ *
+ * @var mixe
+ */
+ protected $_adapter = 'dummy';
+
+ /**
+ * Fallback driver
+ *
+ * @param string
+ */
protected $_backup_driver;
/**
@@ -59,9 +81,9 @@ class CI_Cache extends CI_Driver_Library {
public function __construct($config = array())
{
$default_config = array(
- 'adapter',
- 'memcached'
- );
+ 'adapter',
+ 'memcached'
+ );
foreach ($default_config as $key)
{
diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php
index 59ab67533..c85034f95 100644
--- a/system/libraries/Cache/drivers/Cache_apc.php
+++ b/system/libraries/Cache/drivers/Cache_apc.php
@@ -75,7 +75,7 @@ class CI_Cache_apc extends CI_Driver {
* Delete from Cache
*
* @param mixed unique identifier of the item in the cache
- * @param bool true on success/false on failure
+ * @return bool true on success/false on failure
*/
public function delete($id)
{
diff --git a/system/libraries/Cache/drivers/Cache_dummy.php b/system/libraries/Cache/drivers/Cache_dummy.php
index e8b791c5b..3f2b4b956 100644
--- a/system/libraries/Cache/drivers/Cache_dummy.php
+++ b/system/libraries/Cache/drivers/Cache_dummy.php
@@ -70,7 +70,7 @@ class CI_Cache_dummy extends CI_Driver {
* Delete from Cache
*
* @param mixed unique identifier of the item in the cache
- * @param bool TRUE, simulating success
+ * @return bool TRUE, simulating success
*/
public function delete($id)
{
diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php
index dd27aa90e..ec4195278 100644
--- a/system/libraries/Cache/drivers/Cache_file.php
+++ b/system/libraries/Cache/drivers/Cache_file.php
@@ -36,8 +36,16 @@
*/
class CI_Cache_file extends CI_Driver {
+ /**
+ * Directory in which to save cache files
+ *
+ * @var string
+ */
protected $_cache_path;
+ /**
+ * Initialize file-based cache
+ */
public function __construct()
{
$CI =& get_instance();
@@ -86,10 +94,10 @@ class CI_Cache_file extends CI_Driver {
public function save($id, $data, $ttl = 60)
{
$contents = array(
- 'time' => time(),
- 'ttl' => $ttl,
- 'data' => $data
- );
+ 'time' => time(),
+ 'ttl' => $ttl,
+ 'data' => $data
+ );
if (write_file($this->_cache_path.$id, serialize($contents)))
{
diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php
index 4cd5f3d6f..813df4b1c 100644
--- a/system/libraries/Cache/drivers/Cache_memcached.php
+++ b/system/libraries/Cache/drivers/Cache_memcached.php
@@ -36,15 +36,25 @@
*/
class CI_Cache_memcached extends CI_Driver {
- protected $_memcached; // Holds the memcached object
+ /**
+ * Holds the memcached object
+ *
+ * @var object
+ */
+ protected $_memcached;
+ /**
+ * Memcached configuration
+ *
+ * @var array
+ */
protected $_memcache_conf = array(
- 'default' => array(
- 'default_host' => '127.0.0.1',
- 'default_port' => 11211,
- 'default_weight' => 1
- )
- );
+ 'default' => array(
+ 'default_host' => '127.0.0.1',
+ 'default_port' => 11211,
+ 'default_weight' => 1
+ )
+ );
/**
* Fetch from cache
diff --git a/system/libraries/Cache/drivers/Cache_wincache.php b/system/libraries/Cache/drivers/Cache_wincache.php
index b32e66a46..74048d564 100644
--- a/system/libraries/Cache/drivers/Cache_wincache.php
+++ b/system/libraries/Cache/drivers/Cache_wincache.php
@@ -78,7 +78,7 @@ class CI_Cache_wincache extends CI_Driver {
* Delete from Cache
*
* @param mixed unique identifier of the item in the cache
- * @param bool true on success/false on failure
+ * @return bool true on success/false on failure
*/
public function delete($id)
{
diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php
index f409f47d4..b1fff154d 100644
--- a/system/libraries/Driver.php
+++ b/system/libraries/Driver.php
@@ -39,11 +39,27 @@
*/
class CI_Driver_Library {
- protected $valid_drivers = array();
+ /**
+ * Array of drivers that are available to use with the driver class
+ *
+ * @var array
+ */
+ protected $valid_drivers = array();
+
+ /**
+ * Name of the current class - usually the driver class
+ *
+ * @var string
+ */
protected static $lib_name;
- // The first time a child is used it won't exist, so we instantiate it
- // subsequents calls will go straight to the proper child.
+ /**
+ * The first time a child is used it won't exist, so we instantiate it
+ * subsequents calls will go straight to the proper child.
+ *
+ * @param mixed $child
+ * @return mixed
+ */
public function __get($child)
{
if ( ! isset($this->lib_name))
@@ -100,6 +116,8 @@ class CI_Driver_Library {
}
+// --------------------------------------------------------------------------
+
/**
* CodeIgniter Driver Class
*
@@ -114,11 +132,32 @@ class CI_Driver_Library {
*/
class CI_Driver {
+ /**
+ * Instance of the parent class
+ *
+ * @var object
+ */
protected $_parent;
+ /**
+ * List of methods in the parent class
+ *
+ * @var array
+ */
protected $_methods = array();
+
+ /**
+ * List of properties in the parent class
+ *
+ * @var array
+ */
protected $_properties = array();
+ /**
+ * Array of methods and properties for the parent class(es)
+ *
+ * @var array
+ */
protected static $_reflections = array();
/**
diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php
index 54b5bf737..17437c1ca 100644
--- a/system/libraries/Encrypt.php
+++ b/system/libraries/Encrypt.php
@@ -38,12 +38,44 @@
*/
class CI_Encrypt {
+ /**
+ * Reference to the user's encryption key
+ *
+ * @var string
+ */
public $encryption_key = '';
+
+ /**
+ * Type of hash operation
+ *
+ * @var string
+ */
protected $_hash_type = 'sha1';
+
+ /**
+ * Flag for the existance of mcrypt
+ *
+ * @var bool
+ */
protected $_mcrypt_exists = FALSE;
+
+ /**
+ * Current cipher to be used with mcrypt
+ *
+ * @var string
+ */
protected $_mcrypt_cipher;
+
+ /**
+ * Method for encrypting/decrypting data
+ *
+ * @var int
+ */
protected $_mcrypt_mode;
+ /**
+ * Initialize Encryption class
+ */
public function __construct()
{
$this->_mcrypt_exists = function_exists('mcrypt_encrypt');
@@ -349,7 +381,8 @@ class CI_Encrypt {
*
* Function description
*
- * @param string
+ * @param string $data
+ * @param string $key
* @return string
*/
protected function _remove_cipher_noise($data, $key)
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 22bc7ddf3..a52cad5ff 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -36,17 +36,81 @@
*/
class CI_Form_validation {
+ /**
+ * Reference to the CodeIgniter instance
+ *
+ * @var object
+ */
protected $CI;
- protected $_field_data = array();
- protected $_config_rules = array();
+
+ /**
+ * Validation data for the current form submission
+ *
+ * @var array
+ */
+ protected $_field_data = array();
+
+ /**
+ * Validation rules for the current form
+ *
+ * @var array
+ */
+ protected $_config_rules = array();
+
+ /**
+ * Array of validation errors
+ *
+ * @var array
+ */
protected $_error_array = array();
+
+ /**
+ * Array of custom error messages
+ *
+ * @var array
+ */
protected $_error_messages = array();
+
+ /**
+ * Start tag for error wrapping
+ *
+ * @var string
+ */
protected $_error_prefix = '
';
+
+ /**
+ * End tag for error wrapping
+ *
+ * @var string
+ */
protected $_error_suffix = '
';
+
+ /**
+ * Custom error message
+ *
+ * @var string
+ */
protected $error_string = '';
+
+ /**
+ * Whether the form data has been validated as safe
+ *
+ * @var bool
+ */
protected $_safe_form_data = FALSE;
+
+ /**
+ * Custom data to validate
+ *
+ * @var array
+ */
protected $validation_data = array();
+ /**
+ * Initialize Form_Validation class
+ *
+ * @param array $rules
+ */
public function __construct($rules = array())
{
$this->CI =& get_instance();
@@ -86,8 +150,9 @@ class CI_Form_validation {
* This function takes an array of field names and validation
* rules as input, validates the info, and stores it
*
- * @param mixed
- * @param string
+ * @param mixed $field
+ * @param string $label
+ * @param mixed $rules
* @return object
*/
public function set_rules($field, $label = '', $rules = '')
@@ -241,6 +306,8 @@ class CI_Form_validation {
* Gets the error message associated with a particular field
*
* @param string the field name
+ * @param string the html start tag
+ * @param strign the html end tag
* @return string
*/
public function error($field = '', $prefix = '', $suffix = '')
@@ -326,6 +393,7 @@ class CI_Form_validation {
*
* This function does all the work.
*
+ * @param string $group
* @return bool
*/
public function run($group = '')
@@ -768,6 +836,7 @@ class CI_Form_validation {
*
* @param string
* @param string
+ * @param bool
* @return string
*/
public function set_select($field = '', $value = '', $default = FALSE)
@@ -803,6 +872,7 @@ class CI_Form_validation {
*
* @param string
* @param string
+ * @param bool
* @return string
*/
public function set_radio($field = '', $value = '', $default = FALSE)
@@ -838,6 +908,7 @@ class CI_Form_validation {
*
* @param string
* @param string
+ * @param bool
* @return string
*/
public function set_checkbox($field = '', $value = '', $default = FALSE)
@@ -1116,6 +1187,7 @@ class CI_Form_validation {
* Greater than
*
* @param string
+ * @param int
* @return bool
*/
public function greater_than($str, $min)
@@ -1129,6 +1201,7 @@ class CI_Form_validation {
* Equal to or Greater than
*
* @param string
+ * @param int
* @return bool
*/
public function greater_than_equal_to($str, $min)
@@ -1142,6 +1215,7 @@ class CI_Form_validation {
* Less than
*
* @param string
+ * @param int
* @return bool
*/
public function less_than($str, $max)
@@ -1155,6 +1229,7 @@ class CI_Form_validation {
* Equal to or Less than
*
* @param string
+ * @param int
* @return bool
*/
public function less_than_equal_to($str, $max)
diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php
index 6320ab50d..1e86f3c61 100644
--- a/system/libraries/Profiler.php
+++ b/system/libraries/Profiler.php
@@ -42,23 +42,45 @@
*/
class CI_Profiler {
+ /**
+ * List of profiler sections available to show
+ *
+ * @var array
+ */
protected $_available_sections = array(
- 'benchmarks',
- 'get',
- 'memory_usage',
- 'post',
- 'uri_string',
- 'controller_info',
- 'queries',
- 'http_headers',
- 'session_data',
- 'config'
- );
+ 'benchmarks',
+ 'get',
+ 'memory_usage',
+ 'post',
+ 'uri_string',
+ 'controller_info',
+ 'queries',
+ 'http_headers',
+ 'session_data',
+ 'config'
+ );
+ /**
+ * Number of queries to show before making the additional queries togglable
+ *
+ * @var int
+ */
protected $_query_toggle_count = 25;
+ /**
+ * Reference to the CodeIgniter singleton
+ *
+ * @var object
+ */
protected $CI;
+ /**
+ * Constructor
+ *
+ * Initialize Profiler
+ *
+ * @param array $config
+ */
public function __construct($config = array())
{
$this->CI =& get_instance();
diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php
index 21bbad038..50bd12486 100644
--- a/system/libraries/Typography.php
+++ b/system/libraries/Typography.php
@@ -36,22 +36,46 @@
*/
class CI_Typography {
- // Block level elements that should not be wrapped inside
tags
+ /**
+ * Block level elements that should not be wrapped inside
tags
+ *
+ * @var string
+ */
public $block_elements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul';
- // Elements that should not have
and tags within them.
+ /**
+ * Elements that should not have
and tags within them.
+ *
+ * @var string
+ */
public $skip_elements = 'p|pre|ol|ul|dl|object|table|h\d';
- // Tags we want the parser to completely ignore when splitting the string.
+ /**
+ * Tags we want the parser to completely ignore when splitting the string.
+ *
+ * @var string
+ */
public $inline_elements = 'a|abbr|acronym|b|bdo|big|br|button|cite|code|del|dfn|em|i|img|ins|input|label|map|kbd|q|samp|select|small|span|strong|sub|sup|textarea|tt|var';
- // array of block level elements that require inner content to be within another block level element
+ /**
+ * array of block level elements that require inner content to be within another block level element
+ *
+ * @var array
+ */
public $inner_block_required = array('blockquote');
- // the last block element parsed
+ /**
+ * the last block element parsed
+ *
+ * @var string
+ */
public $last_block_element = '';
- // whether or not to protect quotes within { curly braces }
+ /**
+ * whether or not to protect quotes within { curly braces }
+ *
+ * @var bool
+ */
public $protect_braced_quotes = FALSE;
/**
diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php
index b8e0d37fb..0ac605fa4 100644
--- a/system/libraries/User_agent.php
+++ b/system/libraries/User_agent.php
@@ -38,25 +38,110 @@
*/
class CI_User_agent {
- public $agent = NULL;
+ /**
+ * Current user-agent
+ *
+ * @var string
+ */
+ public $agent = NULL;
- public $is_browser = FALSE;
- public $is_robot = FALSE;
- public $is_mobile = FALSE;
+ /**
+ * Flag for if the user-agent belongs to a browser
+ *
+ * @var bool
+ */
+ public $is_browser = FALSE;
+
+ /**
+ * Flag for if the user-agent is a robot
+ *
+ * @var bool
+ */
+ public $is_robot = FALSE;
+
+ /**
+ * Flag for if the user-agent is a mobile browser
+ *
+ * @var bool
+ */
+ public $is_mobile = FALSE;
- public $languages = array();
- public $charsets = array();
+ /**
+ * Languages accepted by the current user agent
+ *
+ * @var array
+ */
+ public $languages = array();
+
+ /**
+ * Character sets accepted by the current user agent
+ *
+ * @var array
+ */
+ public $charsets = array();
- public $platforms = array();
- public $browsers = array();
- public $mobiles = array();
- public $robots = array();
+ /**
+ * List of platforms to compare against current user agent
+ *
+ * @var array
+ */
+ public $platforms = array();
+
+ /**
+ * List of browsers to compare against current user agent
+ *
+ * @var array
+ */
+ public $browsers = array();
+
+ /**
+ * List of mobile browsers to compare against current user agent
+ *
+ * @var array
+ */
+ public $mobiles = array();
+
+ /**
+ * List of robots to compare against current user agent
+ *
+ * @var array
+ */
+ public $robots = array();
- public $platform = '';
- public $browser = '';
- public $version = '';
- public $mobile = '';
- public $robot = '';
+ /**
+ * Current user-agent platform
+ *
+ * @var string
+ */
+ public $platform = '';
+
+ /**
+ * Current user-agent browser
+ *
+ * @var string
+ */
+ public $browser = '';
+
+ /**
+ * Current user-agent version
+ *
+ * @var string
+ */
+ public $version = '';
+
+ /**
+ * Current user-agent mobile name
+ *
+ * @var string
+ */
+ public $mobile = '';
+
+ /**
+ * Current user-agent robot name
+ *
+ * @var string
+ */
+ public $robot = '';
/**
* Constructor
@@ -302,6 +387,7 @@ class CI_User_agent {
/**
* Is Browser
*
+ * @param string $key
* @return bool
*/
public function is_browser($key = NULL)
@@ -326,6 +412,7 @@ class CI_User_agent {
/**
* Is Robot
*
+ * @param string $key
* @return bool
*/
public function is_robot($key = NULL)
@@ -350,6 +437,7 @@ class CI_User_agent {
/**
* Is Mobile
*
+ * @param string $key
* @return bool
*/
public function is_mobile($key = NULL)
@@ -503,6 +591,7 @@ class CI_User_agent {
/**
* Test for a particular language
*
+ * @param string $lang
* @return bool
*/
public function accept_lang($lang = 'en')
@@ -515,6 +604,7 @@ class CI_User_agent {
/**
* Test for a particular character set
*
+ * @param string $charset
* @return bool
*/
public function accept_charset($charset = 'utf-8')
diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php
index fea560c2e..7009deacc 100644
--- a/system/libraries/Xmlrpc.php
+++ b/system/libraries/Xmlrpc.php
@@ -104,24 +104,24 @@ class CI_Xmlrpc {
);
// Array of Valid Parents for Various XML-RPC elements
- $this->valid_parents = array('BOOLEAN' => array('VALUE'),
- 'I4' => array('VALUE'),
- 'INT' => array('VALUE'),
- 'STRING' => array('VALUE'),
- 'DOUBLE' => array('VALUE'),
- 'DATETIME.ISO8601' => array('VALUE'),
- 'BASE64' => array('VALUE'),
- 'ARRAY' => array('VALUE'),
- 'STRUCT' => array('VALUE'),
- 'PARAM' => array('PARAMS'),
- 'METHODNAME' => array('METHODCALL'),
- 'PARAMS' => array('METHODCALL', 'METHODRESPONSE'),
- 'MEMBER' => array('STRUCT'),
- 'NAME' => array('MEMBER'),
- 'DATA' => array('ARRAY'),
- 'FAULT' => array('METHODRESPONSE'),
- 'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT')
- );
+ $this->valid_parents = array('BOOLEAN' => array('VALUE'),
+ 'I4' => array('VALUE'),
+ 'INT' => array('VALUE'),
+ 'STRING' => array('VALUE'),
+ 'DOUBLE' => array('VALUE'),
+ 'DATETIME.ISO8601' => array('VALUE'),
+ 'BASE64' => array('VALUE'),
+ 'ARRAY' => array('VALUE'),
+ 'STRUCT' => array('VALUE'),
+ 'PARAM' => array('PARAMS'),
+ 'METHODNAME' => array('METHODCALL'),
+ 'PARAMS' => array('METHODCALL', 'METHODRESPONSE'),
+ 'MEMBER' => array('STRUCT'),
+ 'NAME' => array('MEMBER'),
+ 'DATA' => array('ARRAY'),
+ 'FAULT' => array('METHODRESPONSE'),
+ 'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT')
+ );
// XML-RPC Responses
diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php
index 6d270c2ea..f0c5b48e7 100644
--- a/system/libraries/Xmlrpcs.php
+++ b/system/libraries/Xmlrpcs.php
@@ -48,12 +48,39 @@ if ( ! class_exists('CI_Xmlrpc'))
*/
class CI_Xmlrpcs extends CI_Xmlrpc
{
- public $methods = array(); //array of methods mapped to function names and signatures
- public $debug_msg = ''; // Debug Message
- public $system_methods = array(); // XML RPC Server methods
- public $controller_obj;
- public $object = FALSE;
+ /**
+ * array of methods mapped to function names and signatures
+ *
+ * @var array
+ */
+ public $methods = array();
+
+ /**
+ * Debug Message
+ *
+ * @var string
+ */
+ public $debug_msg = '';
+
+ /**
+ * XML RPC Server methods
+ *
+ * @var array
+ */
+ public $system_methods = array();
+
+ /**
+ * Configuration object
+ *
+ * @var object
+ */
+ public $object = FALSE;
+ /**
+ * Initialize XMLRPC class
+ *
+ * @param array $config
+ */
public function __construct($config = array())
{
parent::__construct();
--
cgit v1.2.3-24-g4f1b
From bb8ae01bff0fa7cb3b14fb5f1310d944c414cf81 Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Fri, 20 Apr 2012 10:31:51 -0400
Subject: added suggested styleguide addition for future consistency
---
user_guide_src/source/general/styleguide.rst | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/user_guide_src/source/general/styleguide.rst b/user_guide_src/source/general/styleguide.rst
index 2b91d1cc0..925954c03 100644
--- a/user_guide_src/source/general/styleguide.rst
+++ b/user_guide_src/source/general/styleguide.rst
@@ -149,7 +149,7 @@ months down the line. There is not a required format for comments, but
the following are recommended.
`DocBlock `_
-style comments preceding class and method declarations so they can be
+style comments preceding class, method, and property declarations so they can be
picked up by IDEs::
/**
@@ -172,6 +172,17 @@ picked up by IDEs::
* @return string
*/
function xml_encode($str)
+
+::
+
+ /**
+ * Data for class manipulation
+ *
+ * @var array
+ */
+ public $data
+
+
Use single line comments within code, leaving a blank line between large
comment blocks and code.
--
cgit v1.2.3-24-g4f1b
From c1a66512eacc76968cbf01e2ee37c3c65584b1f0 Mon Sep 17 00:00:00 2001
From: Repox
Date: Mon, 23 Apr 2012 13:14:27 +0200
Subject: Corrected the migration_missing_down_method language string
---
system/language/english/migration_lang.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/language/english/migration_lang.php b/system/language/english/migration_lang.php
index 4763ca243..f17530f00 100644
--- a/system/language/english/migration_lang.php
+++ b/system/language/english/migration_lang.php
@@ -5,7 +5,7 @@ $lang['migration_not_found'] = "This migration could not be found.";
$lang['migration_multiple_version'] = "This are multiple migrations with the same version number: %d.";
$lang['migration_class_doesnt_exist'] = "The migration class \"%s\" could not be found.";
$lang['migration_missing_up_method'] = "The migration class \"%s\" is missing an 'up' method.";
-$lang['migration_missing_down_method'] = "The migration class \"%s\" is missing an 'up' method.";
+$lang['migration_missing_down_method'] = "The migration class \"%s\" is missing an 'down' method.";
$lang['migration_invalid_filename'] = "Migration \"%s\" has an invalid filename.";
--
cgit v1.2.3-24-g4f1b
From 31d30bcf206ed2e9168b93f74511708d6bc4b505 Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Mon, 23 Apr 2012 08:58:42 -0400
Subject: Merge upstream
---
system/core/CodeIgniter.php | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index 9714d095c..7deccd048 100755
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* System Initialization File
*
@@ -406,4 +404,4 @@
}
/* End of file CodeIgniter.php */
-/* Location: ./system/core/CodeIgniter.php */
+/* Location: ./system/core/CodeIgniter.php */
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 48a7fbbeb53e82e9298036d40c42ec2564699ed0 Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Mon, 23 Apr 2012 11:58:16 -0400
Subject: Use tabs to separate class properties
---
system/core/Benchmark.php | 4 ++--
system/core/CodeIgniter.php | 2 +-
system/core/Common.php | 1 -
system/core/Config.php | 6 +++---
system/core/Controller.php | 2 +-
system/core/Exceptions.php | 4 ++--
system/core/Hooks.php | 6 +++---
system/core/Input.php | 14 +++++++-------
system/core/Lang.php | 4 ++--
system/core/Loader.php | 22 +++++++++++-----------
system/core/Output.php | 14 +++++++-------
system/core/Router.php | 10 +++++-----
system/core/Security.php | 14 +++++++-------
system/core/URI.php | 6 +++---
14 files changed, 54 insertions(+), 55 deletions(-)
diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php
index 39027e809..c17e95a19 100755
--- a/system/core/Benchmark.php
+++ b/system/core/Benchmark.php
@@ -46,7 +46,7 @@ class CI_Benchmark {
*
* @var array
*/
- public $marker = array();
+ public $marker = array();
// --------------------------------------------------------------------
@@ -119,4 +119,4 @@ class CI_Benchmark {
}
/* End of file Benchmark.php */
-/* Location: ./system/core/Benchmark.php */
\ No newline at end of file
+/* Location: ./system/core/Benchmark.php */
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index 293582243..793c4687e 100755
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
@@ -40,7 +40,7 @@
/**
* CodeIgniter Version
*
- * @var string
+ * @var string
*
*/
define('CI_VERSION', '3.0-dev');
diff --git a/system/core/Common.php b/system/core/Common.php
index 075b221bd..78aa6e874 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -39,7 +39,6 @@
// ------------------------------------------------------------------------
-
if ( ! function_exists('is_php'))
{
/**
diff --git a/system/core/Config.php b/system/core/Config.php
index fc6183444..1eab08b82 100755
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -45,14 +45,14 @@ class CI_Config {
*
* @var array
*/
- public $config = array();
+ public $config = array();
/**
* List of all loaded config files
*
* @var array
*/
- public $is_loaded = array();
+ public $is_loaded = array();
/**
* List of paths to search when trying to load a config file.
@@ -60,7 +60,7 @@ class CI_Config {
*
* @var array
*/
- public $_config_paths = array(APPPATH);
+ public $_config_paths = array(APPPATH);
/**
* Constructor
diff --git a/system/core/Controller.php b/system/core/Controller.php
index 0c6c47183..1f69146d0 100644
--- a/system/core/Controller.php
+++ b/system/core/Controller.php
@@ -42,7 +42,7 @@ class CI_Controller {
/**
* Reference to the global CI instance
*
- * @var object
+ * @var object
*/
private static $instance;
diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php
index f55f9fcba..2e9f0c766 100755
--- a/system/core/Exceptions.php
+++ b/system/core/Exceptions.php
@@ -39,14 +39,14 @@ class CI_Exceptions {
/**
* Nesting level of the output buffering mechanism
*
- * @var int
+ * @var int
*/
public $ob_level;
/**
* List if available error levels
*
- * @var array
+ * @var array
*/
public $levels = array(
E_ERROR => 'Error',
diff --git a/system/core/Hooks.php b/system/core/Hooks.php
index 672fe29dd..b42ecbe20 100755
--- a/system/core/Hooks.php
+++ b/system/core/Hooks.php
@@ -43,21 +43,21 @@ class CI_Hooks {
*
* @var bool
*/
- public $enabled = FALSE;
+ public $enabled = FALSE;
/**
* List of all hooks set in config/hooks.php
*
* @var array
*/
- public $hooks = array();
+ public $hooks = array();
/**
* Determines wether hook is in progress, used to prevent infinte loops
*
* @var bool
*/
- public $in_progress = FALSE;
+ public $in_progress = FALSE;
/**
* Initialize the Hooks Preferences
diff --git a/system/core/Input.php b/system/core/Input.php
index 7ee8f3685..fc2a550bc 100755
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -43,28 +43,28 @@ class CI_Input {
*
* @var string
*/
- public $ip_address = FALSE;
+ public $ip_address = FALSE;
/**
* user agent (web browser) being used by the current user
*
* @var string
*/
- public $user_agent = FALSE;
+ public $user_agent = FALSE;
/**
* If FALSE, then $_GET will be set to an empty array
*
* @var bool
*/
- protected $_allow_get_array = TRUE;
+ protected $_allow_get_array = TRUE;
/**
* If TRUE, then newlines are standardized
*
* @var bool
*/
- protected $_standardize_newlines = TRUE;
+ protected $_standardize_newlines = TRUE;
/**
* Determines whether the XSS filter is always active when GET, POST or COOKIE data is encountered
@@ -72,7 +72,7 @@ class CI_Input {
*
* @var bool
*/
- protected $_enable_xss = FALSE;
+ protected $_enable_xss = FALSE;
/**
* Enables a CSRF cookie token to be set.
@@ -80,14 +80,14 @@ class CI_Input {
*
* @var bool
*/
- protected $_enable_csrf = FALSE;
+ protected $_enable_csrf = FALSE;
/**
* List of all HTTP request headers
*
* @var array
*/
- protected $headers = array();
+ protected $headers = array();
/**
* Constructor
diff --git a/system/core/Lang.php b/system/core/Lang.php
index 7abdc6102..2963012fc 100755
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
@@ -41,14 +41,14 @@ class CI_Lang {
*
* @var array
*/
- public $language = array();
+ public $language = array();
/**
* List of loaded language files
*
* @var array
*/
- public $is_loaded = array();
+ public $is_loaded = array();
/**
* Initialize language class
diff --git a/system/core/Loader.php b/system/core/Loader.php
index b99ce6964..7fb3eab41 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -51,77 +51,77 @@ class CI_Loader {
*
* @var array
*/
- protected $_ci_view_paths = array();
+ protected $_ci_view_paths = array();
/**
* List of paths to load libraries from
*
* @var array
*/
- protected $_ci_library_paths = array();
+ protected $_ci_library_paths = array();
/**
* List of paths to load models from
*
* @var array
*/
- protected $_ci_model_paths = array();
+ protected $_ci_model_paths = array();
/**
* List of paths to load helpers from
*
* @var array
*/
- protected $_ci_helper_paths = array();
+ protected $_ci_helper_paths = array();
/**
* List of loaded base classes
*
* @var array
*/
- protected $_base_classes = array(); // Set by the controller class
+ protected $_base_classes = array(); // Set by the controller class
/**
* List of cached variables
*
* @var array
*/
- protected $_ci_cached_vars = array();
+ protected $_ci_cached_vars = array();
/**
* List of loaded classes
*
* @var array
*/
- protected $_ci_classes = array();
+ protected $_ci_classes = array();
/**
* List of loaded files
*
* @var array
*/
- protected $_ci_loaded_files = array();
+ protected $_ci_loaded_files = array();
/**
* List of loaded models
*
* @var array
*/
- protected $_ci_models = array();
+ protected $_ci_models = array();
/**
* List of loaded helpers
*
* @var array
*/
- protected $_ci_helpers = array();
+ protected $_ci_helpers = array();
/**
* List of class name mappings
*
* @var array
*/
- protected $_ci_varmap = array(
+ protected $_ci_varmap = array(
'unit_test' => 'unit',
'user_agent' => 'agent'
);
diff --git a/system/core/Output.php b/system/core/Output.php
index 0683539c9..513c657a6 100755
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -50,49 +50,49 @@ class CI_Output {
*
* @var int
*/
- public $cache_expiration = 0;
+ public $cache_expiration = 0;
/**
* List of server headers
*
* @var array
*/
- public $headers = array();
+ public $headers = array();
/**
* List of mime types
*
* @var array
*/
- public $mime_types = array();
+ public $mime_types = array();
/**
* Determines wether profiler is enabled
*
* @var book
*/
- public $enable_profiler = FALSE;
+ public $enable_profiler = FALSE;
/**
* Determines if output compression is enabled
*
* @var bool
*/
- protected $_zlib_oc = FALSE;
+ protected $_zlib_oc = FALSE;
/**
* List of profiler sections
*
* @var array
*/
- protected $_profiler_sections = array();
+ protected $_profiler_sections = array();
/**
* Whether or not to parse variables like {elapsed_time} and {memory_usage}
*
* @var bool
*/
- public $parse_exec_vars = TRUE;
+ public $parse_exec_vars = TRUE;
/**
* Set up Output class
diff --git a/system/core/Router.php b/system/core/Router.php
index b5c200214..9314052fe 100755
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -50,35 +50,35 @@ class CI_Router {
*
* @var array
*/
- public $routes = array();
+ public $routes = array();
/**
* List of error routes
*
* @var array
*/
- public $error_routes = array();
+ public $error_routes = array();
/**
* Current class name
*
* @var string
*/
- public $class = '';
+ public $class = '';
/**
* Current method name
*
* @var string
*/
- public $method = 'index';
+ public $method = 'index';
/**
* Sub-directory that contains the requested controller class
*
* @var string
*/
- public $directory = '';
+ public $directory = '';
/**
* Default controller (and method if specific)
diff --git a/system/core/Security.php b/system/core/Security.php
index 139511661..974e2e428 100755
--- a/system/core/Security.php
+++ b/system/core/Security.php
@@ -41,14 +41,14 @@ class CI_Security {
*
* @var string
*/
- protected $_xss_hash = '';
+ protected $_xss_hash = '';
/**
* Random Hash for Cross Site Request Forgery Protection Cookie
*
* @var string
*/
- protected $_csrf_hash = '';
+ protected $_csrf_hash = '';
/**
* Expiration time for Cross Site Request Forgery Protection Cookie
@@ -56,28 +56,28 @@ class CI_Security {
*
* @var int
*/
- protected $_csrf_expire = 7200;
+ protected $_csrf_expire = 7200;
/**
* Token name for Cross Site Request Forgery Protection Cookie
*
* @var string
*/
- protected $_csrf_token_name = 'ci_csrf_token';
+ protected $_csrf_token_name = 'ci_csrf_token';
/**
* Cookie name for Cross Site Request Forgery Protection Cookie
*
* @var string
*/
- protected $_csrf_cookie_name = 'ci_csrf_token';
+ protected $_csrf_cookie_name = 'ci_csrf_token';
/**
* List of never allowed strings
*
* @var array
*/
- protected $_never_allowed_str = array(
+ protected $_never_allowed_str = array(
'document.cookie' => '[removed]',
'document.write' => '[removed]',
'.parentNode' => '[removed]',
@@ -95,7 +95,7 @@ class CI_Security {
*
* @var array
*/
- protected $_never_allowed_regex = array(
+ protected $_never_allowed_regex = array(
'javascript\s*:',
'expression\s*(\(|&\#40;)', // CSS and IE
'vbscript\s*:', // IE, surprise!
diff --git a/system/core/URI.php b/system/core/URI.php
index 140295338..ff2c458b8 100755
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -42,7 +42,7 @@ class CI_URI {
*
* @var array
*/
- public $keyval = array();
+ public $keyval = array();
/**
* Current uri string
@@ -56,7 +56,7 @@ class CI_URI {
*
* @var array
*/
- public $segments = array();
+ public $segments = array();
/**
* Re-indexed list of uri segments
@@ -64,7 +64,7 @@ class CI_URI {
*
* @var array
*/
- public $rsegments = array();
+ public $rsegments = array();
/**
* Constructor
--
cgit v1.2.3-24-g4f1b
From fc90a7b66df97db1fa0c792759118119836cb7ed Mon Sep 17 00:00:00 2001
From: Cosmin Atanasiu
Date: Mon, 23 Apr 2012 20:56:37 -0700
Subject: Update system/libraries/Javascript.php
---
system/libraries/Javascript.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php
index 629a3adfe..21c9e11bd 100644
--- a/system/libraries/Javascript.php
+++ b/system/libraries/Javascript.php
@@ -723,7 +723,7 @@ class CI_Javascript {
{
if (is_object($result))
{
- $json_result = $result->result_array();
+ $json_result = (array)$result;
}
elseif (is_array($result))
{
--
cgit v1.2.3-24-g4f1b
From 5335bc317f07f12c0f0bae5ac9189f75fcad0f1c Mon Sep 17 00:00:00 2001
From: Wes Baker
Date: Tue, 24 Apr 2012 15:17:14 -0400
Subject: Updating XSS cleaning to better handle base64 encoded attributes.
---
system/core/Security.php | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/system/core/Security.php b/system/core/Security.php
index ac39ce97b..65746637b 100755
--- a/system/core/Security.php
+++ b/system/core/Security.php
@@ -99,7 +99,8 @@ class CI_Security {
'javascript\s*:',
'expression\s*(\(|&\#40;)', // CSS and IE
'vbscript\s*:', // IE, surprise!
- 'Redirect\s+302'
+ 'Redirect\s+302',
+ "([\"'])?data\s*:[^\\1]*?base64[^\\1]*?,[^\\1]*?\\1?"
);
public function __construct()
@@ -362,7 +363,7 @@ class CI_Security {
* These words are compacted back to their correct state.
*/
$words = array(
- 'javascript', 'expression', 'vbscript', 'script',
+ 'javascript', 'expression', 'vbscript', 'script', 'base64',
'applet', 'alert', 'document', 'write', 'cookie', 'window'
);
@@ -602,10 +603,11 @@ class CI_Security {
$attribs = array();
// find occurrences of illegal attribute strings without quotes
- preg_match_all('/('.implode('|', $evil_attributes).')\s*=\s*([^\s]*)/is', $str, $matches, PREG_SET_ORDER);
+ preg_match_all('/('.implode('|', $evil_attributes).')\s*=\s*([^\s>]*)/is', $str, $matches, PREG_SET_ORDER);
foreach ($matches as $attr)
{
+
$attribs[] = preg_quote($attr[0], '/');
}
@@ -620,7 +622,7 @@ class CI_Security {
// replace illegal attribute strings that are inside an html tag
if (count($attribs) > 0)
{
- $str = preg_replace('/<(\/?[^><]+?)([^A-Za-z\-])('.implode('|', $attribs).')([\s><])([><]*)/i', '<$1$2$4$5', $str, -1, $count);
+ $str = preg_replace("/<(\/?[^><]+?)([^A-Za-z<>\-])(.*?)(".implode('|', $attribs).")(.*?)([\s><])([><]*)/i", '<$1 $3$5$6$7', $str, -1, $count);
}
} while ($count);
@@ -661,7 +663,7 @@ class CI_Security {
protected function _js_link_removal($match)
{
return str_replace($match[1],
- preg_replace('#href=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|
-EOF;
- }
-}
-
/* End of file smiley_helper.php */
/* Location: ./system/helpers/smiley_helper.php */
\ No newline at end of file
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php
index aed35c157..b42799a8e 100644
--- a/system/helpers/string_helper.php
+++ b/system/helpers/string_helper.php
@@ -37,22 +37,22 @@
// ------------------------------------------------------------------------
-/**
- * Trim Slashes
- *
- * Removes any leading/trailing slashes from a string:
- *
- * /this/that/theother/
- *
- * becomes:
- *
- * this/that/theother
- *
- * @param string
- * @return string
- */
if ( ! function_exists('trim_slashes'))
{
+ /**
+ * Trim Slashes
+ *
+ * Removes any leading/trailing slashes from a string:
+ *
+ * /this/that/theother/
+ *
+ * becomes:
+ *
+ * this/that/theother
+ *
+ * @param string
+ * @return string
+ */
function trim_slashes($str)
{
return trim($str, '/');
@@ -61,16 +61,16 @@ if ( ! function_exists('trim_slashes'))
// ------------------------------------------------------------------------
-/**
- * Strip Slashes
- *
- * Removes slashes contained in a string or in an array
- *
- * @param mixed string or array
- * @return mixed string or array
- */
if ( ! function_exists('strip_slashes'))
{
+ /**
+ * Strip Slashes
+ *
+ * Removes slashes contained in a string or in an array
+ *
+ * @param mixed string or array
+ * @return mixed string or array
+ */
function strip_slashes($str)
{
if (is_array($str))
@@ -91,16 +91,16 @@ if ( ! function_exists('strip_slashes'))
// ------------------------------------------------------------------------
-/**
- * Strip Quotes
- *
- * Removes single and double quotes from a string
- *
- * @param string
- * @return string
- */
if ( ! function_exists('strip_quotes'))
{
+ /**
+ * Strip Quotes
+ *
+ * Removes single and double quotes from a string
+ *
+ * @param string
+ * @return string
+ */
function strip_quotes($str)
{
return str_replace(array('"', "'"), '', $str);
@@ -109,16 +109,16 @@ if ( ! function_exists('strip_quotes'))
// ------------------------------------------------------------------------
-/**
- * Quotes to Entities
- *
- * Converts single and double quotes to entities
- *
- * @param string
- * @return string
- */
if ( ! function_exists('quotes_to_entities'))
{
+ /**
+ * Quotes to Entities
+ *
+ * Converts single and double quotes to entities
+ *
+ * @param string
+ * @return string
+ */
function quotes_to_entities($str)
{
return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str);
@@ -127,23 +127,23 @@ if ( ! function_exists('quotes_to_entities'))
// ------------------------------------------------------------------------
-/**
- * Reduce Double Slashes
- *
- * Converts double slashes in a string to a single slash,
- * except those found in http://
- *
- * http://www.some-site.com//index.php
- *
- * becomes:
- *
- * http://www.some-site.com/index.php
- *
- * @param string
- * @return string
- */
if ( ! function_exists('reduce_double_slashes'))
{
+ /**
+ * Reduce Double Slashes
+ *
+ * Converts double slashes in a string to a single slash,
+ * except those found in http://
+ *
+ * http://www.some-site.com//index.php
+ *
+ * becomes:
+ *
+ * http://www.some-site.com/index.php
+ *
+ * @param string
+ * @return string
+ */
function reduce_double_slashes($str)
{
return preg_replace('#(^|[^:])//+#', '\\1/', $str);
@@ -152,24 +152,24 @@ if ( ! function_exists('reduce_double_slashes'))
// ------------------------------------------------------------------------
-/**
- * Reduce Multiples
- *
- * Reduces multiple instances of a particular character. Example:
- *
- * Fred, Bill,, Joe, Jimmy
- *
- * becomes:
- *
- * Fred, Bill, Joe, Jimmy
- *
- * @param string
- * @param string the character you wish to reduce
- * @param bool TRUE/FALSE - whether to trim the character from the beginning/end
- * @return string
- */
if ( ! function_exists('reduce_multiples'))
{
+ /**
+ * Reduce Multiples
+ *
+ * Reduces multiple instances of a particular character. Example:
+ *
+ * Fred, Bill,, Joe, Jimmy
+ *
+ * becomes:
+ *
+ * Fred, Bill, Joe, Jimmy
+ *
+ * @param string
+ * @param string the character you wish to reduce
+ * @param bool TRUE/FALSE - whether to trim the character from the beginning/end
+ * @return string
+ */
function reduce_multiples($str, $character = ',', $trim = FALSE)
{
$str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str);
@@ -185,17 +185,17 @@ if ( ! function_exists('reduce_multiples'))
// ------------------------------------------------------------------------
-/**
- * Create a Random String
- *
- * Useful for generating passwords or hashes.
- *
- * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1
- * @param int number of characters
- * @return string
- */
if ( ! function_exists('random_string'))
{
+ /**
+ * Create a Random String
+ *
+ * Useful for generating passwords or hashes.
+ *
+ * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1
+ * @param int number of characters
+ * @return string
+ */
function random_string($type = 'alnum', $len = 8)
{
switch($type)
@@ -242,16 +242,16 @@ if ( ! function_exists('random_string'))
// ------------------------------------------------------------------------
-/**
- * Add's _1 to a string or increment the ending number to allow _2, _3, etc
- *
- * @param string required
- * @param string What should the duplicate number be appended with
- * @param string Which number should be used for the first dupe increment
- * @return string
- */
if ( ! function_exists('increment_string'))
{
+ /**
+ * Add's _1 to a string or increment the ending number to allow _2, _3, etc
+ *
+ * @param string required
+ * @param string What should the duplicate number be appended with
+ * @param string Which number should be used for the first dupe increment
+ * @return string
+ */
function increment_string($str, $separator = '_', $first = 1)
{
preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match);
@@ -262,17 +262,17 @@ if ( ! function_exists('increment_string'))
// ------------------------------------------------------------------------
-/**
- * Alternator
- *
- * Allows strings to be alternated. See docs...
- *
- * @param string (as many parameters as needed)
- * @return string
- */
if ( ! function_exists('alternator'))
{
- function alternator()
+ /**
+ * Alternator
+ *
+ * Allows strings to be alternated. See docs...
+ *
+ * @param string (as many parameters as needed)
+ * @return string
+ */
+ function alternator($args)
{
static $i;
@@ -288,15 +288,15 @@ if ( ! function_exists('alternator'))
// ------------------------------------------------------------------------
-/**
- * Repeater function
- *
- * @param string
- * @param int number of repeats
- * @return string
- */
if ( ! function_exists('repeater'))
{
+ /**
+ * Repeater function
+ *
+ * @param string
+ * @param int number of repeats
+ * @return string
+ */
function repeater($data, $num = 1)
{
return ($num > 0) ? str_repeat($data, $num) : '';
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index cc501c334..f53b06b93 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -37,18 +37,18 @@
// ------------------------------------------------------------------------
-/**
- * Word Limiter
- *
- * Limits a string to X number of words.
- *
- * @param string
- * @param int
- * @param string the end character. Usually an ellipsis
- * @return string
- */
if ( ! function_exists('word_limiter'))
{
+ /**
+ * Word Limiter
+ *
+ * Limits a string to X number of words.
+ *
+ * @param string
+ * @param int
+ * @param string the end character. Usually an ellipsis
+ * @return string
+ */
function word_limiter($str, $limit = 100, $end_char = '…')
{
if (trim($str) == '')
@@ -69,19 +69,19 @@ if ( ! function_exists('word_limiter'))
// ------------------------------------------------------------------------
-/**
- * Character Limiter
- *
- * Limits the string based on the character count. Preserves complete words
- * so the character count may not be exactly as specified.
- *
- * @param string
- * @param int
- * @param string the end character. Usually an ellipsis
- * @return string
- */
if ( ! function_exists('character_limiter'))
{
+ /**
+ * Character Limiter
+ *
+ * Limits the string based on the character count. Preserves complete words
+ * so the character count may not be exactly as specified.
+ *
+ * @param string
+ * @param int
+ * @param string the end character. Usually an ellipsis
+ * @return string
+ */
function character_limiter($str, $n = 500, $end_char = '…')
{
if (strlen($str) < $n)
@@ -112,16 +112,16 @@ if ( ! function_exists('character_limiter'))
// ------------------------------------------------------------------------
-/**
- * High ASCII to Entities
- *
- * Converts High ascii text and MS Word special characters to character entities
- *
- * @param string
- * @return string
- */
if ( ! function_exists('ascii_to_entities'))
{
+ /**
+ * High ASCII to Entities
+ *
+ * Converts High ascii text and MS Word special characters to character entities
+ *
+ * @param string
+ * @return string
+ */
function ascii_to_entities($str)
{
$count = 1;
@@ -172,17 +172,17 @@ if ( ! function_exists('ascii_to_entities'))
// ------------------------------------------------------------------------
-/**
- * Entities to ASCII
- *
- * Converts character entities back to ASCII
- *
- * @param string
- * @param bool
- * @return string
- */
if ( ! function_exists('entities_to_ascii'))
{
+ /**
+ * Entities to ASCII
+ *
+ * Converts character entities back to ASCII
+ *
+ * @param string
+ * @param bool
+ * @return string
+ */
function entities_to_ascii($str, $all = TRUE)
{
if (preg_match_all('/\(\d+)\;/', $str, $matches))
@@ -227,20 +227,20 @@ if ( ! function_exists('entities_to_ascii'))
// ------------------------------------------------------------------------
-/**
- * Word Censoring Function
- *
- * Supply a string and an array of disallowed words and any
- * matched words will be converted to #### or to the replacement
- * word you've submitted.
- *
- * @param string the text string
- * @param string the array of censoered words
- * @param string the optional replacement value
- * @return string
- */
if ( ! function_exists('word_censor'))
{
+ /**
+ * Word Censoring Function
+ *
+ * Supply a string and an array of disallowed words and any
+ * matched words will be converted to #### or to the replacement
+ * word you've submitted.
+ *
+ * @param string the text string
+ * @param string the array of censoered words
+ * @param string the optional replacement value
+ * @return string
+ */
function word_censor($str, $censored, $replacement = '')
{
if ( ! is_array($censored))
@@ -274,16 +274,16 @@ if ( ! function_exists('word_censor'))
// ------------------------------------------------------------------------
-/**
- * Code Highlighter
- *
- * Colorizes code strings
- *
- * @param string the text string
- * @return string
- */
if ( ! function_exists('highlight_code'))
{
+ /**
+ * Code Highlighter
+ *
+ * Colorizes code strings
+ *
+ * @param string the text string
+ * @return string
+ */
function highlight_code($str)
{
// The highlight string function encodes and highlights
@@ -317,19 +317,19 @@ if ( ! function_exists('highlight_code'))
// ------------------------------------------------------------------------
-/**
- * Phrase Highlighter
- *
- * Highlights a phrase within a text string
- *
- * @param string the text string
- * @param string the phrase you'd like to highlight
- * @param string the openging tag to precede the phrase with
- * @param string the closing tag to end the phrase with
- * @return string
- */
if ( ! function_exists('highlight_phrase'))
{
+ /**
+ * Phrase Highlighter
+ *
+ * Highlights a phrase within a text string
+ *
+ * @param string the text string
+ * @param string the phrase you'd like to highlight
+ * @param string the openging tag to precede the phrase with
+ * @param string the closing tag to end the phrase with
+ * @return string
+ */
function highlight_phrase($str, $phrase, $tag_open = '', $tag_close = '')
{
if ($str == '')
@@ -348,14 +348,14 @@ if ( ! function_exists('highlight_phrase'))
// ------------------------------------------------------------------------
-/**
- * Convert Accented Foreign Characters to ASCII
- *
- * @param string the text string
- * @return string
- */
if ( ! function_exists('convert_accented_characters'))
{
+ /**
+ * Convert Accented Foreign Characters to ASCII
+ *
+ * @param string the text string
+ * @return string
+ */
function convert_accented_characters($str)
{
if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'))
@@ -378,19 +378,19 @@ if ( ! function_exists('convert_accented_characters'))
// ------------------------------------------------------------------------
-/**
- * Word Wrap
- *
- * Wraps text at the specified character. Maintains the integrity of words.
- * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor
- * will URLs.
- *
- * @param string the text string
- * @param int the number of characters to wrap at
- * @return string
- */
if ( ! function_exists('word_wrap'))
{
+ /**
+ * Word Wrap
+ *
+ * Wraps text at the specified character. Maintains the integrity of words.
+ * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor
+ * will URLs.
+ *
+ * @param string the text string
+ * @param int the number of characters to wrap at
+ * @return string
+ */
function word_wrap($str, $charlim = '76')
{
// Se the character limit
@@ -481,19 +481,19 @@ if ( ! function_exists('word_wrap'))
// ------------------------------------------------------------------------
-/**
- * Ellipsize String
- *
- * This function will strip tags from a string, split it at its max_length and ellipsize
- *
- * @param string string to ellipsize
- * @param int max length of string
- * @param mixed int (1|0) or float, .5, .2, etc for position to split
- * @param string ellipsis ; Default '...'
- * @return string ellipsized string
- */
if ( ! function_exists('ellipsize'))
{
+ /**
+ * Ellipsize String
+ *
+ * This function will strip tags from a string, split it at its max_length and ellipsize
+ *
+ * @param string string to ellipsize
+ * @param int max length of string
+ * @param mixed int (1|0) or float, .5, .2, etc for position to split
+ * @param string ellipsis ; Default '...'
+ * @return string ellipsized string
+ */
function ellipsize($str, $max_length, $position = 1, $ellipsis = '…')
{
// Strip tags
diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php
index 7a3db5d6b..af9d16a89 100644
--- a/system/helpers/typography_helper.php
+++ b/system/helpers/typography_helper.php
@@ -37,14 +37,14 @@
// ------------------------------------------------------------------------
-/**
- * Convert newlines to HTML line breaks except within PRE tags
- *
- * @param string
- * @return string
- */
if ( ! function_exists('nl2br_except_pre'))
{
+ /**
+ * Convert newlines to HTML line breaks except within PRE tags
+ *
+ * @param string
+ * @return string
+ */
function nl2br_except_pre($str)
{
$CI =& get_instance();
@@ -55,16 +55,16 @@ if ( ! function_exists('nl2br_except_pre'))
// ------------------------------------------------------------------------
-/**
- * Auto Typography Wrapper Function
- *
- * @param string
- * @param bool whether to allow javascript event handlers
- * @param bool whether to reduce multiple instances of double newlines to two
- * @return string
- */
if ( ! function_exists('auto_typography'))
{
+ /**
+ * Auto Typography Wrapper Function
+ *
+ * @param string
+ * @param bool whether to allow javascript event handlers
+ * @param bool whether to reduce multiple instances of double newlines to two
+ * @return string
+ */
function auto_typography($str, $strip_js_event_handlers = TRUE, $reduce_linebreaks = FALSE)
{
$CI =& get_instance();
@@ -73,20 +73,19 @@ if ( ! function_exists('auto_typography'))
}
}
-
// --------------------------------------------------------------------
-/**
- * HTML Entities Decode
- *
- * This function is a replacement for html_entity_decode()
- *
- * @param string
- * @param string
- * @return string
- */
if ( ! function_exists('entity_decode'))
{
+ /**
+ * HTML Entities Decode
+ *
+ * This function is a replacement for html_entity_decode()
+ *
+ * @param string
+ * @param string
+ * @return string
+ */
function entity_decode($str, $charset = NULL)
{
global $SEC;
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
index 5576c2748..fa685645a 100644
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -37,17 +37,17 @@
// ------------------------------------------------------------------------
-/**
- * Site URL
- *
- * Create a local URL based on your basepath. Segments can be passed via the
- * first parameter either as a string or an array.
- *
- * @param string
- * @return string
- */
if ( ! function_exists('site_url'))
{
+ /**
+ * Site URL
+ *
+ * Create a local URL based on your basepath. Segments can be passed via the
+ * first parameter either as a string or an array.
+ *
+ * @param string
+ * @return string
+ */
function site_url($uri = '')
{
$CI =& get_instance();
@@ -57,18 +57,18 @@ if ( ! function_exists('site_url'))
// ------------------------------------------------------------------------
-/**
- * Base URL
- *
- * Create a local URL based on your basepath.
- * Segments can be passed in as a string or an array, same as site_url
- * or a URL to a file can be passed in, e.g. to an image file.
- *
- * @param string
- * @return string
- */
if ( ! function_exists('base_url'))
{
+ /**
+ * Base URL
+ *
+ * Create a local URL based on your basepath.
+ * Segments can be passed in as a string or an array, same as site_url
+ * or a URL to a file can be passed in, e.g. to an image file.
+ *
+ * @param string
+ * @return string
+ */
function base_url($uri = '')
{
$CI =& get_instance();
@@ -78,16 +78,16 @@ if ( ! function_exists('base_url'))
// ------------------------------------------------------------------------
-/**
- * Current URL
- *
- * Returns the full URL (including segments) of the page where this
- * function is placed
- *
- * @return string
- */
if ( ! function_exists('current_url'))
{
+ /**
+ * Current URL
+ *
+ * Returns the full URL (including segments) of the page where this
+ * function is placed
+ *
+ * @return string
+ */
function current_url()
{
$CI =& get_instance();
@@ -96,15 +96,16 @@ if ( ! function_exists('current_url'))
}
// ------------------------------------------------------------------------
-/**
- * URL String
- *
- * Returns the URI segments.
- *
- * @return string
- */
+
if ( ! function_exists('uri_string'))
{
+ /**
+ * URL String
+ *
+ * Returns the URI segments.
+ *
+ * @return string
+ */
function uri_string()
{
$CI =& get_instance();
@@ -114,15 +115,15 @@ if ( ! function_exists('uri_string'))
// ------------------------------------------------------------------------
-/**
- * Index page
- *
- * Returns the "index_page" from your config file
- *
- * @return string
- */
if ( ! function_exists('index_page'))
{
+ /**
+ * Index page
+ *
+ * Returns the "index_page" from your config file
+ *
+ * @return string
+ */
function index_page()
{
$CI =& get_instance();
@@ -132,18 +133,18 @@ if ( ! function_exists('index_page'))
// ------------------------------------------------------------------------
-/**
- * Anchor Link
- *
- * Creates an anchor based on the local URL.
- *
- * @param string the URL
- * @param string the link title
- * @param mixed any attributes
- * @return string
- */
if ( ! function_exists('anchor'))
{
+ /**
+ * Anchor Link
+ *
+ * Creates an anchor based on the local URL.
+ *
+ * @param string the URL
+ * @param string the link title
+ * @param mixed any attributes
+ * @return string
+ */
function anchor($uri = '', $title = '', $attributes = '')
{
$title = (string) $title;
@@ -173,19 +174,19 @@ if ( ! function_exists('anchor'))
// ------------------------------------------------------------------------
-/**
- * Anchor Link - Pop-up version
- *
- * Creates an anchor based on the local URL. The link
- * opens a new window based on the attributes specified.
- *
- * @param string the URL
- * @param string the link title
- * @param mixed any attributes
- * @return string
- */
if ( ! function_exists('anchor_popup'))
{
+ /**
+ * Anchor Link - Pop-up version
+ *
+ * Creates an anchor based on the local URL. The link
+ * opens a new window based on the attributes specified.
+ *
+ * @param string the URL
+ * @param string the link title
+ * @param mixed any attributes
+ * @return string
+ */
function anchor_popup($uri = '', $title = '', $attributes = FALSE)
{
$title = (string) $title;
@@ -223,16 +224,16 @@ if ( ! function_exists('anchor_popup'))
// ------------------------------------------------------------------------
-/**
- * Mailto Link
- *
- * @param string the email address
- * @param string the link title
- * @param mixed any attributes
- * @return string
- */
if ( ! function_exists('mailto'))
{
+ /**
+ * Mailto Link
+ *
+ * @param string the email address
+ * @param string the link title
+ * @param mixed any attributes
+ * @return string
+ */
function mailto($email, $title = '', $attributes = '')
{
$title = (string) $title;
@@ -248,18 +249,18 @@ if ( ! function_exists('mailto'))
// ------------------------------------------------------------------------
-/**
- * Encoded Mailto Link
- *
- * Create a spam-protected mailto link written in Javascript
- *
- * @param string the email address
- * @param string the link title
- * @param mixed any attributes
- * @return string
- */
if ( ! function_exists('safe_mailto'))
{
+ /**
+ * Encoded Mailto Link
+ *
+ * Create a spam-protected mailto link written in Javascript
+ *
+ * @param string the email address
+ * @param string the link title
+ * @param mixed any attributes
+ * @return string
+ */
function safe_mailto($email, $title = '', $attributes = '')
{
$title = (string) $title;
@@ -357,21 +358,21 @@ if ( ! function_exists('safe_mailto'))
// ------------------------------------------------------------------------
-/**
- * Auto-linker
- *
- * Automatically links URL and Email addresses.
- * Note: There's a bit of extra code here to deal with
- * URLs or emails that end in a period. We'll strip these
- * off and add them after the link.
- *
- * @param string the string
- * @param string the type: email, url, or both
- * @param bool whether to create pop-up links
- * @return string
- */
if ( ! function_exists('auto_link'))
{
+ /**
+ * Auto-linker
+ *
+ * Automatically links URL and Email addresses.
+ * Note: There's a bit of extra code here to deal with
+ * URLs or emails that end in a period. We'll strip these
+ * off and add them after the link.
+ *
+ * @param string the string
+ * @param string the type: email, url, or both
+ * @param bool whether to create pop-up links
+ * @return string
+ */
function auto_link($str, $type = 'both', $popup = FALSE)
{
if ($type !== 'email' && preg_match_all('#(^|\s|\(|\b)((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i', $str, $matches))
@@ -423,16 +424,16 @@ if ( ! function_exists('auto_link'))
// ------------------------------------------------------------------------
-/**
- * Prep URL
- *
- * Simply adds the http:// part if no scheme is included
- *
- * @param string the URL
- * @return string
- */
if ( ! function_exists('prep_url'))
{
+ /**
+ * Prep URL
+ *
+ * Simply adds the http:// part if no scheme is included
+ *
+ * @param string the URL
+ * @return string
+ */
function prep_url($str = '')
{
if ($str === 'http://' OR $str == '')
@@ -453,20 +454,20 @@ if ( ! function_exists('prep_url'))
// ------------------------------------------------------------------------
-/**
- * Create URL Title
- *
- * Takes a "title" string as input and creates a
- * human-friendly URL string with a "separator" string
- * as the word separator.
- *
- * @param string the string
- * @param string the separator
- * @param bool
- * @return string
- */
if ( ! function_exists('url_title'))
{
+ /**
+ * Create URL Title
+ *
+ * Takes a "title" string as input and creates a
+ * human-friendly URL string with a "separator" string
+ * as the word separator.
+ *
+ * @param string the string
+ * @param string the separator
+ * @param bool
+ * @return string
+ */
function url_title($str, $separator = '-', $lowercase = FALSE)
{
if ($separator === 'dash')
@@ -504,19 +505,20 @@ if ( ! function_exists('url_title'))
// ------------------------------------------------------------------------
-/**
- * Header Redirect
- *
- * Header redirect in two flavors
- * For very fine grained control over headers, you could use the Output
- * Library's set_header() function.
- *
- * @param string the URL
- * @param string the method: location or refresh
- * @return string
- */
if ( ! function_exists('redirect'))
{
+ /**
+ * Header Redirect
+ *
+ * Header redirect in two flavors
+ * For very fine grained control over headers, you could use the Output
+ * Library's set_header() function.
+ *
+ * @param string the URL
+ * @param string the method: location or refresh
+ * @param int
+ * @return string
+ */
function redirect($uri = '', $method = 'auto', $http_response_code = 302)
{
if ( ! preg_match('#^https?://#i', $uri))
@@ -545,17 +547,17 @@ if ( ! function_exists('redirect'))
// ------------------------------------------------------------------------
-/**
- * Parse out the attributes
- *
- * Some of the functions use this
- *
- * @param array
- * @param bool
- * @return string
- */
if ( ! function_exists('_parse_attributes'))
{
+ /**
+ * Parse out the attributes
+ *
+ * Some of the functions use this
+ *
+ * @param array
+ * @param bool
+ * @return string
+ */
function _parse_attributes($attributes, $javascript = FALSE)
{
if (is_string($attributes))
diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php
index 67fd34b97..958c633dd 100644
--- a/system/helpers/xml_helper.php
+++ b/system/helpers/xml_helper.php
@@ -37,15 +37,15 @@
// ------------------------------------------------------------------------
-/**
- * Convert Reserved XML characters to Entities
- *
- * @param string
- * @param bool
- * @return string
- */
if ( ! function_exists('xml_convert'))
{
+ /**
+ * Convert Reserved XML characters to Entities
+ *
+ * @param string
+ * @param bool
+ * @return string
+ */
function xml_convert($str, $protect_all = FALSE)
{
$temp = '__TEMP_AMPERSANDS__';
--
cgit v1.2.3-24-g4f1b
From 827b3f0f6fa3fd62f0276908f38d23a4165f0f41 Mon Sep 17 00:00:00 2001
From: Chris Berthe
Date: Fri, 27 Apr 2012 23:36:54 -0400
Subject: Important spelling fix to CodeIgniter.php file
---
system/core/CodeIgniter.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index 793c4687e..349f9f2d0 100755
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
@@ -153,7 +153,7 @@
*
* Note: Order here is rather important as the UTF-8
* class needs to be used very early on, but it cannot
- * properly determine if UTf-8 can be supported until
+ * properly determine if UTF-8 can be supported until
* after the Config class is instantiated.
*
*/
--
cgit v1.2.3-24-g4f1b
From 193d448eec149b9b26c89a157c9394266a18ffae Mon Sep 17 00:00:00 2001
From: George Petsagourakis
Date: Sat, 28 Apr 2012 11:16:18 +0300
Subject: Minor assignment fix. Can not use $array[] for reading.
---
system/database/DB_query_builder.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index 393a1cd75..d0af66de1 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -281,7 +281,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$v = trim($v);
$this->_track_aliases($v);
- $v = $this->qb_from[] = $this->protect_identifiers($v, TRUE, NULL, FALSE);
+ $this->qb_from[] = $v = $this->protect_identifiers($v, TRUE, NULL, FALSE);
if ($this->qb_caching === TRUE)
{
--
cgit v1.2.3-24-g4f1b
From e57411502933afad6fca682efb437db05998e532 Mon Sep 17 00:00:00 2001
From: Phil Sturgeon
Date: Mon, 30 Apr 2012 17:57:37 +0200
Subject: Reverted recent commit, cookie_prefix was breaking things.
---
system/core/Input.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/system/core/Input.php b/system/core/Input.php
index 7594a2e45..fc2a550bc 100755
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -226,7 +226,6 @@ class CI_Input {
*/
public function cookie($index = '', $xss_clean = FALSE)
{
- $index = config_item('cookie_prefix').$index;
return $this->_fetch_from_array($_COOKIE, $index, $xss_clean);
}
--
cgit v1.2.3-24-g4f1b
From a5918ebb5354f6e8bea0149fd95fc98412d461eb Mon Sep 17 00:00:00 2001
From: Cosmin Atanasiu
Date: Mon, 30 Apr 2012 22:46:20 -0700
Subject: Update system/libraries/Javascript.php
---
system/libraries/Javascript.php | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php
index 21c9e11bd..b56dd9888 100644
--- a/system/libraries/Javascript.php
+++ b/system/libraries/Javascript.php
@@ -723,7 +723,14 @@ class CI_Javascript {
{
if (is_object($result))
{
- $json_result = (array)$result;
+ if (is_callable( array( $result, "result_array" ) ))
+ {
+ $json_result = $result->result_array();
+ }
+ else
+ {
+ $json_result = (array)$result;
+ }
}
elseif (is_array($result))
{
--
cgit v1.2.3-24-g4f1b
From 0b10a8c71cd8a60281f8dbe872ae4ba0404ac2c3 Mon Sep 17 00:00:00 2001
From: Cosmin Atanasiu
Date: Mon, 30 Apr 2012 22:51:17 -0700
Subject: Update system/libraries/Javascript.php
---
system/libraries/Javascript.php | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php
index b56dd9888..008136192 100644
--- a/system/libraries/Javascript.php
+++ b/system/libraries/Javascript.php
@@ -723,14 +723,14 @@ class CI_Javascript {
{
if (is_object($result))
{
- if (is_callable( array( $result, "result_array" ) ))
- {
- $json_result = $result->result_array();
- }
- else
- {
- $json_result = (array)$result;
- }
+ if (is_callable( array( $result, "result_array" ) ))
+ {
+ $json_result = $result->result_array();
+ }
+ else
+ {
+ $json_result = (array)$result;
+ }
}
elseif (is_array($result))
{
--
cgit v1.2.3-24-g4f1b
From 3259e98b2b775d6dd932e03ae37b08c6e0465898 Mon Sep 17 00:00:00 2001
From: Cosmin Atanasiu
Date: Tue, 1 May 2012 20:41:46 -0700
Subject: Update system/libraries/Javascript.php
---
system/libraries/Javascript.php | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php
index 008136192..dd2df697c 100644
--- a/system/libraries/Javascript.php
+++ b/system/libraries/Javascript.php
@@ -723,14 +723,7 @@ class CI_Javascript {
{
if (is_object($result))
{
- if (is_callable( array( $result, "result_array" ) ))
- {
- $json_result = $result->result_array();
- }
- else
- {
- $json_result = (array)$result;
- }
+ $json_result = is_callable(array($result, 'result_array')) ? $result->result_array() : (array) $result;
}
elseif (is_array($result))
{
--
cgit v1.2.3-24-g4f1b
From 1a3885babb73870ef99af24297c722d8251480a1 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Wed, 2 May 2012 10:23:12 +0300
Subject: Fix pagination anchor_class with multiple initializations
---
system/libraries/Pagination.php | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php
index 0fe73d69f..3d2911813 100644
--- a/system/libraries/Pagination.php
+++ b/system/libraries/Pagination.php
@@ -94,17 +94,16 @@ class CI_Pagination {
{
foreach ($params as $key => $val)
{
- if (isset($this->$key))
+ if ($key === 'anchor_class')
+ {
+ $this->anchor_class = ($val != '') ? 'class="'.$val.'" ' : '';
+ }
+ elseif (isset($this->$key))
{
$this->$key = $val;
}
}
}
-
- if ($this->anchor_class != '')
- {
- $this->anchor_class = 'class="'.$this->anchor_class.'" ';
- }
}
// --------------------------------------------------------------------
--
cgit v1.2.3-24-g4f1b
From 963c96c5507ceb8b5c3de50d0ab959d21dcc8cd1 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Wed, 2 May 2012 13:09:57 +0300
Subject: Fix a wrong variable name
---
system/helpers/text_helper.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index daf31c3d6..c1c0eb947 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -377,7 +377,7 @@ if ( ! function_exists('convert_accented_characters'))
include(APPPATH.'config/foreign_chars.php');
}
- if ( ! isset($foreign_characters) OR ! is_array($foreign_chars))
+ if ( ! isset($foreign_characters) OR ! is_array($foreign_characters))
{
return $str;
}
--
cgit v1.2.3-24-g4f1b
From 58dc75471c25f33b059967ffb515eedc08e86a0b Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Wed, 2 May 2012 13:24:19 +0300
Subject: Some line separation for better readability
---
system/database/drivers/sqlite/sqlite_forge.php | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php
index ce8eac91e..0a1c156be 100644
--- a/system/database/drivers/sqlite/sqlite_forge.php
+++ b/system/database/drivers/sqlite/sqlite_forge.php
@@ -105,10 +105,15 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
$sql .= "\n\t".$this->db->protect_identifiers($field)
.' '.$attributes['TYPE']
+
.( ! empty($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '')
+
.(( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
+
.(isset($attributes['DEFAULT']) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '')
+
.(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+
.(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '');
}
--
cgit v1.2.3-24-g4f1b
From 3110a0a3cc6b25985acc251799ca9cc97f92ce03 Mon Sep 17 00:00:00 2001
From: Phil Sturgeon
Date: Wed, 2 May 2012 11:37:31 +0100
Subject: Added a phpDocumenter config file
Allows API documentation to be built very easily. Wether or not
CodeIgniter will support property docblocks or not is currently in
question, but at least everything else will show up.
---
phpdoc.dist.xml | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
create mode 100644 phpdoc.dist.xml
diff --git a/phpdoc.dist.xml b/phpdoc.dist.xml
new file mode 100644
index 000000000..f1fcc6225
--- /dev/null
+++ b/phpdoc.dist.xml
@@ -0,0 +1,25 @@
+
+
+ CodeIgniter v3.0.0 API
+
+ ./api/
+
+
+ ./api/
+
+
+ .
+ ./application/*
+ ./tests/*
+ ./user_guide_src/*
+ ./views/*
+
+
+
+ warn
+
+ ./api/log/{DATE}.log
+ ./api/{DATE}.errors.log
+
+
+
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 81aa94bbb533737c19a705d5b8864bd47fbab85c Mon Sep 17 00:00:00 2001
From: Phil Sturgeon
Date: Wed, 2 May 2012 11:40:46 +0100
Subject: Reverted rui_string change.
This had knock-on effects as can be seen in #1306. Issue #122 has been
reopend until it is fixed properly.
---
system/core/Router.php | 5 +----
system/core/URI.php | 4 ++--
user_guide_src/source/changelog.rst | 2 ++
3 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/system/core/Router.php b/system/core/Router.php
index fe9909b06..9314052fe 100755
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -242,12 +242,9 @@ class CI_Router {
$segments[1] = 'index';
}
- // This is being routed to a file in a sub directory
- $this->directory and array_unshift($segments, trim($this->directory, '/'));
-
// Update our "routed" segment array to contain the segments.
// Note: If there is no custom routing, this array will be
- // identical to $this->uri->segments
+ // identical to $this->uri->segments
$this->uri->rsegments = $segments;
}
diff --git a/system/core/URI.php b/system/core/URI.php
index 705575a0c..cf82c5838 100755
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -645,10 +645,10 @@ class CI_URI {
*/
public function ruri_string()
{
- return implode('/', $this->rsegment_array());
+ return '/'.implode('/', $this->rsegment_array());
}
}
/* End of file URI.php */
-/* Location: ./system/core/URI.php */
\ No newline at end of file
+/* Location: ./system/core/URI.php */
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index bdb418f86..95e32f793 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -204,6 +204,7 @@ Bug fixes for 3.0
- Fixed a bug (#23, #1238) - delete_all() in the `Database Caching Library ` used to delete .htaccess and index.html files, which is a potential security risk.
- Fixed a bug in :doc:`Trackback Library ` method validate_url() where it didn't actually do anything, due to input not being passed by reference.
- Fixed a bug (#11, #183, #863) - CI_Form_validation::_execute() silently continued to the next rule, if a rule method/function is not found.
+<<<<<<< HEAD
- Fixed a bug (#122) Where routed uri string was being reported incorrectly in sub-directories
- Fixed a bug (#1242) - read_dir() in the :doc:`Zip Library ` wasn't compatible with Windows.
- Fixed a bug (#306) - ODBC driver didn't have an _insert_batch() method, which resulted in fatal error being triggered when insert_batch() is used with it.
@@ -214,6 +215,7 @@ Bug fixes for 3.0
- Fixed a bug in SQLSRV's delete() method where like() and limit() conditions were ignored.
- Fixed a bug (#1265) - Database connections were always closed, regardless of the 'pconnect' option value.
- Fixed a bug (#128) - :doc:`Language Library ` did not correctly keep track of loaded language files.
+- Fixed a bug (#1242) Added Windows path compatibility to function read_dir of ZIP library
Version 2.1.1
=============
--
cgit v1.2.3-24-g4f1b
From ee04a913dfd78d394a0e09f01655df0870369512 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Wed, 2 May 2012 13:41:23 +0300
Subject: Changelog fix
---
user_guide_src/source/changelog.rst | 1 -
1 file changed, 1 deletion(-)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 95e32f793..bbbe6f718 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -204,7 +204,6 @@ Bug fixes for 3.0
- Fixed a bug (#23, #1238) - delete_all() in the `Database Caching Library ` used to delete .htaccess and index.html files, which is a potential security risk.
- Fixed a bug in :doc:`Trackback Library ` method validate_url() where it didn't actually do anything, due to input not being passed by reference.
- Fixed a bug (#11, #183, #863) - CI_Form_validation::_execute() silently continued to the next rule, if a rule method/function is not found.
-<<<<<<< HEAD
- Fixed a bug (#122) Where routed uri string was being reported incorrectly in sub-directories
- Fixed a bug (#1242) - read_dir() in the :doc:`Zip Library ` wasn't compatible with Windows.
- Fixed a bug (#306) - ODBC driver didn't have an _insert_batch() method, which resulted in fatal error being triggered when insert_batch() is used with it.
--
cgit v1.2.3-24-g4f1b
From c821a587dce2da70bab3f5955f2b40c6a3c194f5 Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Wed, 2 May 2012 10:37:01 -0400
Subject: Fix phpdoc config file
---
phpdoc.dist.xml | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/phpdoc.dist.xml b/phpdoc.dist.xml
index f1fcc6225..6dc58c259 100644
--- a/phpdoc.dist.xml
+++ b/phpdoc.dist.xml
@@ -8,11 +8,7 @@
./api/
- .
- ./application/*
- ./tests/*
- ./user_guide_src/*
- ./views/*
+ ./system
--
cgit v1.2.3-24-g4f1b
From 2d51c08027382cc10692188ccb68789daf2f2083 Mon Sep 17 00:00:00 2001
From: George Petsagourakis
Date: Wed, 2 May 2012 20:29:04 +0300
Subject: Fixing some typos.
---
system/libraries/Form_validation.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index a52cad5ff..5547c6a69 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -1005,7 +1005,7 @@ class CI_Form_validation {
return (MB_ENABLED === TRUE)
? ($val <= mb_strlen($str))
- : ($val <= strlen(str));
+ : ($val <= strlen($str));
}
// --------------------------------------------------------------------
--
cgit v1.2.3-24-g4f1b
From 306b378525a13d9c5d1a7f0d6d50c2f263f22a04 Mon Sep 17 00:00:00 2001
From: George Petsagourakis
Date: Wed, 2 May 2012 20:31:08 +0300
Subject: Fixing some typos in the xmlrpc class. Also, fputs is an alias for
fwrite.
---
system/libraries/Xmlrpc.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php
index 7009deacc..0d2533855 100644
--- a/system/libraries/Xmlrpc.php
+++ b/system/libraries/Xmlrpc.php
@@ -436,7 +436,7 @@ class XML_RPC_Client extends CI_Xmlrpc
*/
public function sendPayload($msg)
{
- $fp = @fsockopen($this->server, $this->port,$this->errno, $this->errstr, $this->timeout);
+ $fp = @fsockopen($this->server, $this->port,$this->errno, $this->errstring, $this->timeout);
if ( ! is_resource($fp))
{
@@ -458,7 +458,7 @@ class XML_RPC_Client extends CI_Xmlrpc
.'Content-Length: '.strlen($msg->payload).$r.$r
.$msg->payload;
- if ( ! fputs($fp, $op, strlen($op)))
+ if ( ! fwrite($fp, $op, strlen($op)))
{
error_log($this->xmlrpcstr['http_error']);
return new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']);
@@ -1076,7 +1076,7 @@ class XML_RPC_Message extends CI_Xmlrpc
// we have an I4/INT
// we must check that only 0123456789- are characters here
$this->xh[$the_parser]['value'] = preg_match('/^[+-]?[0-9\t ]+$/', $this->xh[$the_parser]['ac'])
- ? (int) $this->xh[$the_parset]['ac']
+ ? (int) $this->xh[$the_parser]['ac']
: 'ERROR_NON_NUMERIC_FOUND';
}
$this->xh[$the_parser]['ac'] = '';
--
cgit v1.2.3-24-g4f1b
From 190c6bb125447f83793d9437f1bea28feada910a Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Thu, 3 May 2012 12:13:39 +0700
Subject: Cleaning up
---
tests/codeigniter/database/query_builder/insert_test.php | 5 ++---
tests/codeigniter/database/query_builder/select_test.php | 16 ++++++++--------
2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php
index 53ce23c19..8ba60e242 100644
--- a/tests/codeigniter/database/query_builder/insert_test.php
+++ b/tests/codeigniter/database/query_builder/insert_test.php
@@ -30,11 +30,10 @@ class Insert_test extends CI_TestCase {
// Do normal insert
$this->assertTrue($this->db->insert('job', $job_data));
- $jobs = $this->db->get('job')->result_array();
- $job1 = $jobs[0];
+ $job1 = $this->db->get('job')->row();
// Check the result
- $this->assertEquals('Grocery Sales', $job1['name']);
+ $this->assertEquals('Grocery Sales', $job1->name);
}
diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php
index dbf432a7c..0d299ed16 100644
--- a/tests/codeigniter/database/query_builder/select_test.php
+++ b/tests/codeigniter/database/query_builder/select_test.php
@@ -41,10 +41,10 @@ class Select_test extends CI_TestCase {
{
$job_min = $this->db->select_min('id')
->get('job')
- ->result_array();
+ ->row();
// Minimum id was 1
- $this->assertEquals('1', $job_min[0]['id']);
+ $this->assertEquals('1', $job_min->id);
}
// ------------------------------------------------------------------------
@@ -56,10 +56,10 @@ class Select_test extends CI_TestCase {
{
$job_max = $this->db->select_max('id')
->get('job')
- ->result_array();
+ ->row();
// Maximum id was 4
- $this->assertEquals('4', $job_max[0]['id']);
+ $this->assertEquals('4', $job_max->id);
}
// ------------------------------------------------------------------------
@@ -71,10 +71,10 @@ class Select_test extends CI_TestCase {
{
$job_avg = $this->db->select_avg('id')
->get('job')
- ->result_array();
+ ->row();
// Average should be 2.5
- $this->assertEquals('2.5', $job_avg[0]['id']);
+ $this->assertEquals('2.5', $job_avg->id);
}
// ------------------------------------------------------------------------
@@ -86,10 +86,10 @@ class Select_test extends CI_TestCase {
{
$job_sum = $this->db->select_sum('id')
->get('job')
- ->result_array();
+ ->row();
// Sum of ids should be 10
- $this->assertEquals('10', $job_sum[0]['id']);
+ $this->assertEquals('10', $job_sum->id);
}
}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 6e131cbd0a5243f29a5ad9f56c80715e534e4267 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Thu, 3 May 2012 12:14:19 +0700
Subject: FROM clause API code-coverage
---
.../database/query_builder/from_test.php | 51 ++++++++++++++++++++++
1 file changed, 51 insertions(+)
create mode 100644 tests/codeigniter/database/query_builder/from_test.php
diff --git a/tests/codeigniter/database/query_builder/from_test.php b/tests/codeigniter/database/query_builder/from_test.php
new file mode 100644
index 000000000..95ae4dfdb
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/from_test.php
@@ -0,0 +1,51 @@
+db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_from_simple()
+ {
+ $jobs = $this->db->from('job')
+ ->get()
+ ->result_array();
+
+ // Check items
+ $this->assertEquals(4, count($jobs));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_from_with_where()
+ {
+ $job1 = $this->db->from('job')
+ ->where('id', 1)
+ ->get()
+ ->row();
+
+ // Check the result
+ $this->assertEquals('1', $job1->id);
+ $this->assertEquals('Developer', $job1->name);
+ $this->assertEquals('Awesome job, but sometimes makes you bored', $job1->description);
+ }
+
+}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 17f799e1017d1688a2890a1ba78e4f53d80af77e Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Thu, 3 May 2012 15:15:40 +0700
Subject: Add user entity into schema skeleton
---
tests/mocks/database/schema/skeleton.php | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
index a3d5bac65..fbd533bfb 100644
--- a/tests/mocks/database/schema/skeleton.php
+++ b/tests/mocks/database/schema/skeleton.php
@@ -50,6 +50,24 @@ class Mock_Database_Schema_Skeleton {
*/
public static function create_tables()
{
+ // User Table
+ static::$forge->add_field(array(
+ 'id' => array(
+ 'type' => 'INTEGER',
+ 'constraint' => 3,
+ ),
+ 'name' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40,
+ ),
+ 'email' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 100,
+ ),
+ ));
+ static::$forge->add_key('id', TRUE);
+ static::$forge->create_table('user', (strpos(static::$driver, 'pgsql') === FALSE));
+
// Job Table
static::$forge->add_field(array(
'id' => array(
@@ -77,6 +95,12 @@ class Mock_Database_Schema_Skeleton {
{
// Job Data
$data = array(
+ 'user' => array(
+ array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com'),
+ array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com'),
+ array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com'),
+ array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com'),
+ )
'job' => array(
array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'),
array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'),
--
cgit v1.2.3-24-g4f1b
From f074dff71f136860102a6042dccd3ff6db02d9f4 Mon Sep 17 00:00:00 2001
From: ThallisPHP
Date: Thu, 3 May 2012 16:01:46 -0300
Subject: Update system/libraries/Cart.php - To enable integrity when using
associative arrays
---
system/libraries/Cart.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php
index eee123584..9f258beb3 100644
--- a/system/libraries/Cart.php
+++ b/system/libraries/Cart.php
@@ -244,7 +244,7 @@ class CI_Cart {
// This becomes the unique "row ID"
if (isset($items['options']) && count($items['options']) > 0)
{
- $rowid = md5($items['id'].implode('', $items['options']));
+ $rowid = md5($items['id'].serialize($items['options']));
}
else
{
--
cgit v1.2.3-24-g4f1b
From d6b41bb2659f959da01aee0ddb38bb4bce6cd4b6 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Fri, 4 May 2012 15:05:22 +0700
Subject: JOIN clause API code-coverage
---
.../database/query_builder/join_test.php | 38 ++++++++++++++++++++++
tests/mocks/database/schema/skeleton.php | 2 +-
2 files changed, 39 insertions(+), 1 deletion(-)
create mode 100644 tests/codeigniter/database/query_builder/join_test.php
diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php
new file mode 100644
index 000000000..e05329d67
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/join_test.php
@@ -0,0 +1,38 @@
+db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_join_simple()
+ {
+ $job_user = $this->db->select('job.id as job_id, job.name as job_name, user.id as user_id, user.name as user_name')
+ ->from('job')
+ ->join('user', 'user.id = job.id')
+ ->get()
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals('1', $job_user[0]['job_id']);
+ $this->assertEquals('1', $job_user[0]['user_id']);
+ $this->assertEquals('Derek Jones', $job_user[0]['user_name']);
+ $this->assertEquals('Developer', $job_user[0]['job_name']);
+ }
+
+}
\ No newline at end of file
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
index fbd533bfb..9ebd6e85f 100644
--- a/tests/mocks/database/schema/skeleton.php
+++ b/tests/mocks/database/schema/skeleton.php
@@ -100,7 +100,7 @@ class Mock_Database_Schema_Skeleton {
array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com'),
array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com'),
array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com'),
- )
+ ),
'job' => array(
array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'),
array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'),
--
cgit v1.2.3-24-g4f1b
From 12f5475e2b279d1c2361ad5fc85bc2ba0d0f9033 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Fri, 4 May 2012 15:46:39 +0700
Subject: WHERE clause API code-coverage
---
.../database/query_builder/where_test.php | 144 +++++++++++++++++++++
1 file changed, 144 insertions(+)
create mode 100644 tests/codeigniter/database/query_builder/where_test.php
diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php
new file mode 100644
index 000000000..607eaa076
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/where_test.php
@@ -0,0 +1,144 @@
+db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_where_simple_key_value()
+ {
+ $job1 = $this->db->where('id', 1)
+ ->get('job')
+ ->row();
+
+ // Check the result
+ $this->assertEquals('1', $job1->id);
+ $this->assertEquals('Developer', $job1->name);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_where_custom_key_value()
+ {
+ $jobs = $this->db->where('id !=', 1)
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(3, count($jobs));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_where_associative_array()
+ {
+ $where = array('id >' => 2, 'name !=' => 'Accountant');
+ $jobs = $this->db->where($where)
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(1, count($jobs));
+
+ // Should be Musician
+ $job = current($jobs);
+
+ $this->assertEquals('Musician', $job['name']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_where_custom_string()
+ {
+ $where = "id > 2 AND name != 'Accountant'";
+ $jobs = $this->db->where($where)
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(1, count($jobs));
+
+ // Should be Musician
+ $job = current($jobs);
+
+ $this->assertEquals('Musician', $job['name']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_where_or()
+ {
+ $jobs = $this->db->where('name !=', 'Accountant')
+ ->or_where('id >', 3)
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(3, count($jobs));
+ $this->assertEquals('Developer', $jobs[0]['name']);
+ $this->assertEquals('Politician', $jobs[1]['name']);
+ $this->assertEquals('Musician', $jobs[2]['name']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_where_in()
+ {
+ $jobs = $this->db->where_in('name', array('Politician', 'Accountant'))
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(2, count($jobs));
+ $this->assertEquals('Politician', $jobs[0]['name']);
+ $this->assertEquals('Accountant', $jobs[1]['name']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_where_not_in()
+ {
+ $jobs = $this->db->where_not_in('name', array('Politician', 'Accountant'))
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(2, count($jobs));
+ $this->assertEquals('Developer', $jobs[0]['name']);
+ $this->assertEquals('Musician', $jobs[1]['name']);
+ }
+
+}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From f78018ec6b081518e4be24934448862a31bda9f8 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Fri, 4 May 2012 15:53:55 +0700
Subject: LIKE clause API code-coverage
---
.../database/query_builder/like_test.php | 90 ++++++++++++++++++++++
1 file changed, 90 insertions(+)
create mode 100644 tests/codeigniter/database/query_builder/like_test.php
diff --git a/tests/codeigniter/database/query_builder/like_test.php b/tests/codeigniter/database/query_builder/like_test.php
new file mode 100644
index 000000000..df98c713f
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/like_test.php
@@ -0,0 +1,90 @@
+db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_like()
+ {
+ $job1 = $this->db->like('name', 'veloper')
+ ->get('job')
+ ->row();
+
+ // Check the result
+ $this->assertEquals('1', $job1->id);
+ $this->assertEquals('Developer', $job1->name);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_or_like()
+ {
+ $jobs = $this->db->like('name', 'ian')
+ ->or_like('name', 'veloper')
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(3, count($jobs));
+ $this->assertEquals('Developer', $jobs[0]['name']);
+ $this->assertEquals('Politician', $jobs[1]['name']);
+ $this->assertEquals('Musician', $jobs[2]['name']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_not_like()
+ {
+ $jobs = $this->db->not_like('name', 'veloper')
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(3, count($jobs));
+ $this->assertEquals('Politician', $jobs[0]['name']);
+ $this->assertEquals('Accountant', $jobs[1]['name']);
+ $this->assertEquals('Musician', $jobs[2]['name']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_or_not_like()
+ {
+ $jobs = $this->db->like('name', 'an')
+ ->or_not_like('name', 'veloper')
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(3, count($jobs));
+ $this->assertEquals('Politician', $jobs[0]['name']);
+ $this->assertEquals('Accountant', $jobs[1]['name']);
+ $this->assertEquals('Musician', $jobs[2]['name']);
+ }
+
+}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 4c316b6bdfa970e98127ea280fcc77ff1288190f Mon Sep 17 00:00:00 2001
From: Michiel Vugteveen
Date: Fri, 4 May 2012 11:32:48 +0200
Subject: unset userdata
---
system/libraries/Session.php | 45 +++++++++++++++++++++++---------------------
1 file changed, 24 insertions(+), 21 deletions(-)
diff --git a/system/libraries/Session.php b/system/libraries/Session.php
index 3fa446d84..3195f0a91 100644
--- a/system/libraries/Session.php
+++ b/system/libraries/Session.php
@@ -36,146 +36,146 @@
*/
class CI_Session {
- /**
+ /**
* Whether to encrypt the session cookie
*
* @var bool
*/
public $sess_encrypt_cookie = FALSE;
-
+
/**
* Whether to use to the database for session storage
*
* @var bool
*/
public $sess_use_database = FALSE;
-
+
/**
* Name of the database table in which to store sessions
*
* @var string
*/
public $sess_table_name = '';
-
+
/**
* Length of time (in seconds) for sessions to expire
*
* @var int
*/
public $sess_expiration = 7200;
-
+
/**
* Whether to kill session on close of browser window
*
* @var bool
*/
public $sess_expire_on_close = FALSE;
-
+
/**
* Whether to match session on ip address
*
* @var bool
*/
public $sess_match_ip = FALSE;
-
+
/**
* Whether to match session on user-agent
*
* @var bool
*/
public $sess_match_useragent = TRUE;
-
+
/**
* Name of session cookie
*
* @var string
*/
public $sess_cookie_name = 'ci_session';
-
+
/**
* Session cookie prefix
*
* @var string
*/
public $cookie_prefix = '';
-
+
/**
* Session cookie path
*
* @var string
*/
public $cookie_path = '';
-
+
/**
* Session cookie domain
*
* @var string
*/
public $cookie_domain = '';
-
+
/**
* Whether to set the cookie only on HTTPS connections
*
* @var bool
*/
public $cookie_secure = FALSE;
-
+
/**
* Whether cookie should be allowed only to be sent by the server
*
* @var bool
*/
public $cookie_httponly = FALSE;
-
+
/**
* Interval at which to update session
*
* @var int
*/
public $sess_time_to_update = 300;
-
+
/**
* Key with which to encrypt the session cookie
*
* @var string
*/
public $encryption_key = '';
-
+
/**
* String to indicate flash data cookies
*
* @var string
*/
public $flashdata_key = 'flash';
-
+
/**
* Function to use to get the current time
*
* @var string
*/
public $time_reference = 'time';
-
+
/**
* Probablity level of garbage collection of old sessions
*
* @var int
*/
public $gc_probability = 5;
-
+
/**
* Session data
*
* @var array
*/
public $userdata = array();
-
+
/**
* Reference to CodeIgniter instance
*
* @var object
*/
public $CI;
-
+
/**
* Current time
*
@@ -570,6 +570,9 @@ class CI_Session {
$this->cookie_domain,
0
);
+
+ // Kill session data
+ $this->userdata = array();
}
// --------------------------------------------------------------------
--
cgit v1.2.3-24-g4f1b
From 0e18f625e10a8d8ba57c58c8597875c342cfa3e6 Mon Sep 17 00:00:00 2001
From: Michiel Vugteveen
Date: Fri, 4 May 2012 11:41:32 +0200
Subject: changelog entry
---
user_guide_src/source/changelog.rst | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index bbbe6f718..a70531901 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -55,7 +55,7 @@ Release Date: Not Released
- Database
- - Renamed the Active Record class to Query Builder to remove confusion with
+ - Renamed the Active Record class to Query Builder to remove confusion with
the Active Record design pattern
- Added new :doc:`Query Builder ` methods that return
- Added the ability to insert objects with insert_batch() in :doc:`Query Builder `.
@@ -215,6 +215,7 @@ Bug fixes for 3.0
- Fixed a bug (#1265) - Database connections were always closed, regardless of the 'pconnect' option value.
- Fixed a bug (#128) - :doc:`Language Library ` did not correctly keep track of loaded language files.
- Fixed a bug (#1242) Added Windows path compatibility to function read_dir of ZIP library
+- Fixed a bug (#1314) sess_destroy() did not destroy userdata.
Version 2.1.1
=============
--
cgit v1.2.3-24-g4f1b
From 4e607b00b2c56b7fdcc5f1d1a290be2363c74a46 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Fri, 4 May 2012 19:22:48 +0700
Subject: GROUP BY clause API code-coverage
---
.travis.yml | 3 +-
.../database/query_builder/group_test.php | 37 ++++++++++++++++++++++
2 files changed, 39 insertions(+), 1 deletion(-)
create mode 100644 tests/codeigniter/database/query_builder/group_test.php
diff --git a/.travis.yml b/.travis.yml
index 97ea0422d..971f62f38 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,4 +25,5 @@ script: phpunit --configuration tests/travis/$DB.phpunit.xml
branches:
only:
- develop
- - master
\ No newline at end of file
+ - master
+ - db-tests
\ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php
new file mode 100644
index 000000000..ddb2d0d6a
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/group_test.php
@@ -0,0 +1,37 @@
+db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_group_by()
+ {
+ $jobs = $this->db->select('name')
+ ->from('job')
+ ->group_by('name HAVING SUM(id) > 2')
+ ->get()
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(2, count($jobs));
+ $this->assertEquals('Accountant', $jobs[0]['name']);
+ $this->assertEquals('Musician', $jobs[1]['name']);
+ }
+
+}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From f7377abee2ef1e165a362edc9a1c650373a002ca Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Fri, 4 May 2012 19:42:24 +0700
Subject: Trace error
---
.../database/query_builder/group_test.php | 8 ++++----
tests/mocks/database/ci_test.sqlite | Bin 17408 -> 19456 bytes
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php
index ddb2d0d6a..dd248ae9a 100644
--- a/tests/codeigniter/database/query_builder/group_test.php
+++ b/tests/codeigniter/database/query_builder/group_test.php
@@ -22,16 +22,16 @@ class Group_test extends CI_TestCase {
*/
public function test_group_by()
{
- $jobs = $this->db->select('name')
+ $jobs = $this->db->select('job.name as job_name, job.id as job_id')
->from('job')
- ->group_by('name HAVING SUM(id) > 2')
+ ->group_by('job_name HAVING SUM(job_id) > 2')
->get()
->result_array();
// Check the result
$this->assertEquals(2, count($jobs));
- $this->assertEquals('Accountant', $jobs[0]['name']);
- $this->assertEquals('Musician', $jobs[1]['name']);
+ $this->assertEquals('Accountant', $jobs[0]['job_name']);
+ $this->assertEquals('Musician', $jobs[1]['job_name']);
}
}
\ No newline at end of file
diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite
index 86d868af2..e4128b23f 100755
Binary files a/tests/mocks/database/ci_test.sqlite and b/tests/mocks/database/ci_test.sqlite differ
--
cgit v1.2.3-24-g4f1b
From 1afd479059c3d6f7c46aa0c36aa56cfba7f94226 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Fri, 4 May 2012 20:34:30 +0700
Subject: HAVING clause API code-coverage
---
.../database/query_builder/group_test.php | 24 +++++++++++++++++----
tests/mocks/database/ci_test.sqlite | Bin 19456 -> 19456 bytes
tests/mocks/database/schema/skeleton.php | 12 +++++++----
3 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php
index dd248ae9a..7d8abc33f 100644
--- a/tests/codeigniter/database/query_builder/group_test.php
+++ b/tests/codeigniter/database/query_builder/group_test.php
@@ -22,16 +22,32 @@ class Group_test extends CI_TestCase {
*/
public function test_group_by()
{
- $jobs = $this->db->select('job.name as job_name, job.id as job_id')
+ $jobs = $this->db->select('name')
->from('job')
- ->group_by('job_name HAVING SUM(job_id) > 2')
+ ->group_by('name')
+ ->get()
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(4, count($jobs));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_having_by()
+ {
+ $jobs = $this->db->select('name')
+ ->from('job')
+ ->group_by('name')
+ ->having('SUM(id) > 2')
->get()
->result_array();
// Check the result
$this->assertEquals(2, count($jobs));
- $this->assertEquals('Accountant', $jobs[0]['job_name']);
- $this->assertEquals('Musician', $jobs[1]['job_name']);
}
}
\ No newline at end of file
diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite
index e4128b23f..d48e3317f 100755
Binary files a/tests/mocks/database/ci_test.sqlite and b/tests/mocks/database/ci_test.sqlite differ
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
index 9ebd6e85f..671336cc4 100644
--- a/tests/mocks/database/schema/skeleton.php
+++ b/tests/mocks/database/schema/skeleton.php
@@ -64,6 +64,10 @@ class Mock_Database_Schema_Skeleton {
'type' => 'VARCHAR',
'constraint' => 100,
),
+ 'country' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40,
+ ),
));
static::$forge->add_key('id', TRUE);
static::$forge->create_table('user', (strpos(static::$driver, 'pgsql') === FALSE));
@@ -96,10 +100,10 @@ class Mock_Database_Schema_Skeleton {
// Job Data
$data = array(
'user' => array(
- array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com'),
- array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com'),
- array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com'),
- array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com'),
+ array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com', 'country' => 'US'),
+ array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com', 'country' => 'Iran'),
+ array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com', 'country' => 'US'),
+ array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com', 'country' => 'UK'),
),
'job' => array(
array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'),
--
cgit v1.2.3-24-g4f1b
From 44d8d881b401238661d81fc9db10482604b4cf43 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Fri, 4 May 2012 20:43:45 +0700
Subject: DISTINCT clause API code-coverage
---
.../database/query_builder/distinct_test.php | 34 ++++++++++++++++++++++
1 file changed, 34 insertions(+)
create mode 100644 tests/codeigniter/database/query_builder/distinct_test.php
diff --git a/tests/codeigniter/database/query_builder/distinct_test.php b/tests/codeigniter/database/query_builder/distinct_test.php
new file mode 100644
index 000000000..925eadb19
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/distinct_test.php
@@ -0,0 +1,34 @@
+db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_distinct()
+ {
+ $users = $this->db->select('country')
+ ->distinct()
+ ->get('user')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(3, count($users));
+ }
+
+}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 8ca31f34c855c783689198f0d352e6efec352b4d Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Fri, 4 May 2012 23:57:46 +0700
Subject: PDO SQLite bug fixed, for result_object
---
system/database/drivers/pdo/pdo_result.php | 19 +++++++------------
tests/mocks/database/ci_test.sqlite | Bin 19456 -> 19456 bytes
2 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/system/database/drivers/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php
index 19aee1dfc..0b8937cc5 100644
--- a/system/database/drivers/pdo/pdo_result.php
+++ b/system/database/drivers/pdo/pdo_result.php
@@ -84,19 +84,14 @@ class CI_DB_pdo_result extends CI_DB_result {
// Define the output
$output = array('assoc', 'object');
+ // Initial value
+ $this->result_assoc = array() and $this->result_object = array();
+
// Fetch the result
- foreach ($output as $type)
+ while ($row = $this->_fetch_assoc())
{
- // Define the method and handler
- $res_method = '_fetch_'.$type;
- $res_handler = 'result_'.$type;
-
- $this->$res_handler = array();
-
- while ($row = $this->$res_method())
- {
- $this->{$res_handler}[] = $row;
- }
+ $this->result_assoc[] = $row;
+ $this->result_object[] = (object) $row;
}
// Save this as buffer and marked the fetch flag
@@ -249,7 +244,7 @@ class CI_DB_pdo_result extends CI_DB_result {
*/
protected function _fetch_object()
{
- return $this->result_id->fetchObject();
+ return $this->result_id->fetch(PDO::FETCH_OBJ);
}
}
diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite
index d48e3317f..23a3de2a4 100755
Binary files a/tests/mocks/database/ci_test.sqlite and b/tests/mocks/database/ci_test.sqlite differ
--
cgit v1.2.3-24-g4f1b
From d2d329a99f60bebc36eebc1c7b3c1a94b9789b49 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Sat, 5 May 2012 00:33:04 +0700
Subject: ORDER BY clause API code-coverage
---
.../database/query_builder/order_test.php | 55 ++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644 tests/codeigniter/database/query_builder/order_test.php
diff --git a/tests/codeigniter/database/query_builder/order_test.php b/tests/codeigniter/database/query_builder/order_test.php
new file mode 100644
index 000000000..01aa1c2b4
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/order_test.php
@@ -0,0 +1,55 @@
+db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_order_ascending()
+ {
+ $jobs = $this->db->order_by('name', 'asc')
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(4, count($jobs));
+ $this->assertEquals('Accountant', $jobs[0]['name']);
+ $this->assertEquals('Developer', $jobs[1]['name']);
+ $this->assertEquals('Musician', $jobs[2]['name']);
+ $this->assertEquals('Politician', $jobs[3]['name']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_order_descending()
+ {
+ $jobs = $this->db->order_by('name', 'desc')
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(4, count($jobs));
+ $this->assertEquals('Politician', $jobs[0]['name']);
+ $this->assertEquals('Musician', $jobs[1]['name']);
+ $this->assertEquals('Developer', $jobs[2]['name']);
+ $this->assertEquals('Accountant', $jobs[3]['name']);
+ }
+}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From be6fb4271ce723376930507dbe534f91344f26c7 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Sat, 5 May 2012 00:35:41 +0700
Subject: LIMIT clause API code-coverage
---
.../database/query_builder/limit_test.php | 49 ++++++++++++++++++++++
1 file changed, 49 insertions(+)
create mode 100644 tests/codeigniter/database/query_builder/limit_test.php
diff --git a/tests/codeigniter/database/query_builder/limit_test.php b/tests/codeigniter/database/query_builder/limit_test.php
new file mode 100644
index 000000000..704f3b651
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/limit_test.php
@@ -0,0 +1,49 @@
+db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_limit()
+ {
+ $jobs = $this->db->limit(2)
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(2, count($jobs));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_limit_and_offset()
+ {
+ $jobs = $this->db->limit(2, 2)
+ ->get('job')
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(2, count($jobs));
+ $this->assertEquals('Accountant', $jobs[0]['name']);
+ $this->assertEquals('Musician', $jobs[1]['name']);
+ }
+}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From c386b2a363c289afcfa07eea081050e35c1e86d8 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Sat, 5 May 2012 00:42:02 +0700
Subject: count code-coverage
---
.../database/query_builder/count_test.php | 44 ++++++++++++++++++++++
1 file changed, 44 insertions(+)
create mode 100644 tests/codeigniter/database/query_builder/count_test.php
diff --git a/tests/codeigniter/database/query_builder/count_test.php b/tests/codeigniter/database/query_builder/count_test.php
new file mode 100644
index 000000000..5e691692d
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/count_test.php
@@ -0,0 +1,44 @@
+db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_count_all()
+ {
+ $job_count = $this->db->count_all('job');
+
+ // Check the result
+ $this->assertEquals(4, $job_count);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_count_all_results()
+ {
+ $job_count = $this->db->like('name', 'ian')
+ ->count_all_results('job');
+
+ // Check the result
+ $this->assertEquals(2, $job_count);
+ }
+}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 9ec507badf60952750e76b5d83da54874dd19119 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Sat, 5 May 2012 00:55:39 +0700
Subject: UPDATE and SET clause code-coverage
---
.../database/query_builder/update_test.php | 71 ++++++++++++++++++++++
1 file changed, 71 insertions(+)
create mode 100644 tests/codeigniter/database/query_builder/update_test.php
diff --git a/tests/codeigniter/database/query_builder/update_test.php b/tests/codeigniter/database/query_builder/update_test.php
new file mode 100644
index 000000000..f5bbffd4f
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/update_test.php
@@ -0,0 +1,71 @@
+db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_update()
+ {
+ // Check initial record
+ $job1 = $this->db->where('id', 1)
+ ->get('job')
+ ->row();
+
+ $this->assertEquals('Developer', $job1->name);
+
+ // Do the update
+ $job_data = array('name' => 'Programmer');
+
+ $this->db->where('id', 1)
+ ->update('job', $job_data);
+
+ // Check updated record
+ $job1 = $this->db->where('id', 1)
+ ->get('job')
+ ->row();
+
+ $this->assertEquals('Programmer', $job1->name);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_update_with_set()
+ {
+ // Check initial record
+ $job1 = $this->db->where('id', 4)
+ ->get('job')
+ ->row();
+
+ $this->assertEquals('Musician', $job1->name);
+
+ // Do the update
+ $this->db->set('name', 'Vocalist');
+ $this->db->update('job', NULL, 'id = 4');
+
+ // Check updated record
+ $job1 = $this->db->where('id', 4)
+ ->get('job')
+ ->row();
+
+ $this->assertEquals('Vocalist', $job1->name);
+ }
+}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 6657cc1672f3f466655b1e476028b9d46a16bd1c Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Sat, 5 May 2012 01:06:41 +0700
Subject: DELETE code-coverage
---
.../database/query_builder/delete_test.php | 72 ++++++++++++++++++++++
1 file changed, 72 insertions(+)
create mode 100644 tests/codeigniter/database/query_builder/delete_test.php
diff --git a/tests/codeigniter/database/query_builder/delete_test.php b/tests/codeigniter/database/query_builder/delete_test.php
new file mode 100644
index 000000000..84ea7616f
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/delete_test.php
@@ -0,0 +1,72 @@
+db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_delete()
+ {
+ // Check initial record
+ $job1 = $this->db->where('id', 1)
+ ->get('job')
+ ->row();
+
+ $this->assertEquals('Developer', $job1->name);
+
+ // Do the delete
+ $this->db->delete('job', array('id' => 1));
+
+ // Check the record
+ $job1 = $this->db->where('id', 1)
+ ->get('job');
+
+ $this->assertEmpty($job1->result_array());
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_delete_several_tables()
+ {
+ // Check initial record
+ $user4 = $this->db->where('id', 4)
+ ->get('user')
+ ->row();
+
+ $job4 = $this->db->where('id', 4)
+ ->get('job')
+ ->row();
+
+ $this->assertEquals('Musician', $job4->name);
+ $this->assertEquals('Chris Martin', $user4->name);
+
+ // Do the delete
+ $this->db->delete(array('job', 'user'), array('id' => 4));
+
+ // Check the record
+ $job4 = $this->db->where('id', 4)->get('job');
+ $user4 = $this->db->where('id', 4)->get('user');
+
+ $this->assertEmpty($job4->result_array());
+ $this->assertEmpty($user4->result_array());
+ }
+
+}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 85859b212e480e2e1a59aae50c759367d6794ecd Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Sat, 5 May 2012 01:26:51 +0700
Subject: empty table API code-coverage
---
.../database/query_builder/empty_test.php | 39 ++++++++++++++++++++++
1 file changed, 39 insertions(+)
create mode 100644 tests/codeigniter/database/query_builder/empty_test.php
diff --git a/tests/codeigniter/database/query_builder/empty_test.php b/tests/codeigniter/database/query_builder/empty_test.php
new file mode 100644
index 000000000..d1f56285f
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/empty_test.php
@@ -0,0 +1,39 @@
+db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_empty_table()
+ {
+ // Check initial record
+ $jobs = $this->db->get('job')->result_array();
+
+ $this->assertEquals(4, count($jobs));
+
+ // Do the empty
+ $this->db->empty_table('job');
+
+ // Check the record
+ $jobs = $this->db->get('job');
+
+ $this->assertEmpty($jobs->result_array());
+ }
+
+}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 39f35fde6d023433e98904105f55f305483b6b5e Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Sat, 5 May 2012 01:29:13 +0700
Subject: TRUNCATE code-coverage
---
.../database/query_builder/truncate_test.php | 61 ++++++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100644 tests/codeigniter/database/query_builder/truncate_test.php
diff --git a/tests/codeigniter/database/query_builder/truncate_test.php b/tests/codeigniter/database/query_builder/truncate_test.php
new file mode 100644
index 000000000..2a9c8a91e
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/truncate_test.php
@@ -0,0 +1,61 @@
+db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_truncate()
+ {
+ // Check initial record
+ $jobs = $this->db->get('job')->result_array();
+
+ $this->assertEquals(4, count($jobs));
+
+ // Do the empty
+ $this->db->truncate('job');
+
+ // Check the record
+ $jobs = $this->db->get('job');
+
+ $this->assertEmpty($jobs->result_array());
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_truncate_with_from()
+ {
+ // Check initial record
+ $users = $this->db->get('user')->result_array();
+
+ $this->assertEquals(4, count($users));
+
+ // Do the empty
+ $this->db->from('user')
+ ->truncate();
+
+ // Check the record
+ $users = $this->db->get('user');
+
+ $this->assertEmpty($users->result_array());
+ }
+
+}
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 51a7c0b98df29205d39bb404c2bcd12bfb4ed4cb Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Sat, 5 May 2012 01:43:08 +0700
Subject: Clean up
---
tests/README.md | 6 ------
tests/codeigniter/Setup_test.php | 10 +++++-----
tests/travis/mysql.phpunit.xml | 6 +-----
tests/travis/pdo/mysql.phpunit.xml | 4 ----
tests/travis/pdo/pgsql.phpunit.xml | 6 +-----
tests/travis/pdo/sqlite.phpunit.xml | 6 +-----
tests/travis/pgsql.phpunit.xml | 6 +-----
tests/travis/sqlite.phpunit.xml | 6 +-----
8 files changed, 10 insertions(+), 40 deletions(-)
diff --git a/tests/README.md b/tests/README.md
index 6d83c34d8..b46f344cb 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -2,12 +2,6 @@
Status : [![Build Status](https://secure.travis-ci.org/EllisLab/CodeIgniter.png?branch=feature/unit-tests)](http://travis-ci.org/EllisLab/CodeIgniter)
-*Do not merge to default until these issues have been addressed*
-
-- Clean up naming conventions
-- Figure out config stuff
-- Figure out database testing
-
### Introduction:
This is the preliminary CodeIgniter testing documentation. It
diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php
index 550245f2f..b48e32bfb 100644
--- a/tests/codeigniter/Setup_test.php
+++ b/tests/codeigniter/Setup_test.php
@@ -2,12 +2,12 @@
class Setup_test extends PHPUnit_Framework_TestCase {
- function test_nonsense()
+ function test_bootstrap_constants()
{
- $this->markTestIncomplete('not implemented');
- // ensure that our bootstrapped test environment
- // is a good representation of an isolated CI install
- //die('here');
+ $this->assertTrue(defined('PROJECT_BASE'));
+ $this->assertTrue(defined('BASEPATH'));
+ $this->assertTrue(defined('APPPATH'));
+ $this->assertTrue(defined('VIEWPATH'));
}
}
\ No newline at end of file
diff --git a/tests/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml
index e9556f758..c5fcf1335 100644
--- a/tests/travis/mysql.phpunit.xml
+++ b/tests/travis/mysql.phpunit.xml
@@ -14,11 +14,7 @@
- ../codeigniter/Setup_test.php
- ../codeigniter/core
- ../codeigniter/helpers
- ../codeigniter/libraries
- ../codeigniter/database
+ ../codeigniter
diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml
index 69eece24f..f6fcc1c39 100644
--- a/tests/travis/pdo/mysql.phpunit.xml
+++ b/tests/travis/pdo/mysql.phpunit.xml
@@ -14,10 +14,6 @@
- ../../codeigniter/Setup_test.php
- ../../codeigniter/core
- ../../codeigniter/helpers
- ../../codeigniter/libraries../../codeigniter/database
diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml
index e68c3e028..6a23227db 100644
--- a/tests/travis/pdo/pgsql.phpunit.xml
+++ b/tests/travis/pdo/pgsql.phpunit.xml
@@ -14,11 +14,7 @@
- ../../codeigniter/Setup_test.php
- ../../codeigniter/core
- ../../codeigniter/helpers
- ../../codeigniter/libraries
- ../../codeigniter/database
+ ../../codeigniter
diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml
index 1871f6221..b85b7308a 100644
--- a/tests/travis/pdo/sqlite.phpunit.xml
+++ b/tests/travis/pdo/sqlite.phpunit.xml
@@ -14,11 +14,7 @@
- ../../codeigniter/Setup_test.php
- ../../codeigniter/core
- ../../codeigniter/helpers
- ../../codeigniter/libraries
- ../../codeigniter/database
+ ../../codeigniter
diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml
index ad8aeded2..78b6046cf 100644
--- a/tests/travis/pgsql.phpunit.xml
+++ b/tests/travis/pgsql.phpunit.xml
@@ -14,11 +14,7 @@
- ../codeigniter/Setup_test.php
- ../codeigniter/core
- ../codeigniter/helpers
- ../codeigniter/libraries
- ../codeigniter/database
+ ../codeigniter
diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml
index 628370e93..46e3d5073 100644
--- a/tests/travis/sqlite.phpunit.xml
+++ b/tests/travis/sqlite.phpunit.xml
@@ -14,11 +14,7 @@
- ../codeigniter/Setup_test.php
- ../codeigniter/core
- ../codeigniter/helpers
- ../codeigniter/libraries
- ../codeigniter/database
+ ../codeigniter
--
cgit v1.2.3-24-g4f1b
From 82196b945e291c65fdb66b35e3205f786ce8e921 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Sat, 5 May 2012 01:52:47 +0700
Subject: Remove temporary branch from travis whitelist
---
.travis.yml | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 971f62f38..97ea0422d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,5 +25,4 @@ script: phpunit --configuration tests/travis/$DB.phpunit.xml
branches:
only:
- develop
- - master
- - db-tests
\ No newline at end of file
+ - master
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From d4fb95ff19666f178b9f84850d122ff07fe193b9 Mon Sep 17 00:00:00 2001
From: Cusco
Date: Sat, 5 May 2012 03:22:24 +0800
Subject: Update system/database/drivers/interbase/interbase_utility.php
---
system/database/drivers/interbase/interbase_utility.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/database/drivers/interbase/interbase_utility.php b/system/database/drivers/interbase/interbase_utility.php
index 1b92af9b6..164211836 100644
--- a/system/database/drivers/interbase/interbase_utility.php
+++ b/system/database/drivers/interbase/interbase_utility.php
@@ -42,7 +42,7 @@ class CI_DB_interbase_utility extends CI_DB_utility {
* @param string $filename
* @return mixed
*/
- protected function backup($filename)
+ protected function _backup($filename)
{
if ($service = ibase_service_attach($this->db->hostname, $this->db->username, $this->db->password))
{
--
cgit v1.2.3-24-g4f1b
From bb2c83bddbf51c42815be3de60eab24fd87ae392 Mon Sep 17 00:00:00 2001
From: Wes Baker
Date: Fri, 4 May 2012 18:44:24 -0400
Subject: Added a return false if an image doesn't pass XSS cleaning to prevent
file_get_contents from returning a NULL and passing through unscathed.
---
system/libraries/Upload.php | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php
index 8ad67050d..4a4a66f73 100644
--- a/system/libraries/Upload.php
+++ b/system/libraries/Upload.php
@@ -850,6 +850,10 @@ class CI_Upload {
{
return TRUE; // its an image, no "triggers" detected in the first 256 bytes, we're good
}
+ else
+ {
+ return FALSE;
+ }
}
if (($data = @file_get_contents($file)) === FALSE)
@@ -1099,4 +1103,4 @@ class CI_Upload {
}
/* End of file Upload.php */
-/* Location: ./system/libraries/Upload.php */
\ No newline at end of file
+/* Location: ./system/libraries/Upload.php */
--
cgit v1.2.3-24-g4f1b
From 43ef706d3684af7efa02c21db02ca150c9b424a9 Mon Sep 17 00:00:00 2001
From: dixy
Date: Sat, 5 May 2012 18:26:54 +0200
Subject: Remove -webkit prefix for box-shadow
---
application/errors/error_404.php | 2 +-
application/errors/error_db.php | 2 +-
application/errors/error_general.php | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/application/errors/error_404.php b/application/errors/error_404.php
index 746032956..c19bedfcd 100644
--- a/application/errors/error_404.php
+++ b/application/errors/error_404.php
@@ -72,7 +72,7 @@ code {
#container {
margin: 10px;
border: 1px solid #D0D0D0;
- -webkit-box-shadow: 0 0 8px #D0D0D0;
+ box-shadow: 0 0 8px #D0D0D0;
}
p {
diff --git a/application/errors/error_db.php b/application/errors/error_db.php
index eb3a75260..3b244e094 100644
--- a/application/errors/error_db.php
+++ b/application/errors/error_db.php
@@ -72,7 +72,7 @@ code {
#container {
margin: 10px;
border: 1px solid #D0D0D0;
- -webkit-box-shadow: 0 0 8px #D0D0D0;
+ box-shadow: 0 0 8px #D0D0D0;
}
p {
diff --git a/application/errors/error_general.php b/application/errors/error_general.php
index 59896e1ea..c88afe168 100644
--- a/application/errors/error_general.php
+++ b/application/errors/error_general.php
@@ -72,7 +72,7 @@ code {
#container {
margin: 10px;
border: 1px solid #D0D0D0;
- -webkit-box-shadow: 0 0 8px #D0D0D0;
+ box-shadow: 0 0 8px #D0D0D0;
}
p {
--
cgit v1.2.3-24-g4f1b
From e463c4d71c2fdcc224e70f7576582220ae64e3d7 Mon Sep 17 00:00:00 2001
From: Wes Baker
Date: Fri, 4 May 2012 18:44:24 -0400
Subject: Added a return false if an image doesn't pass XSS cleaning to prevent
file_get_contents from returning a NULL and passing through unscathed.
---
system/libraries/Upload.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php
index b0490de30..0e5d73b19 100644
--- a/system/libraries/Upload.php
+++ b/system/libraries/Upload.php
@@ -868,6 +868,10 @@ class CI_Upload {
{
return TRUE; // its an image, no "triggers" detected in the first 256 bytes, we're good
}
+ else
+ {
+ return FALSE;
+ }
}
if (($data = @file_get_contents($file)) === FALSE)
--
cgit v1.2.3-24-g4f1b
From cdcceecba73dd9f54665f531d15c12f5c9679738 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Wed, 9 May 2012 11:23:30 +0300
Subject: Fix issue #1342
---
system/libraries/Form_validation.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 5547c6a69..73f607be8 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -448,7 +448,7 @@ class CI_Form_validation {
{
$this->_field_data[$field]['postdata'] = $this->_reduce_array($validation_array, $row['keys']);
}
- elseif ( ! empty($validation_array[$field]))
+ elseif (isset($validation_array[$field]))
{
$this->_field_data[$field]['postdata'] = $validation_array[$field];
}
--
cgit v1.2.3-24-g4f1b
From d41f423528b21d97ff0eb268e10947b257f5a90e Mon Sep 17 00:00:00 2001
From: Soesapto Joeni Hantoro
Date: Fri, 11 May 2012 11:00:42 +0700
Subject: Generate better conditions statement on boolean field type. Actually
boolean field type need TRUE or FALSE value. Common DBMS (e.g., MySQL) can
substite this value with 1 or 0, but it can't be implemented on PostgreSQL.
So, its better to use TRUE or FALSE value for boolean field type.
---
system/database/DB_query_builder.php | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index d0af66de1..969a25acb 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -432,7 +432,21 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$k .= ' IS NULL';
}
- if ( ! is_null($v))
+ if ( is_bool($v))
+ {
+ if ($escape === TRUE)
+ {
+ $k = $this->protect_identifiers($k, FALSE, $escape);
+
+ $v = ' '.($v ? 'TRUE' : 'FALSE');
+ }
+
+ if ( ! $this->_has_operator($k))
+ {
+ $k .= ' =';
+ }
+ }
+ else if ( ! is_null($v))
{
if ($escape === TRUE)
{
--
cgit v1.2.3-24-g4f1b
From b01d96f65a78528323b3917eec31c4ed8b58eb7b Mon Sep 17 00:00:00 2001
From: Soesapto Joeni Hantoro
Date: Fri, 11 May 2012 11:18:38 +0700
Subject: simpler script, add boolean handling on DB_driver/escape
---
system/database/DB_query_builder.php | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index 969a25acb..8fa67ea06 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -432,26 +432,16 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$k .= ' IS NULL';
}
- if ( is_bool($v))
+ if ( ! is_null($v))
{
if ($escape === TRUE)
{
$k = $this->protect_identifiers($k, FALSE, $escape);
-
- $v = ' '.($v ? 'TRUE' : 'FALSE');
+ $v = ' '.$this->escape($v);
}
-
- if ( ! $this->_has_operator($k))
+ else if (is_bool($v))
{
- $k .= ' =';
- }
- }
- else if ( ! is_null($v))
- {
- if ($escape === TRUE)
- {
- $k = $this->protect_identifiers($k, FALSE, $escape);
- $v = ' '.$this->escape($v);
+ $v = ' '.($v ? 'TRUE' : 'FALSE');
}
if ( ! $this->_has_operator($k))
--
cgit v1.2.3-24-g4f1b
From 938c7ef59991ed12b8634b292e2f8fc9fa385264 Mon Sep 17 00:00:00 2001
From: Soesapto Joeni Hantoro
Date: Fri, 11 May 2012 11:21:43 +0700
Subject: Escaping boolean data type, some DBMS (e.g., postgre) need it
---
system/database/DB_driver.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index ef77b594e..09513e267 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -696,7 +696,7 @@ abstract class CI_DB_driver {
}
elseif (is_bool($str))
{
- return ($str === FALSE) ? 0 : 1;
+ return ($str === FALSE) ? "FALSE" : "TRUE";
}
elseif (is_null($str))
{
--
cgit v1.2.3-24-g4f1b
From ca7d822f224033196e0e327944a01f319c90f37f Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Fri, 11 May 2012 10:59:09 +0300
Subject: User_agent library improvements
---
application/config/user_agents.php | 147 +++++++++++++++++++-----------------
system/libraries/User_agent.php | 24 +++---
user_guide_src/source/changelog.rst | 2 +-
3 files changed, 89 insertions(+), 84 deletions(-)
diff --git a/application/config/user_agents.php b/application/config/user_agents.php
index 60f256e01..72d74dbc7 100644
--- a/application/config/user_agents.php
+++ b/application/config/user_agents.php
@@ -36,7 +36,7 @@
|
*/
-$platforms = array (
+$platforms = array(
'windows nt 6.1' => 'Windows 7',
'windows nt 6.0' => 'Windows Vista',
'windows nt 5.2' => 'Windows 2003',
@@ -51,6 +51,11 @@ $platforms = array (
'windows 95' => 'Windows 95',
'win95' => 'Windows 95',
'windows' => 'Unknown Windows OS',
+ 'android' => 'Android',
+ 'blackberry' => 'BlackBerry',
+ 'iphone' => 'iOS',
+ 'ipad' => 'iOS',
+ 'ipod' => 'iOS',
'os x' => 'Mac OS X',
'ppc mac' => 'Power PC Mac',
'freebsd' => 'FreeBSD',
@@ -117,84 +122,84 @@ $mobiles = array(
// 'motorola' => 'Motorola'
// Phones and Manufacturers
- 'motorola' => "Motorola",
- 'nokia' => "Nokia",
- 'palm' => "Palm",
- 'iphone' => "Apple iPhone",
- 'ipad' => "iPad",
- 'ipod' => "Apple iPod Touch",
- 'sony' => "Sony Ericsson",
- 'ericsson' => "Sony Ericsson",
- 'blackberry' => "BlackBerry",
- 'cocoon' => "O2 Cocoon",
- 'blazer' => "Treo",
- 'lg' => "LG",
- 'amoi' => "Amoi",
- 'xda' => "XDA",
- 'mda' => "MDA",
- 'vario' => "Vario",
- 'htc' => "HTC",
- 'samsung' => "Samsung",
- 'sharp' => "Sharp",
- 'sie-' => "Siemens",
- 'alcatel' => "Alcatel",
- 'benq' => "BenQ",
- 'ipaq' => "HP iPaq",
- 'mot-' => "Motorola",
- 'playstation portable' => "PlayStation Portable",
- 'hiptop' => "Danger Hiptop",
- 'nec-' => "NEC",
- 'panasonic' => "Panasonic",
- 'philips' => "Philips",
- 'sagem' => "Sagem",
- 'sanyo' => "Sanyo",
- 'spv' => "SPV",
- 'zte' => "ZTE",
- 'sendo' => "Sendo",
- 'dsi' => "Nintendo DSi",
- 'ds' => "Nintendo DS",
- 'wii' => "Nintendo Wii",
- '3ds' => "Nintendo 3DS",
- 'open web' => "Open Web",
- 'openweb' => "OpenWeb",
+ 'motorola' => 'Motorola',
+ 'nokia' => 'Nokia',
+ 'palm' => 'Palm',
+ 'iphone' => 'Apple iPhone',
+ 'ipad' => 'iPad',
+ 'ipod' => 'Apple iPod Touch',
+ 'sony' => 'Sony Ericsson',
+ 'ericsson' => 'Sony Ericsson',
+ 'blackberry' => 'BlackBerry',
+ 'cocoon' => 'O2 Cocoon',
+ 'blazer' => 'Treo',
+ 'lg' => 'LG',
+ 'amoi' => 'Amoi',
+ 'xda' => 'XDA',
+ 'mda' => 'MDA',
+ 'vario' => 'Vario',
+ 'htc' => 'HTC',
+ 'samsung' => 'Samsung',
+ 'sharp' => 'Sharp',
+ 'sie-' => 'Siemens',
+ 'alcatel' => 'Alcatel',
+ 'benq' => 'BenQ',
+ 'ipaq' => 'HP iPaq',
+ 'mot-' => 'Motorola',
+ 'playstation portable' => 'PlayStation Portable',
+ 'hiptop' => 'Danger Hiptop',
+ 'nec-' => 'NEC',
+ 'panasonic' => 'Panasonic',
+ 'philips' => 'Philips',
+ 'sagem' => 'Sagem',
+ 'sanyo' => 'Sanyo',
+ 'spv' => 'SPV',
+ 'zte' => 'ZTE',
+ 'sendo' => 'Sendo',
+ 'dsi' => 'Nintendo DSi',
+ 'ds' => 'Nintendo DS',
+ 'wii' => 'Nintendo Wii',
+ '3ds' => 'Nintendo 3DS',
+ 'open web' => 'Open Web',
+ 'openweb' => 'OpenWeb',
// Operating Systems
- 'android' => "Android",
- 'symbian' => "Symbian",
- 'SymbianOS' => "SymbianOS",
- 'elaine' => "Palm",
- 'palm' => "Palm",
- 'series60' => "Symbian S60",
- 'windows ce' => "Windows CE",
+ 'android' => 'Android',
+ 'symbian' => 'Symbian',
+ 'SymbianOS' => 'SymbianOS',
+ 'elaine' => 'Palm',
+ 'palm' => 'Palm',
+ 'series60' => 'Symbian S60',
+ 'windows ce' => 'Windows CE',
// Browsers
- 'obigo' => "Obigo",
- 'netfront' => "Netfront Browser",
- 'openwave' => "Openwave Browser",
- 'mobilexplorer' => "Mobile Explorer",
- 'operamini' => "Opera Mini",
- 'opera mini' => "Opera Mini",
- 'opera mobi' => "Opera Mobile",
+ 'obigo' => 'Obigo',
+ 'netfront' => 'Netfront Browser',
+ 'openwave' => 'Openwave Browser',
+ 'mobilexplorer' => 'Mobile Explorer',
+ 'operamini' => 'Opera Mini',
+ 'opera mini' => 'Opera Mini',
+ 'opera mobi' => 'Opera Mobile',
// Other
- 'digital paths' => "Digital Paths",
- 'avantgo' => "AvantGo",
- 'xiino' => "Xiino",
- 'novarra' => "Novarra Transcoder",
- 'vodafone' => "Vodafone",
- 'docomo' => "NTT DoCoMo",
- 'o2' => "O2",
+ 'digital paths' => 'Digital Paths',
+ 'avantgo' => 'AvantGo',
+ 'xiino' => 'Xiino',
+ 'novarra' => 'Novarra Transcoder',
+ 'vodafone' => 'Vodafone',
+ 'docomo' => 'NTT DoCoMo',
+ 'o2' => 'O2',
// Fallback
- 'mobile' => "Generic Mobile",
- 'wireless' => "Generic Mobile",
- 'j2me' => "Generic Mobile",
- 'midp' => "Generic Mobile",
- 'cldc' => "Generic Mobile",
- 'up.link' => "Generic Mobile",
- 'up.browser' => "Generic Mobile",
- 'smartphone' => "Generic Mobile",
- 'cellphone' => "Generic Mobile"
+ 'mobile' => 'Generic Mobile',
+ 'wireless' => 'Generic Mobile',
+ 'j2me' => 'Generic Mobile',
+ 'midp' => 'Generic Mobile',
+ 'cldc' => 'Generic Mobile',
+ 'up.link' => 'Generic Mobile',
+ 'up.browser' => 'Generic Mobile',
+ 'smartphone' => 'Generic Mobile',
+ 'cellphone' => 'Generic Mobile'
);
// There are hundreds of bots but these are the most common.
diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php
index 0ac605fa4..ff596f04b 100644
--- a/system/libraries/User_agent.php
+++ b/system/libraries/User_agent.php
@@ -51,14 +51,14 @@ class CI_User_agent {
* @var bool
*/
public $is_browser = FALSE;
-
+
/**
* Flag for if the user-agent is a robot
*
* @var bool
*/
public $is_robot = FALSE;
-
+
/**
* Flag for if the user-agent is a mobile browser
*
@@ -72,7 +72,7 @@ class CI_User_agent {
* @var array
*/
public $languages = array();
-
+
/**
* Character sets accepted by the current user agent
*
@@ -86,21 +86,21 @@ class CI_User_agent {
* @var array
*/
public $platforms = array();
-
+
/**
* List of browsers to compare against current user agent
*
* @var array
*/
public $browsers = array();
-
+
/**
* List of mobile browsers to compare against current user agent
*
* @var array
*/
public $mobiles = array();
-
+
/**
* List of robots to compare against current user agent
*
@@ -114,28 +114,28 @@ class CI_User_agent {
* @var string
*/
public $platform = '';
-
+
/**
* Current user-agent browser
*
* @var string
*/
public $browser = '';
-
+
/**
* Current user-agent version
*
* @var string
*/
public $version = '';
-
+
/**
* Current user-agent mobile name
*
* @var string
*/
public $mobile = '';
-
+
/**
* Current user-agent robot name
*
@@ -330,7 +330,7 @@ class CI_User_agent {
{
foreach ($this->mobiles as $key => $val)
{
- if (FALSE !== (strpos(strtolower($this->agent), $key)))
+ if (FALSE !== (stripos($this->agent, $key)))
{
$this->is_mobile = TRUE;
$this->mobile = $val;
@@ -604,7 +604,7 @@ class CI_User_agent {
/**
* Test for a particular character set
*
- * @param string $charset
+ * @param string $charset
* @return bool
*/
public function accept_charset($charset = 'utf-8')
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index a70531901..4756eb3f5 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -22,7 +22,7 @@ Release Date: Not Released
- PHP 5.1.6 is no longer supported. CodeIgniter now requires PHP 5.2.4.
- Added an optional backtrace to php-error template.
- Added Android to the list of user agents.
- - Added Windows 7 to the list of user platforms.
+ - Added Windows 7, Android, Blackberry and iOS to the list of user platforms.
- Ability to log certain error types, not all under a threshold.
- Added support for pem, p10, p12, p7a, p7c, p7m, p7r, p7s, crt, crl, der, kdb, rsa, cer, sst, csr Certs to mimes.php.
- Added support for pgp and gpg to mimes.php.
--
cgit v1.2.3-24-g4f1b
From 585cf67a98d8a31f584c13a319310ca7561d572c Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Fri, 11 May 2012 11:55:15 +0300
Subject: Remove a duplicate mobile user agent entry
---
application/config/user_agents.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/application/config/user_agents.php b/application/config/user_agents.php
index 72d74dbc7..76114616b 100644
--- a/application/config/user_agents.php
+++ b/application/config/user_agents.php
@@ -168,7 +168,6 @@ $mobiles = array(
'symbian' => 'Symbian',
'SymbianOS' => 'SymbianOS',
'elaine' => 'Palm',
- 'palm' => 'Palm',
'series60' => 'Symbian S60',
'windows ce' => 'Windows CE',
--
cgit v1.2.3-24-g4f1b
From 46d53fb8799eb2f84798f0e7a5f57b065c2482e2 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Fri, 11 May 2012 13:42:24 +0300
Subject: Fix issue #1349
---
system/libraries/Upload.php | 2 +-
user_guide_src/source/changelog.rst | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php
index 4a4a66f73..24d4bd4d0 100644
--- a/system/libraries/Upload.php
+++ b/system/libraries/Upload.php
@@ -725,7 +725,7 @@ class CI_Upload {
public function get_extension($filename)
{
$x = explode('.', $filename);
- return '.'.end($x);
+ return (count($x) !== 1) ? '.'.end($x) : '';
}
// --------------------------------------------------------------------
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 4756eb3f5..d457a3fbc 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -214,8 +214,9 @@ Bug fixes for 3.0
- Fixed a bug in SQLSRV's delete() method where like() and limit() conditions were ignored.
- Fixed a bug (#1265) - Database connections were always closed, regardless of the 'pconnect' option value.
- Fixed a bug (#128) - :doc:`Language Library ` did not correctly keep track of loaded language files.
-- Fixed a bug (#1242) Added Windows path compatibility to function read_dir of ZIP library
-- Fixed a bug (#1314) sess_destroy() did not destroy userdata.
+- Fixed a bug (#1242) - Added Windows path compatibility to function read_dir of ZIP library
+- Fixed a bug (#1314) - sess_destroy() did not destroy userdata.
+- Fixed a bug (#1349) - get_extension() in the `File Uploading Library ` returned the original filename when it didn't have an actual extension.
Version 2.1.1
=============
--
cgit v1.2.3-24-g4f1b
From fff6c2a3caa1ce14e58fcb3ee0d937d17985eea1 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Sun, 13 May 2012 22:15:23 +0300
Subject: Improve the solution for issue #1342
---
system/libraries/Form_validation.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 73f607be8..c396580be 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -448,7 +448,7 @@ class CI_Form_validation {
{
$this->_field_data[$field]['postdata'] = $this->_reduce_array($validation_array, $row['keys']);
}
- elseif (isset($validation_array[$field]))
+ elseif (isset($validation_array[$field]) && $validation_array[$field] !== '')
{
$this->_field_data[$field]['postdata'] = $validation_array[$field];
}
--
cgit v1.2.3-24-g4f1b
From 66c982e8fa8fb0261394b63b25a3817503263d17 Mon Sep 17 00:00:00 2001
From: Thanasis Polychronakis
Date: Mon, 14 May 2012 21:31:04 +0300
Subject: Load base config first, then environment's config
---
system/core/Common.php | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/system/core/Common.php b/system/core/Common.php
index 78aa6e874..01b0d8673 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -231,21 +231,21 @@ if ( ! function_exists('get_config'))
return $_config[0];
}
- // Is the config file in the environment folder?
- if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
- {
- $file_path = APPPATH.'config/config.php';
+ $file_path = APPPATH.'config/config.php';
+ $found = false;
+ if (file_exists($file_path)) {
+ $found = true;
+ require($file_path);
}
- // Fetch the config file
- if ( ! file_exists($file_path))
+ // Is the config file in the environment folder?
+ if (defined(ENVIRONMENT) && file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
{
- set_status_header(503);
+ require($file_path);
+ } else if (!$found) {
exit('The configuration file does not exist.');
}
- require($file_path);
-
// Does the $config array exist in the file?
if ( ! isset($config) OR ! is_array($config))
{
--
cgit v1.2.3-24-g4f1b
From 09069ddcecde9a0c66e41087e816567d420eb750 Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Mon, 14 May 2012 15:21:33 -0400
Subject: Move errors to views folder
---
application/errors/error_404.php | 89 ------------------------------
application/errors/error_db.php | 89 ------------------------------
application/errors/error_general.php | 89 ------------------------------
application/errors/error_php.php | 55 ------------------
application/errors/index.html | 10 ----
application/views/errors/error_404.php | 89 ++++++++++++++++++++++++++++++
application/views/errors/error_db.php | 89 ++++++++++++++++++++++++++++++
application/views/errors/error_general.php | 89 ++++++++++++++++++++++++++++++
application/views/errors/error_php.php | 55 ++++++++++++++++++
application/views/errors/index.html | 10 ++++
system/core/Exceptions.php | 4 +-
11 files changed, 334 insertions(+), 334 deletions(-)
delete mode 100644 application/errors/error_404.php
delete mode 100644 application/errors/error_db.php
delete mode 100644 application/errors/error_general.php
delete mode 100644 application/errors/error_php.php
delete mode 100644 application/errors/index.html
create mode 100644 application/views/errors/error_404.php
create mode 100644 application/views/errors/error_db.php
create mode 100644 application/views/errors/error_general.php
create mode 100644 application/views/errors/error_php.php
create mode 100644 application/views/errors/index.html
diff --git a/application/errors/error_404.php b/application/errors/error_404.php
deleted file mode 100644
index c19bedfcd..000000000
--- a/application/errors/error_404.php
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
-404 Page Not Found
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/application/errors/error_db.php b/application/errors/error_db.php
deleted file mode 100644
index 3b244e094..000000000
--- a/application/errors/error_db.php
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
-Database Error
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/application/errors/error_general.php b/application/errors/error_general.php
deleted file mode 100644
index c88afe168..000000000
--- a/application/errors/error_general.php
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
-Error
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/application/errors/error_php.php b/application/errors/error_php.php
deleted file mode 100644
index 3855720de..000000000
--- a/application/errors/error_php.php
+++ /dev/null
@@ -1,55 +0,0 @@
-
-
-
-
-
A PHP Error was encountered
-
-
Severity:
-
Message:
-
Filename:
-
Line Number:
-
-
-
-
Backtrace:
-
-
-
-
- File:
- Line:
- Function:
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/application/errors/index.html b/application/errors/index.html
deleted file mode 100644
index c942a79ce..000000000
--- a/application/errors/index.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
- 403 Forbidden
-
-
-
-
Directory access is forbidden.
-
-
-
\ No newline at end of file
diff --git a/application/views/errors/error_404.php b/application/views/errors/error_404.php
new file mode 100644
index 000000000..c19bedfcd
--- /dev/null
+++ b/application/views/errors/error_404.php
@@ -0,0 +1,89 @@
+
+
+
+
+404 Page Not Found
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/views/errors/error_db.php b/application/views/errors/error_db.php
new file mode 100644
index 000000000..3b244e094
--- /dev/null
+++ b/application/views/errors/error_db.php
@@ -0,0 +1,89 @@
+
+
+
+
+Database Error
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/views/errors/error_general.php b/application/views/errors/error_general.php
new file mode 100644
index 000000000..c88afe168
--- /dev/null
+++ b/application/views/errors/error_general.php
@@ -0,0 +1,89 @@
+
+
+
+
+Error
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/views/errors/error_php.php b/application/views/errors/error_php.php
new file mode 100644
index 000000000..3855720de
--- /dev/null
+++ b/application/views/errors/error_php.php
@@ -0,0 +1,55 @@
+
+
+
+
+
A PHP Error was encountered
+
+
Severity:
+
Message:
+
Filename:
+
Line Number:
+
+
+
+
Backtrace:
+
+
+
+
+ File:
+ Line:
+ Function:
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/views/errors/index.html b/application/views/errors/index.html
new file mode 100644
index 000000000..c942a79ce
--- /dev/null
+++ b/application/views/errors/index.html
@@ -0,0 +1,10 @@
+
+
+ 403 Forbidden
+
+
+
+
Directory access is forbidden.
+
+
+
\ No newline at end of file
diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php
index 2e9f0c766..f9618044e 100755
--- a/system/core/Exceptions.php
+++ b/system/core/Exceptions.php
@@ -141,7 +141,7 @@ class CI_Exceptions {
ob_end_flush();
}
ob_start();
- include(APPPATH.'errors/'.$template.'.php');
+ include(APPPATH.'views/errors/'.$template.'.php');
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
@@ -175,7 +175,7 @@ class CI_Exceptions {
ob_end_flush();
}
ob_start();
- include(APPPATH.'errors/'.'error_php.php');
+ include(APPPATH.'views/errors/error_php.php');
$buffer = ob_get_contents();
ob_end_clean();
echo $buffer;
--
cgit v1.2.3-24-g4f1b
From f25b9295557f9d5fda1e0b2342964f17e26a390e Mon Sep 17 00:00:00 2001
From: Soesapto Joeni Hantoro
Date: Tue, 15 May 2012 08:10:31 +0700
Subject: Escaping boolean data type on postgre
---
system/database/drivers/postgre/postgre_driver.php | 101 +++++++++++++++++++++
1 file changed, 101 insertions(+)
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 84bf768ee..915763ad7 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -310,6 +310,35 @@ class CI_DB_postgre_driver extends CI_DB {
// --------------------------------------------------------------------
+ /**
+ * "Smart" Escape String
+ *
+ * Escapes data based on type
+ * Sets boolean and null types
+ *
+ * @param string
+ * @return mixed
+ */
+ public function escape($str)
+ {
+ if (is_string($str) OR method_exists($str, '__toString'))
+ {
+ return "'".$this->escape_str($str)."'";
+ }
+ elseif (is_bool($str))
+ {
+ return $str ? "TRUE" : "FALSE";
+ }
+ elseif (is_null($str))
+ {
+ return 'NULL';
+ }
+
+ return $str;
+ }
+
+ // --------------------------------------------------------------------
+
/**
* Affected Rows
*
@@ -557,6 +586,78 @@ class CI_DB_postgre_driver extends CI_DB {
// --------------------------------------------------------------------
+ /**
+ * Where
+ *
+ * Called by where() or or_where()
+ *
+ * @param mixed
+ * @param mixed
+ * @param string
+ * @return object
+ *
+ */
+ protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
+ {
+ $type = $this->_group_get_type($type);
+
+ if ( ! is_array($key))
+ {
+ $key = array($key => $value);
+ }
+
+ // If the escape value was not set will will base it on the global setting
+ if ( ! is_bool($escape))
+ {
+ $escape = $this->_protect_identifiers;
+ }
+
+ foreach ($key as $k => $v)
+ {
+ $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) ? '' : $type;
+
+ if (is_null($v) && ! $this->_has_operator($k))
+ {
+ // value appears not to have been set, assign the test to IS NULL
+ $k .= ' IS NULL';
+ }
+
+ if ( ! is_null($v))
+ {
+ if ($escape === TRUE)
+ {
+ $k = $this->protect_identifiers($k, FALSE, $escape);
+ $v = ' '.$this->escape($v);
+ }
+ else if (is_bool($v))
+ {
+ $v = ' '.($v ? 'TRUE' : 'FALSE');
+ }
+
+ if ( ! $this->_has_operator($k))
+ {
+ $k .= ' = ';
+ }
+ }
+ else
+ {
+ $k = $this->protect_identifiers($k, FALSE, $escape);
+ }
+
+ $this->qb_where[] = $prefix.$k.$v;
+ if ($this->qb_caching === TRUE)
+ {
+ $this->qb_cache_where[] = $prefix.$k.$v;
+ $this->qb_cache_exists[] = 'where';
+ }
+
+ }
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
/**
* Close DB Connection
*
--
cgit v1.2.3-24-g4f1b
From 68fe7935a391b20dcf0cbdde9c1b49c697a6443b Mon Sep 17 00:00:00 2001
From: Soesapto Joeni Hantoro
Date: Tue, 15 May 2012 08:19:29 +0700
Subject: Rollback changes, move it to postgre_driver
---
system/database/DB_driver.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 09513e267..ef77b594e 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -696,7 +696,7 @@ abstract class CI_DB_driver {
}
elseif (is_bool($str))
{
- return ($str === FALSE) ? "FALSE" : "TRUE";
+ return ($str === FALSE) ? 0 : 1;
}
elseif (is_null($str))
{
--
cgit v1.2.3-24-g4f1b
From f79bdda8d823495b1f6524bd0cafb985860b7331 Mon Sep 17 00:00:00 2001
From: Soesapto Joeni Hantoro
Date: Tue, 15 May 2012 08:20:24 +0700
Subject: Rollback changes, move it to postgre_driver
---
system/database/DB_query_builder.php | 4 ----
1 file changed, 4 deletions(-)
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index 8fa67ea06..d0af66de1 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -439,10 +439,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$k = $this->protect_identifiers($k, FALSE, $escape);
$v = ' '.$this->escape($v);
}
- else if (is_bool($v))
- {
- $v = ' '.($v ? 'TRUE' : 'FALSE');
- }
if ( ! $this->_has_operator($k))
{
--
cgit v1.2.3-24-g4f1b
From d2574db779d97f2a1ff8351b5a7c31c028601e17 Mon Sep 17 00:00:00 2001
From: Soesapto Joeni Hantoro
Date: Tue, 15 May 2012 16:28:16 +0700
Subject: Escaping boolean data type for postgre
---
system/database/drivers/postgre/postgre_driver.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 915763ad7..4b2fb7a9e 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -327,7 +327,7 @@ class CI_DB_postgre_driver extends CI_DB {
}
elseif (is_bool($str))
{
- return $str ? "TRUE" : "FALSE";
+ return ($str) ? 'TRUE' : 'FALSE';
}
elseif (is_null($str))
{
@@ -629,7 +629,7 @@ class CI_DB_postgre_driver extends CI_DB {
$k = $this->protect_identifiers($k, FALSE, $escape);
$v = ' '.$this->escape($v);
}
- else if (is_bool($v))
+ elseif (is_bool($v))
{
$v = ' '.($v ? 'TRUE' : 'FALSE');
}
--
cgit v1.2.3-24-g4f1b
From 5963db71348a06c14b38e7ce998df4249d4fd45a Mon Sep 17 00:00:00 2001
From: Soesapto Joeni Hantoro
Date: Tue, 15 May 2012 16:31:18 +0700
Subject: escaping boolean data type for postgre change log
---
user_guide_src/source/changelog.rst | 1 +
1 file changed, 1 insertion(+)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index a70531901..77c7e2ca4 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -100,6 +100,7 @@ Release Date: Not Released
- Added PDO support for create_database(), drop_database and drop_table() in :doc:`Database Forge `.
- Added MSSQL, SQLSRV support for optimize_table() in :doc:`Database Utility `.
- Improved CUBRID support for list_databases() in :doc:`Database Utility ` (until now only the currently used database was returned).
+ - Added escaping boolean data type for PosgreSQL
- Libraries
--
cgit v1.2.3-24-g4f1b
From dabeaa11ca2076935e5091e0f9e90ff9c4593962 Mon Sep 17 00:00:00 2001
From: Soesapto Joeni Hantoro
Date: Tue, 15 May 2012 16:37:46 +0700
Subject: Escaping boolean data type for postgre
---
system/database/drivers/postgre/postgre_driver.php | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 4b2fb7a9e..670eb549d 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -321,20 +321,12 @@ class CI_DB_postgre_driver extends CI_DB {
*/
public function escape($str)
{
- if (is_string($str) OR method_exists($str, '__toString'))
- {
- return "'".$this->escape_str($str)."'";
- }
- elseif (is_bool($str))
+ if (is_bool($str))
{
return ($str) ? 'TRUE' : 'FALSE';
}
- elseif (is_null($str))
- {
- return 'NULL';
- }
- return $str;
+ return parent::escape($str);
}
// --------------------------------------------------------------------
--
cgit v1.2.3-24-g4f1b
From 242925bc084e4d606d5f34bdb49bdf9f5235ec32 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Tue, 15 May 2012 13:03:51 +0300
Subject: Minor changes on the pull #1355 additions
---
system/database/drivers/postgre/postgre_driver.php | 8 ++++----
user_guide_src/source/changelog.rst | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 670eb549d..17bd37b38 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -328,7 +328,7 @@ class CI_DB_postgre_driver extends CI_DB {
return parent::escape($str);
}
-
+
// --------------------------------------------------------------------
/**
@@ -623,7 +623,7 @@ class CI_DB_postgre_driver extends CI_DB {
}
elseif (is_bool($v))
{
- $v = ' '.($v ? 'TRUE' : 'FALSE');
+ $v = ($v ? ' TRUE' : ' FALSE');
}
if ( ! $this->_has_operator($k))
@@ -647,7 +647,7 @@ class CI_DB_postgre_driver extends CI_DB {
return $this;
}
-
+
// --------------------------------------------------------------------
/**
@@ -664,4 +664,4 @@ class CI_DB_postgre_driver extends CI_DB {
}
/* End of file postgre_driver.php */
-/* Location: ./system/database/drivers/postgre/postgre_driver.php */
+/* Location: ./system/database/drivers/postgre/postgre_driver.php */
\ No newline at end of file
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 2f2ebce98..d33a6a635 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -77,6 +77,7 @@ Release Date: Not Released
- pg_version() is now used to get the database version number, when possible.
- Added db_set_charset() support.
- Added _optimize_table() support for the :doc:`Database Utility Class ` (rebuilds table indexes).
+ - Added boolean data type support in escape().
- Added a constructor to the DB_result class and moved all driver-specific properties and logic out of the base DB_driver class to allow better abstraction.
- Removed limit() and order_by() support for UPDATE and DELETE queries in PostgreSQL driver. Postgres does not support those features.
- Removed protect_identifiers() and renamed internal method _protect_identifiers() to it instead - it was just an alias.
@@ -100,7 +101,6 @@ Release Date: Not Released
- Added PDO support for create_database(), drop_database and drop_table() in :doc:`Database Forge `.
- Added MSSQL, SQLSRV support for optimize_table() in :doc:`Database Utility `.
- Improved CUBRID support for list_databases() in :doc:`Database Utility ` (until now only the currently used database was returned).
- - Added escaping boolean data type for PosgreSQL
- Libraries
--
cgit v1.2.3-24-g4f1b
From 570e77cd78e0c704b032c3e7702372ca63d5ddaa Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Tue, 15 May 2012 18:47:24 +0700
Subject: Benchmark code-coverage
---
tests/codeigniter/core/Benchmark_test.php | 42 +++++++++++++++++++++++++++++++
tests/mocks/core/benchmark.php | 3 +++
2 files changed, 45 insertions(+)
create mode 100644 tests/codeigniter/core/Benchmark_test.php
create mode 100644 tests/mocks/core/benchmark.php
diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php
new file mode 100644
index 000000000..2790b582e
--- /dev/null
+++ b/tests/codeigniter/core/Benchmark_test.php
@@ -0,0 +1,42 @@
+benchmark = new Mock_Core_Benchmark();
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_mark()
+ {
+ $this->assertEmpty($this->benchmark->marker);
+
+ $this->benchmark->mark('code_start');
+
+ $this->assertEquals(1, count($this->benchmark->marker));
+ $this->assertArrayHasKey('code_start', $this->benchmark->marker);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_elapsed_time()
+ {
+ $this->assertEquals('{elapsed_time}', $this->benchmark->elapsed_time());
+ $this->assertEmpty($this->benchmark->elapsed_time('undefined_point'));
+
+ $this->benchmark->mark('code_start');
+ sleep(1);
+ $this->benchmark->mark('code_end');
+
+ $this->assertEquals('1.00', $this->benchmark->elapsed_time('code_start', 'code_end', 3));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_memory_usage()
+ {
+ $this->assertEquals('{memory_usage}', $this->benchmark->memory_usage());
+ }
+}
\ No newline at end of file
diff --git a/tests/mocks/core/benchmark.php b/tests/mocks/core/benchmark.php
new file mode 100644
index 000000000..d92be21db
--- /dev/null
+++ b/tests/mocks/core/benchmark.php
@@ -0,0 +1,3 @@
+
Date: Tue, 15 May 2012 18:48:45 +0700
Subject: Clean up autoloader annotation
---
tests/mocks/autoloader.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php
index f1bdb5d6f..92c9bea59 100644
--- a/tests/mocks/autoloader.php
+++ b/tests/mocks/autoloader.php
@@ -6,7 +6,6 @@
//
// Prototype :
//
-// include_once('Mock_Core_Loader') // Will load ./mocks/core/loader.php
// $mock_table = new Mock_Libraries_Table(); // Will load ./mocks/libraries/table.php
// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php
// and so on...
--
cgit v1.2.3-24-g4f1b
From 8af88f3f729b7bcfd2a106f858b5445deafe5ed0 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Tue, 15 May 2012 21:52:53 +0700
Subject: Security Code coverage
---
tests/Bootstrap.php | 3 ++
tests/codeigniter/core/Security_test.php | 79 ++++++++++++++++++++++++++++++++
tests/mocks/core/security.php | 27 +++++++++++
tests/mocks/libraries/table.php | 2 +-
4 files changed, 110 insertions(+), 1 deletion(-)
create mode 100644 tests/codeigniter/core/Security_test.php
create mode 100644 tests/mocks/core/security.php
diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php
index 9f89d1be8..2bec364ef 100644
--- a/tests/Bootstrap.php
+++ b/tests/Bootstrap.php
@@ -12,6 +12,9 @@ define('BASEPATH', PROJECT_BASE.'system/');
define('APPPATH', PROJECT_BASE.'application/');
define('VIEWPATH', PROJECT_BASE.'');
+// Set cookie for security test
+$_COOKIE['ci_csrf_cookie'] = md5(uniqid(rand(), TRUE));
+
// Prep our test environment
require_once 'vfsStream/vfsStream.php';
include_once $dir.'/mocks/core/common.php';
diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php
new file mode 100644
index 000000000..c3b526965
--- /dev/null
+++ b/tests/codeigniter/core/Security_test.php
@@ -0,0 +1,79 @@
+ci_set_config('csrf_protection', TRUE);
+ $this->ci_set_config('csrf_token_name', 'ci_csrf_token');
+ // @see : ./Bootstrap.php Line 16
+ $this->ci_set_config('csrf_cookie_name', 'ci_csrf_cookie');
+ $this->ci_set_config('csrf_expire', 7200);
+ $this->ci_set_config('csrf_regenerate', TRUE);
+ $this->ci_set_config('csrf_exclude_uris', array());
+
+ $this->ci_set_config('cookie_prefix', "");
+ $this->ci_set_config('cookie_domain', "");
+ $this->ci_set_config('cookie_path', "/");
+ $this->ci_set_config('cookie_secure', FALSE);
+ $this->ci_set_config('cookie_httponly', FALSE);
+
+ $this->security = new Mock_Core_Security();
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_csrf_verify()
+ {
+ $_SERVER['REQUEST_METHOD'] = 'GET';
+
+ $this->assertInstanceOf('CI_Security', $this->security->csrf_verify());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_csrf_verify_invalid()
+ {
+ // Without issuing $_POST[csrf_token_name], this request will triggering CSRF error
+ $_SERVER['REQUEST_METHOD'] = 'POST';
+
+ $this->setExpectedException('RuntimeException', 'CI Error: The action you have requested is not allowed');
+
+ $this->security->csrf_verify();
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_csrf_verify_valid()
+ {
+ $_SERVER['REQUEST_METHOD'] = 'POST';
+ $_POST[$this->security->csrf_token_name] = $this->security->csrf_hash;
+
+ $this->assertInstanceOf('CI_Security', $this->security->csrf_verify());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_get_csrf_hash()
+ {
+ $this->assertEquals($this->security->csrf_hash, $this->security->get_csrf_hash());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_get_csrf_token_name()
+ {
+ $this->assertEquals('ci_csrf_token', $this->security->get_csrf_token_name());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_xss_clean()
+ {
+ $harm_string = "Hello, i try to your site";
+
+ $harmless_string = $this->security->xss_clean($harm_string);
+
+ $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless_string);
+ }
+}
\ No newline at end of file
diff --git a/tests/mocks/core/security.php b/tests/mocks/core/security.php
new file mode 100644
index 000000000..de8e44710
--- /dev/null
+++ b/tests/mocks/core/security.php
@@ -0,0 +1,27 @@
+{'_'.$property}) ? $this->{'_'.$property} : NULL;
+ }
+
+ // Overide inaccesible protected method
+ public function __call($method, $params)
+ {
+ if (is_callable(array($this, '_'.$method)))
+ {
+ return call_user_func_array(array($this, '_'.$method), $params);
+ }
+
+ throw new BadMethodCallException('Method '.$method.' was not found');
+ }
+
+}
\ No newline at end of file
diff --git a/tests/mocks/libraries/table.php b/tests/mocks/libraries/table.php
index 1a6ff8d35..97fbb30bd 100644
--- a/tests/mocks/libraries/table.php
+++ b/tests/mocks/libraries/table.php
@@ -2,7 +2,7 @@
class Mock_Libraries_Table extends CI_Table {
- // Overide inaccesible private or protected method
+ // Overide inaccesible protected method
public function __call($method, $params)
{
if (is_callable(array($this, '_'.$method)))
--
cgit v1.2.3-24-g4f1b
From d40a545e9e7e4dc222d58fe46fe23f3691f043ee Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Tue, 15 May 2012 22:00:14 +0700
Subject: Comment block for explanation
---
tests/mocks/core/security.php | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tests/mocks/core/security.php b/tests/mocks/core/security.php
index de8e44710..c5269fbc5 100644
--- a/tests/mocks/core/security.php
+++ b/tests/mocks/core/security.php
@@ -4,6 +4,9 @@ class Mock_Core_Security extends CI_Security {
public function csrf_set_cookie()
{
+ // We cannot set cookie in CLI mode, so for csrf test, who rely on $_COOKIE,
+ // we superseded set_cookie with directly set the cookie variable,
+ // @see : ./Bootstrap.php, line 16
return $this;
}
--
cgit v1.2.3-24-g4f1b
From 7756af5df0a53930019e9fd7b828504f0c2c5427 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Tue, 15 May 2012 23:57:05 +0700
Subject: Input class code-coverage
---
tests/Bootstrap.php | 3 -
tests/codeigniter/core/Input_test.php | 144 +++++++++++++++++++++++++++++++
tests/codeigniter/core/Security_test.php | 14 +--
tests/mocks/core/input.php | 31 +++++++
tests/mocks/core/security.php | 2 +-
tests/mocks/core/utf8.php | 27 ++++++
6 files changed, 207 insertions(+), 14 deletions(-)
create mode 100644 tests/codeigniter/core/Input_test.php
create mode 100644 tests/mocks/core/input.php
create mode 100644 tests/mocks/core/utf8.php
diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php
index 2bec364ef..9f89d1be8 100644
--- a/tests/Bootstrap.php
+++ b/tests/Bootstrap.php
@@ -12,9 +12,6 @@ define('BASEPATH', PROJECT_BASE.'system/');
define('APPPATH', PROJECT_BASE.'application/');
define('VIEWPATH', PROJECT_BASE.'');
-// Set cookie for security test
-$_COOKIE['ci_csrf_cookie'] = md5(uniqid(rand(), TRUE));
-
// Prep our test environment
require_once 'vfsStream/vfsStream.php';
include_once $dir.'/mocks/core/common.php';
diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php
new file mode 100644
index 000000000..fd0576e38
--- /dev/null
+++ b/tests/codeigniter/core/Input_test.php
@@ -0,0 +1,144 @@
+ci_set_config('allow_get_array', TRUE);
+ $this->ci_set_config('global_xss_filtering', FALSE);
+ $this->ci_set_config('csrf_protection', FALSE);
+
+ $security = new Mock_Core_Security();
+ $utf8 = new Mock_Core_Utf8();
+
+ $this->input = new Mock_Core_Input($security, $utf8);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_get_not_exists()
+ {
+ $this->assertEmpty($this->input->get());
+ $this->assertEmpty($this->input->get('foo'));
+
+ $this->assertTrue( ! $this->input->get());
+ $this->assertTrue( ! $this->input->get('foo'));
+
+ $this->assertTrue($this->input->get() == FALSE);
+ $this->assertTrue($this->input->get('foo') == FALSE);
+
+ $this->assertTrue($this->input->get() === FALSE);
+ $this->assertTrue($this->input->get('foo') === FALSE);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_get_exist()
+ {
+ $_SERVER['REQUEST_METHOD'] = 'GET';
+ $_GET['foo'] = 'bar';
+
+ $this->assertArrayHasKey('foo', $this->input->get());
+ $this->assertEquals('bar', $this->input->get('foo'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_get_exist_with_xss_clean()
+ {
+ $_SERVER['REQUEST_METHOD'] = 'GET';
+ $_GET['harm'] = "Hello, i try to your site";
+
+ $this->assertArrayHasKey('harm', $this->input->get());
+ $this->assertEquals("Hello, i try to your site", $this->input->get('harm'));
+ $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $this->input->get('harm', TRUE));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_post_not_exists()
+ {
+ $this->assertEmpty($this->input->post());
+ $this->assertEmpty($this->input->post('foo'));
+
+ $this->assertTrue( ! $this->input->post());
+ $this->assertTrue( ! $this->input->post('foo'));
+
+ $this->assertTrue($this->input->post() == FALSE);
+ $this->assertTrue($this->input->post('foo') == FALSE);
+
+ $this->assertTrue($this->input->post() === FALSE);
+ $this->assertTrue($this->input->post('foo') === FALSE);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_post_exist()
+ {
+ $_SERVER['REQUEST_METHOD'] = 'POST';
+ $_POST['foo'] = 'bar';
+
+ $this->assertArrayHasKey('foo', $this->input->post());
+ $this->assertEquals('bar', $this->input->post('foo'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_post_exist_with_xss_clean()
+ {
+ $_SERVER['REQUEST_METHOD'] = 'POST';
+ $_POST['harm'] = "Hello, i try to your site";
+
+ $this->assertArrayHasKey('harm', $this->input->post());
+ $this->assertEquals("Hello, i try to your site", $this->input->post('harm'));
+ $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $this->input->post('harm', TRUE));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_get_post()
+ {
+ $_SERVER['REQUEST_METHOD'] = 'POST';
+ $_POST['foo'] = 'bar';
+
+ $this->assertEquals('bar', $this->input->get_post('foo'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_cookie()
+ {
+ $_COOKIE['foo'] = 'bar';
+
+ $this->assertEquals('bar', $this->input->cookie('foo'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_server()
+ {
+ $this->assertEquals('GET', $this->input->server('REQUEST_METHOD'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_fetch_from_array()
+ {
+ $data = array(
+ 'foo' => 'bar',
+ 'harm' => 'Hello, i try to your site',
+ );
+
+ $foo = $this->input->fetch_from_array($data, 'foo');
+ $harm = $this->input->fetch_from_array($data, 'harm');
+ $harmless = $this->input->fetch_from_array($data, 'harm', TRUE);
+
+ $this->assertEquals('bar', $foo);
+ $this->assertEquals("Hello, i try to your site", $harm);
+ $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless);
+ }
+}
\ No newline at end of file
diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php
index c3b526965..1796ba74d 100644
--- a/tests/codeigniter/core/Security_test.php
+++ b/tests/codeigniter/core/Security_test.php
@@ -4,19 +4,13 @@ class Security_test extends CI_TestCase {
public function set_up()
{
+ // Set cookie for security test
+ $_COOKIE['ci_csrf_cookie'] = md5(uniqid(rand(), TRUE));
+
+ // Set config for Security class
$this->ci_set_config('csrf_protection', TRUE);
$this->ci_set_config('csrf_token_name', 'ci_csrf_token');
- // @see : ./Bootstrap.php Line 16
$this->ci_set_config('csrf_cookie_name', 'ci_csrf_cookie');
- $this->ci_set_config('csrf_expire', 7200);
- $this->ci_set_config('csrf_regenerate', TRUE);
- $this->ci_set_config('csrf_exclude_uris', array());
-
- $this->ci_set_config('cookie_prefix', "");
- $this->ci_set_config('cookie_domain', "");
- $this->ci_set_config('cookie_path', "/");
- $this->ci_set_config('cookie_secure', FALSE);
- $this->ci_set_config('cookie_httponly', FALSE);
$this->security = new Mock_Core_Security();
}
diff --git a/tests/mocks/core/input.php b/tests/mocks/core/input.php
new file mode 100644
index 000000000..8a337d2ef
--- /dev/null
+++ b/tests/mocks/core/input.php
@@ -0,0 +1,31 @@
+_allow_get_array = (config_item('allow_get_array') === TRUE);
+ $this->_enable_xss = (config_item('global_xss_filtering') === TRUE);
+ $this->_enable_csrf = (config_item('csrf_protection') === TRUE);
+
+ // Assign Security and Utf8 classes
+ $this->security = $security;
+ $this->uni = $utf8;
+
+ // Sanitize global arrays
+ $this->_sanitize_globals();
+ }
+
+ public function fetch_from_array($array, $index = '', $xss_clean = FALSE)
+ {
+ return parent::_fetch_from_array($array, $index, $xss_clean);
+ }
+
+}
\ No newline at end of file
diff --git a/tests/mocks/core/security.php b/tests/mocks/core/security.php
index c5269fbc5..d7ea0e6bd 100644
--- a/tests/mocks/core/security.php
+++ b/tests/mocks/core/security.php
@@ -6,7 +6,7 @@ class Mock_Core_Security extends CI_Security {
{
// We cannot set cookie in CLI mode, so for csrf test, who rely on $_COOKIE,
// we superseded set_cookie with directly set the cookie variable,
- // @see : ./Bootstrap.php, line 16
+ // @see : ./tests/codeigniter/core/Security_test.php, line 8
return $this;
}
diff --git a/tests/mocks/core/utf8.php b/tests/mocks/core/utf8.php
new file mode 100644
index 000000000..b77d717e7
--- /dev/null
+++ b/tests/mocks/core/utf8.php
@@ -0,0 +1,27 @@
+
Date: Wed, 16 May 2012 00:08:05 +0700
Subject: Remove unused hardcoded reference from *phpunit.xml files
---
tests/travis/mysql.phpunit.xml | 2 --
tests/travis/pdo/mysql.phpunit.xml | 4 +---
tests/travis/pdo/pgsql.phpunit.xml | 2 --
tests/travis/pdo/sqlite.phpunit.xml | 2 --
tests/travis/pgsql.phpunit.xml | 2 --
tests/travis/sqlite.phpunit.xml | 2 --
6 files changed, 1 insertion(+), 13 deletions(-)
diff --git a/tests/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml
index c5fcf1335..1792ae38d 100644
--- a/tests/travis/mysql.phpunit.xml
+++ b/tests/travis/mysql.phpunit.xml
@@ -21,8 +21,6 @@
PEAR_INSTALL_DIRPHP_LIBDIR
- PROJECT_BASE.'tests'
- '../../system/core/CodeIgniter.php'
\ No newline at end of file
diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml
index f6fcc1c39..602030d4e 100644
--- a/tests/travis/pdo/mysql.phpunit.xml
+++ b/tests/travis/pdo/mysql.phpunit.xml
@@ -14,15 +14,13 @@
- ../../codeigniter/database
+ ../../codeigniterPEAR_INSTALL_DIRPHP_LIBDIR
- PROJECT_BASE.'tests'
- '../../../system/core/CodeIgniter.php'
\ No newline at end of file
diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml
index 6a23227db..77e1493c6 100644
--- a/tests/travis/pdo/pgsql.phpunit.xml
+++ b/tests/travis/pdo/pgsql.phpunit.xml
@@ -21,8 +21,6 @@
PEAR_INSTALL_DIRPHP_LIBDIR
- PROJECT_BASE.'tests'
- '../../../system/core/CodeIgniter.php'
\ No newline at end of file
diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml
index b85b7308a..cdccef017 100644
--- a/tests/travis/pdo/sqlite.phpunit.xml
+++ b/tests/travis/pdo/sqlite.phpunit.xml
@@ -21,8 +21,6 @@
PEAR_INSTALL_DIRPHP_LIBDIR
- PROJECT_BASE.'tests'
- '../../../system/core/CodeIgniter.php'
\ No newline at end of file
diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml
index 78b6046cf..dfc1bff1c 100644
--- a/tests/travis/pgsql.phpunit.xml
+++ b/tests/travis/pgsql.phpunit.xml
@@ -21,8 +21,6 @@
PEAR_INSTALL_DIRPHP_LIBDIR
- PROJECT_BASE.'tests'
- '../../system/core/CodeIgniter.php'
\ No newline at end of file
diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml
index 46e3d5073..3223da5e7 100644
--- a/tests/travis/sqlite.phpunit.xml
+++ b/tests/travis/sqlite.phpunit.xml
@@ -21,8 +21,6 @@
PEAR_INSTALL_DIRPHP_LIBDIR
- PROJECT_BASE.'tests'
- '../../system/core/CodeIgniter.php'
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 04d4091dfa551475998c351e09858e5ebdcf4482 Mon Sep 17 00:00:00 2001
From: Alan Jenkins
Date: Mon, 30 Apr 2012 16:04:43 +0100
Subject: fix backtrace filtering
The backtrace was filtered to remove CI system files,
but the filter was buggy. It would also filter out
application files which happened to contain the string "system"...
or ALL files, if the application directory is under /system/
(Perhaps the latter comes as a surprise, but it's explicitly
mentioned in index.php and ).
Instead, we should test whether the file is underneath BASEPATH
(using realpath() to make sure we have the same sort of slashes).
---
application/errors/error_php.php | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/application/errors/error_php.php b/application/errors/error_php.php
index 3855720de..b76dc8a9e 100644
--- a/application/errors/error_php.php
+++ b/application/errors/error_php.php
@@ -40,12 +40,15 @@
Backtrace:
-
+
+
File:
Line:
Function:
+
--
cgit v1.2.3-24-g4f1b
From 2ed226bd5ed19754c2fb28d4b98ac5423741f039 Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Wed, 16 May 2012 08:37:32 -0400
Subject: Add note in the upgrade guide to move errors folder
---
user_guide_src/source/installation/upgrade_300.rst | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst
index e434e8d45..63c4227dc 100644
--- a/user_guide_src/source/installation/upgrade_300.rst
+++ b/user_guide_src/source/installation/upgrade_300.rst
@@ -40,4 +40,9 @@ need to rename the `$active_record` variable to `$query_builder`.
$active_group = 'default';
// $active_record = TRUE;
- $query_builder = TRUE;
\ No newline at end of file
+ $query_builder = TRUE;
+
+Step 5: Move your errors folder
+===============================
+
+In version 3.0.0, the errors folder has been moved from "application/errors" to "application/views/errors".
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 09a1b5e7fb3c930aa9a50e246236227a499b5d28 Mon Sep 17 00:00:00 2001
From: Taufan Aditya
Date: Wed, 16 May 2012 22:18:00 +0700
Subject: Reduce decimal points, since there is a micro differencess on runtime
and update travis status
---
tests/README.md | 2 +-
tests/codeigniter/core/Benchmark_test.php | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/README.md b/tests/README.md
index b46f344cb..c8fc608e8 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -1,6 +1,6 @@
# CodeIgniter Unit Tests #
-Status : [![Build Status](https://secure.travis-ci.org/EllisLab/CodeIgniter.png?branch=feature/unit-tests)](http://travis-ci.org/EllisLab/CodeIgniter)
+Status : [![Build Status](https://secure.travis-ci.org/EllisLab/CodeIgniter.png?branch=develop)](http://travis-ci.org/EllisLab/CodeIgniter)
### Introduction:
diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php
index 2790b582e..109b38821 100644
--- a/tests/codeigniter/core/Benchmark_test.php
+++ b/tests/codeigniter/core/Benchmark_test.php
@@ -29,8 +29,8 @@ class Benchmark_test extends CI_TestCase {
$this->benchmark->mark('code_start');
sleep(1);
$this->benchmark->mark('code_end');
-
- $this->assertEquals('1.00', $this->benchmark->elapsed_time('code_start', 'code_end', 3));
+
+ $this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1));
}
// --------------------------------------------------------------------
--
cgit v1.2.3-24-g4f1b
From 94e74bf0f8ae82a28c70fe1a3cb76a01f6c50fd8 Mon Sep 17 00:00:00 2001
From: Alan Jenkins
Date: Wed, 16 May 2012 17:20:56 +0100
Subject: If we want E_STRICT, don't suppress it!
15be8fc "Changed the 'development' environment default error
reporting to included E_STRICT"
Not present in any tagged release, so
no need for -stable or a changlelog entry.
---
system/core/Common.php | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/system/core/Common.php b/system/core/Common.php
index 78aa6e874..ec94c528b 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -487,16 +487,6 @@ if ( ! function_exists('_exception_handler'))
*/
function _exception_handler($severity, $message, $filepath, $line)
{
- // We don't bother with "strict" notices since they tend to fill up
- // the log file with excess information that isn't normally very helpful.
- // For example, if you are running PHP 5 and you use version 4 style
- // class functions (without prefixes like "public", "private", etc.)
- // you'll get notices telling you that these have been deprecated.
- if ($severity == E_STRICT)
- {
- return;
- }
-
$_error =& load_class('Exceptions', 'core');
// Should we display the error? We'll get the current error_reporting
--
cgit v1.2.3-24-g4f1b
From e2c374fc474f91cc1c04aaae68e15cef6984f494 Mon Sep 17 00:00:00 2001
From: Alexander Hofstede
Date: Thu, 17 May 2012 00:28:08 +0200
Subject: Check cookie against md5 regex.
Otherwise, cookie can contain arbitrary injected code that gets sent
back directly to the browser.
---
system/core/Security.php | 2 +-
user_guide/changelog.html | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/system/core/Security.php b/system/core/Security.php
index a3e227437..6f5ac1ed8 100755
--- a/system/core/Security.php
+++ b/system/core/Security.php
@@ -848,7 +848,7 @@ class CI_Security {
// each page load since a page could contain embedded
// sub-pages causing this feature to fail
if (isset($_COOKIE[$this->_csrf_cookie_name]) &&
- $_COOKIE[$this->_csrf_cookie_name] != '')
+ preg_match('#^[0-9a-f]{32}$#iS', $_COOKIE[$this->_csrf_cookie_name]) === 1)
{
return $this->_csrf_hash = $_COOKIE[$this->_csrf_cookie_name];
}
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 613c4e65d..38275955b 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -85,6 +85,7 @@ Change Log
Fixed a bug - CI_Upload::_file_mime_type() could've failed if mime_content_type() is used for the detection and returns FALSE.
Fixed a bug (#538) - Windows paths were ignored when using the Image Manipulation Class to create a new file.
Fixed a bug - When database caching was enabled, $this->db->query() checked the cache before binding variables which resulted in cached queries never being found.
+
Fixed a bug - CSRF cookie value was allowed to be any (non-empty) string before being written to the output, making code injection a risk.
Fixed a bug - CI_Upload::_file_mime_type() could've failed if mime_content_type() is used for the detection and returns FALSE.
Fixed a bug (#538) - Windows paths were ignored when using the Image Manipulation Class to create a new file.
Fixed a bug - When database caching was enabled, $this->db->query() checked the cache before binding variables which resulted in cached queries never being found.
-
Fixed a bug - CSRF cookie value was allowed to be any (non-empty) string before being written to the output, making code injection a risk.
+
Fixed a bug - CSRF cookie value was allowed to be any (non-empty) string before being written to the output, making code injection a risk.
Fixed a bug - CI_Upload::_file_mime_type() could've failed if mime_content_type() is used for the detection and returns FALSE.
Fixed a bug (#538) - Windows paths were ignored when using the Image Manipulation Class to create a new file.
Fixed a bug - When database caching was enabled, $this->db->query() checked the cache before binding variables which resulted in cached queries never being found.
-
Fixed a bug - CSRF cookie value was allowed to be any (non-empty) string before being written to the output, making code injection a risk.
+
Fixed a bug - CSRF cookie value was allowed to be any (non-empty) string before being written to the output, making code injection a risk.
--
cgit v1.2.3-24-g4f1b
From 8f04c69fe65ddc2604425eaee811b50a909d905f Mon Sep 17 00:00:00 2001
From: Alexander Hofstede
Date: Thu, 17 May 2012 10:52:44 +0200
Subject: Use tabs for indenting
---
user_guide/changelog.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 38275955b..55fbceeaf 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -85,7 +85,7 @@ Change Log
Fixed a bug - CI_Upload::_file_mime_type() could've failed if mime_content_type() is used for the detection and returns FALSE.
Fixed a bug (#538) - Windows paths were ignored when using the Image Manipulation Class to create a new file.
Fixed a bug - When database caching was enabled, $this->db->query() checked the cache before binding variables which resulted in cached queries never being found.
-
Fixed a bug - CSRF cookie value was allowed to be any (non-empty) string before being written to the output, making code injection a risk.
+
Fixed a bug - CSRF cookie value was allowed to be any (non-empty) string before being written to the output, making code injection a risk.
--
cgit v1.2.3-24-g4f1b
From 92ebfb65ac044f5c2e6d88fba137253854cf1b94 Mon Sep 17 00:00:00 2001
From: Andrey Andreev
Date: Thu, 17 May 2012 12:49:24 +0300
Subject: Cleanup the core classes
---
system/core/Benchmark.php | 6 ++--
system/core/CodeIgniter.php | 2 +-
system/core/Common.php | 6 ++--
system/core/Config.php | 27 +++++++++---------
system/core/Controller.php | 7 +++--
system/core/Exceptions.php | 12 ++++----
system/core/Hooks.php | 6 ++--
system/core/Input.php | 31 ++++++++++-----------
system/core/Loader.php | 35 +++++++++++------------
system/core/Model.php | 3 ++
system/core/Output.php | 18 ++++++------
system/core/Router.php | 25 ++++++++---------
system/core/Security.php | 18 ++++++------
system/core/URI.php | 67 ++++++++++++++++++++++-----------------------
system/core/Utf8.php | 4 ++-
15 files changed, 135 insertions(+), 132 deletions(-)
diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php
index c17e95a19..bb630f40b 100755
--- a/system/core/Benchmark.php
+++ b/system/core/Benchmark.php
@@ -25,13 +25,11 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Benchmark Class
*
* This class enables you to mark points and calculate the time difference
- * between them. Memory consumption can also be displayed.
+ * between them. Memory consumption can also be displayed.
*
* @package CodeIgniter
* @subpackage Libraries
@@ -119,4 +117,4 @@ class CI_Benchmark {
}
/* End of file Benchmark.php */
-/* Location: ./system/core/Benchmark.php */
+/* Location: ./system/core/Benchmark.php */
\ No newline at end of file
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index 349f9f2d0..00db6e13a 100755
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
@@ -31,7 +31,7 @@
* Loads the base classes and executes the request.
*
* @package CodeIgniter
- * @subpackage codeigniter
+ * @subpackage CodeIgniter
* @category Front-controller
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/
diff --git a/system/core/Common.php b/system/core/Common.php
index 78aa6e874..8b897776f 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -31,7 +31,7 @@
* Loads the base classes and executes the request.
*
* @package CodeIgniter
- * @subpackage codeigniter
+ * @subpackage CodeIgniter
* @category Common Functions
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/
@@ -57,7 +57,7 @@ if ( ! function_exists('is_php'))
if ( ! isset($_is_php[$version]))
{
- $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE;
+ $_is_php[$version] = (version_compare(PHP_VERSION, $version) >= 0);
}
return $_is_php[$version];
@@ -506,7 +506,7 @@ if ( ! function_exists('_exception_handler'))
$_error->show_php_error($severity, $message, $filepath, $line);
}
- // Should we log the error? No? We're done...
+ // Should we log the error? No? We're done...
if (config_item('log_threshold') == 0)
{
return;
diff --git a/system/core/Config.php b/system/core/Config.php
index 9cebe6c86..c07ffa591 100755
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Config Class
*
@@ -46,14 +44,14 @@ class CI_Config {
* @var array
*/
public $config = array();
-
+
/**
* List of all loaded config files
*
* @var array
*/
public $is_loaded = array();
-
+
/**
* List of paths to search when trying to load a config file.
* This must be public as it's used by the Loader class.
@@ -77,9 +75,9 @@ class CI_Config {
{
if (isset($_SERVER['HTTP_HOST']))
{
- $base_url = ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
- $base_url .= '://'. $_SERVER['HTTP_HOST']
- . str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
+ $base_url = ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') ? 'https' : 'http';
+ $base_url .= '://'.$_SERVER['HTTP_HOST']
+ .str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
}
else
{
@@ -96,9 +94,9 @@ class CI_Config {
* Load Config File
*
* @param string the config file name
- * @param boolean if configuration values should be loaded into their own section
- * @param boolean true if errors should just return false, false if an error message should be displayed
- * @return boolean if the file was loaded correctly
+ * @param bool if configuration values should be loaded into their own section
+ * @param bool true if errors should just return false, false if an error message should be displayed
+ * @return bool if the file was loaded correctly
*/
public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
{
@@ -254,8 +252,8 @@ class CI_Config {
* Base URL
* Returns base_url [. uri_string]
*
- * @param string $uri
- * @return string
+ * @param string $uri
+ * @return string
*/
public function base_url($uri = '')
{
@@ -267,8 +265,8 @@ class CI_Config {
/**
* Build URI string for use in Config::site_url() and Config::base_url()
*
- * @param mixed $uri
- * @return string
+ * @param mixed $uri
+ * @return string
*/
protected function _uri_string($uri)
{
@@ -345,6 +343,7 @@ class CI_Config {
}
}
}
+
}
/* End of file Config.php */
diff --git a/system/core/Controller.php b/system/core/Controller.php
index 1f69146d0..491414807 100644
--- a/system/core/Controller.php
+++ b/system/core/Controller.php
@@ -48,6 +48,8 @@ class CI_Controller {
/**
* Set up controller properties and methods
+ *
+ * @return void
*/
public function __construct()
{
@@ -67,14 +69,15 @@ class CI_Controller {
}
/**
- * Return the CI object
+ * Return the CI object
*
- * @return object
+ * @return object
*/
public static function &get_instance()
{
return self::$instance;
}
+
}
/* End of file Controller.php */
diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php
index 2e9f0c766..965a717ad 100755
--- a/system/core/Exceptions.php
+++ b/system/core/Exceptions.php
@@ -65,6 +65,8 @@ class CI_Exceptions {
/**
* Initialize execption class
+ *
+ * @return void
*/
public function __construct()
{
@@ -87,7 +89,7 @@ class CI_Exceptions {
*/
public function log_exception($severity, $message, $filepath, $line)
{
- $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
+ $severity = isset($this->levels[$severity]) ? $this->levels[$severity] : $severity;
log_message('error', 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE);
}
@@ -127,14 +129,14 @@ class CI_Exceptions {
* @param string the heading
* @param string the message
* @param string the template name
- * @param int the status code
+ * @param int the status code
* @return string
*/
public function show_error($heading, $message, $template = 'error_general', $status_code = 500)
{
set_status_header($status_code);
- $message = '
Before performing an update you should take your site offline by replacing the index.php file with a static one.
+
+
Step 1: Update your CodeIgniter files
+
+
Replace all files and directories in your "system" folder and replace your index.php file. If any modifications were made to your index.php they will need to be made fresh in this new one.
+
+
Note: If you have any custom developed files in these folders please make copies of them first.
+
+
Step 2: Replace config/mimes.php
+
+
This config file has been updated to contain more user mime-types, please copy it to application/config/mimes.php.
@@ -89,7 +89,7 @@ minimizing the amount of code needed for a given task.
diff --git a/user_guide/installation/downloads.html b/user_guide/installation/downloads.html
index 14c65edd0..12252ad47 100644
--- a/user_guide/installation/downloads.html
+++ b/user_guide/installation/downloads.html
@@ -28,7 +28,7 @@
Public Git access is available at GitHub.
- Please note that while every effort is made to keep this code base functional, we cannot guarantee the functionality of code taken
- from the tip.
+
Public Git access is available at GitHub.
+ Please note that while every effort is made to keep this code base functional, we cannot guarantee the functionality of code taken
+ from the tip.
+
+
Beginning with version 2.0.3, stable tags are also available via GitHub, simply select the version from the Tags dropdown.
-
Beginning with version 2.0.3, stable tags are also available via GitHub, simply select the version from the Tags dropdown.