summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml9
-rw-r--r--application/config/database.php8
-rw-r--r--system/core/Loader.php16
-rwxr-xr-xsystem/core/Router.php5
-rwxr-xr-xsystem/core/URI.php2
-rwxr-xr-xsystem/database/DB.php20
-rw-r--r--system/database/DB_driver.php8
-rw-r--r--system/database/DB_query_builder.php (renamed from system/database/DB_active_rec.php)497
-rw-r--r--system/database/drivers/cubrid/cubrid_driver.php6
-rw-r--r--system/database/drivers/interbase/interbase_driver.php2
-rw-r--r--system/database/drivers/mssql/mssql_driver.php4
-rw-r--r--system/database/drivers/mysql/mysql_driver.php4
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php4
-rw-r--r--system/database/drivers/oci8/oci8_driver.php4
-rw-r--r--system/database/drivers/odbc/odbc_driver.php4
-rw-r--r--system/database/drivers/pdo/pdo_driver.php6
-rw-r--r--system/database/drivers/postgre/postgre_driver.php4
-rw-r--r--system/database/drivers/sqlite/sqlite_driver.php4
-rw-r--r--system/database/drivers/sqlite3/sqlite3_driver.php2
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_driver.php4
-rw-r--r--tests/codeigniter/database/DB_driver_test.php36
-rw-r--r--tests/codeigniter/database/query_builder/.gitkeep0
-rw-r--r--tests/codeigniter/database/query_builder/get_test.php53
-rw-r--r--tests/codeigniter/database/query_builder/insert_test.php67
-rw-r--r--tests/codeigniter/database/query_builder/select_test.php95
-rw-r--r--tests/mocks/autoloader.php15
-rwxr-xr-xtests/mocks/database/ci_test.sqlitebin17408 -> 17408 bytes
-rw-r--r--tests/mocks/database/config/pdo/mysql.php37
-rw-r--r--tests/mocks/database/config/pdo/pgsql.php37
-rw-r--r--tests/mocks/database/config/pdo/sqlite.php37
-rw-r--r--tests/mocks/database/config/sqlite.php9
-rw-r--r--tests/mocks/database/db.php17
-rw-r--r--tests/mocks/database/db/driver.php36
-rw-r--r--tests/mocks/database/db/querybuilder.php10
-rw-r--r--tests/mocks/database/drivers/mysql.php16
-rw-r--r--tests/mocks/database/drivers/pdo.php16
-rw-r--r--tests/mocks/database/drivers/postgre.php16
-rw-r--r--tests/mocks/database/drivers/sqlite.php16
-rw-r--r--tests/mocks/database/schema/.gitkeep0
-rw-r--r--tests/mocks/database/schema/skeleton.php98
-rw-r--r--tests/travis/mysql.phpunit.xml5
-rw-r--r--tests/travis/pdo/mysql.phpunit.xml32
-rw-r--r--tests/travis/pdo/pgsql.phpunit.xml32
-rw-r--r--tests/travis/pdo/sqlite.phpunit.xml32
-rw-r--r--tests/travis/pgsql.phpunit.xml5
-rw-r--r--tests/travis/sqlite.phpunit.xml5
-rw-r--r--user_guide_src/source/changelog.rst8
-rw-r--r--user_guide_src/source/database/configuration.rst12
-rw-r--r--user_guide_src/source/database/connecting.rst2
-rw-r--r--user_guide_src/source/database/examples.rst8
-rw-r--r--user_guide_src/source/database/index.rst4
-rw-r--r--user_guide_src/source/database/queries.rst2
-rw-r--r--user_guide_src/source/database/query_builder.rst (renamed from user_guide_src/source/database/active_record.rst)36
-rw-r--r--user_guide_src/source/general/models.rst2
-rw-r--r--user_guide_src/source/helpers/directory_helper.rst2
-rw-r--r--user_guide_src/source/installation/upgrade_300.rst10
-rw-r--r--user_guide_src/source/overview/features.rst2
-rw-r--r--user_guide_src/source/tutorial/create_news_items.rst2
-rw-r--r--user_guide_src/source/tutorial/index.rst2
-rw-r--r--user_guide_src/source/tutorial/news_section.rst4
60 files changed, 1061 insertions, 370 deletions
diff --git a/.travis.yml b/.travis.yml
index 84029b964..97ea0422d 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/application/config/database.php b/application/config/database.php
index f08d88761..19498735c 100644
--- a/application/config/database.php
+++ b/application/config/database.php
@@ -46,7 +46,7 @@
| cubrid, interbase, mssql, mysql, mysqli, oci8,
| odbc, pdo, postgre, sqlite, sqlite3, sqlsrv
| ['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
@@ -69,12 +69,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'] = array(
'dsn' => '',
diff --git a/system/core/Loader.php b/system/core/Loader.php
index 7fb3eab41..bf7f6cb02 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -323,16 +323,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') && $return == FALSE && $active_record == NULL && isset($CI->db) && is_object($CI->db))
+ if (class_exists('CI_DB') && $return == FALSE && $query_builder == NULL && isset($CI->db) && is_object($CI->db))
{
return FALSE;
}
@@ -341,7 +341,7 @@ class CI_Loader {
if ($return === TRUE)
{
- return DB($params, $active_record);
+ return DB($params, $query_builder);
}
// Initialize the db variable. Needed to prevent
@@ -349,7 +349,7 @@ class CI_Loader {
$CI->db = '';
// Load the DB class
- $CI->db =& DB($params, $active_record);
+ $CI->db =& DB($params, $query_builder);
}
// --------------------------------------------------------------------
@@ -683,7 +683,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);
}
// --------------------------------------------------------------------
@@ -723,7 +723,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
{
@@ -1263,4 +1263,4 @@ class CI_Loader {
}
/* End of file Loader.php */
-/* Location: ./system/core/Loader.php */ \ No newline at end of file
+/* Location: ./system/core/Loader.php */
diff --git a/system/core/Router.php b/system/core/Router.php
index 9314052fe..fe9909b06 100755
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -242,9 +242,12 @@ 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 ff2c458b8..705575a0c 100755
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -645,7 +645,7 @@ class CI_URI {
*/
public function ruri_string()
{
- return '/'.implode('/', $this->rsegment_array());
+ return implode('/', $this->rsegment_array());
}
}
diff --git a/system/database/DB.php b/system/database/DB.php
index 0d81e40d3..b28439b29 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) && strpos($params, '://') === FALSE)
@@ -111,22 +111,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'))
@@ -159,4 +159,4 @@ function &DB($params = '', $active_record_override = NULL)
}
/* End of file DB.php */
-/* Location: ./system/database/DB.php */ \ No newline at end of file
+/* Location: ./system/database/DB.php */
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index cb04c7103..ef77b594e 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -1208,7 +1208,7 @@ abstract 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
@@ -1283,7 +1283,7 @@ abstract 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)
{
@@ -1380,7 +1380,7 @@ abstract 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.
*
@@ -1393,4 +1393,4 @@ abstract class CI_DB_driver {
}
/* End of file DB_driver.php */
-/* Location: ./system/database/DB_driver.php */ \ No newline at end of file
+/* Location: ./system/database/DB_driver.php */
diff --git a/system/database/DB_active_rec.php b/system/database/DB_query_builder.php
index e78b2a893..393a1cd75 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_query_builder.php
@@ -26,9 +26,9 @@
*/
/**
- * Active Record Class
+ * Query Builder Class
*
- * This is the platform-independent base Active Record implementation class.
+ * This is the platform-independent base Query Builder implementation class.
*
* @package CodeIgniter
* @subpackage Drivers
@@ -36,46 +36,47 @@
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
*/
-abstract class CI_DB_active_record extends CI_DB_driver {
+
+abstract class CI_DB_query_builder extends CI_DB_driver {
protected $return_delete_sql = FALSE;
protected $reset_delete_data = FALSE;
- protected $ar_select = array();
- protected $ar_distinct = FALSE;
- protected $ar_from = array();
- protected $ar_join = array();
- protected $ar_where = array();
- protected $ar_like = array();
- protected $ar_groupby = array();
- protected $ar_having = array();
- protected $ar_keys = array();
- protected $ar_limit = FALSE;
- protected $ar_offset = FALSE;
- protected $ar_order = FALSE;
- protected $ar_orderby = array();
- protected $ar_set = array();
- protected $ar_wherein = array();
- protected $ar_aliased_tables = array();
- protected $ar_store_array = array();
- protected $ar_where_group_started = FALSE;
- protected $ar_where_group_count = 0;
-
- // Active Record Caching variables
- protected $ar_caching = FALSE;
- protected $ar_cache_exists = array();
- protected $ar_cache_select = array();
- protected $ar_cache_from = array();
- protected $ar_cache_join = array();
- protected $ar_cache_where = array();
- protected $ar_cache_like = array();
- protected $ar_cache_groupby = array();
- protected $ar_cache_having = array();
- protected $ar_cache_orderby = array();
- protected $ar_cache_set = array();
-
- protected $ar_no_escape = array();
- protected $ar_cache_no_escape = array();
+ protected $qb_select = array();
+ protected $qb_distinct = FALSE;
+ protected $qb_from = array();
+ protected $qb_join = array();
+ protected $qb_where = array();
+ protected $qb_like = array();
+ protected $qb_groupby = array();
+ protected $qb_having = array();
+ protected $qb_keys = array();
+ protected $qb_limit = FALSE;
+ protected $qb_offset = FALSE;
+ protected $qb_order = FALSE;
+ protected $qb_orderby = array();
+ protected $qb_set = array();
+ protected $qb_wherein = array();
+ protected $qb_aliased_tables = array();
+ protected $qb_store_array = array();
+ protected $qb_where_group_started = FALSE;
+ protected $qb_where_group_count = 0;
+
+ // Query Builder Caching variables
+ protected $qb_caching = FALSE;
+ protected $qb_cache_exists = array();
+ protected $qb_cache_select = array();
+ protected $qb_cache_from = array();
+ protected $qb_cache_join = array();
+ protected $qb_cache_where = array();
+ protected $qb_cache_like = array();
+ protected $qb_cache_groupby = array();
+ protected $qb_cache_having = array();
+ protected $qb_cache_orderby = array();
+ protected $qb_cache_set = array();
+
+ protected $qb_no_escape = array();
+ protected $qb_cache_no_escape = array();
/**
* Select
@@ -98,14 +99,14 @@ abstract class CI_DB_active_record extends CI_DB_driver {
if ($val != '')
{
- $this->ar_select[] = $val;
- $this->ar_no_escape[] = $escape;
+ $this->qb_select[] = $val;
+ $this->qb_no_escape[] = $escape;
- if ($this->ar_caching === TRUE)
+ if ($this->qb_caching === TRUE)
{
- $this->ar_cache_select[] = $val;
- $this->ar_cache_exists[] = 'select';
- $this->ar_cache_no_escape[] = $escape;
+ $this->qb_cache_select[] = $val;
+ $this->qb_cache_exists[] = 'select';
+ $this->qb_cache_no_escape[] = $escape;
}
}
}
@@ -211,13 +212,14 @@ abstract class CI_DB_active_record extends CI_DB_driver {
}
$sql = $this->protect_identifiers($type.'('.trim($select).')').' AS '.$this->protect_identifiers(trim($alias));
- $this->ar_select[] = $sql;
- $this->ar_no_escape[] = NULL;
+
+ $this->qb_select[] = $sql;
+ $this->qb_no_escape[] = NULL;
- if ($this->ar_caching === TRUE)
+ if ($this->qb_caching === TRUE)
{
- $this->ar_cache_select[] = $sql;
- $this->ar_cache_exists[] = 'select';
+ $this->qb_cache_select[] = $sql;
+ $this->qb_cache_exists[] = 'select';
}
return $this;
@@ -254,7 +256,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
*/
public function distinct($val = TRUE)
{
- $this->ar_distinct = (is_bool($val)) ? $val : TRUE;
+ $this->qb_distinct = (is_bool($val)) ? $val : TRUE;
return $this;
}
@@ -278,12 +280,13 @@ abstract class CI_DB_active_record extends CI_DB_driver {
{
$v = trim($v);
$this->_track_aliases($v);
- $v = $this->ar_from[] = $this->protect_identifiers($v, TRUE, NULL, FALSE);
- if ($this->ar_caching === TRUE)
+ $v = $this->qb_from[] = $this->protect_identifiers($v, TRUE, NULL, FALSE);
+
+ if ($this->qb_caching === TRUE)
{
- $this->ar_cache_from[] = $v;
- $this->ar_cache_exists[] = 'from';
+ $this->qb_cache_from[] = $v;
+ $this->qb_cache_exists[] = 'from';
}
}
}
@@ -292,14 +295,15 @@ abstract class CI_DB_active_record 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->ar_from[] = $val = $this->protect_identifiers($val, TRUE, NULL, FALSE);
- if ($this->ar_caching === TRUE)
+ $this->qb_from[] = $val = $this->protect_identifiers($val, TRUE, NULL, FALSE);
+
+ if ($this->qb_caching === TRUE)
{
- $this->ar_cache_from[] = $val;
- $this->ar_cache_exists[] = 'from';
+ $this->qb_cache_from[] = $val;
+ $this->qb_cache_exists[] = 'from';
}
}
}
@@ -336,7 +340,7 @@ abstract class CI_DB_active_record 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
@@ -346,12 +350,12 @@ abstract class CI_DB_active_record extends CI_DB_driver {
}
// Assemble the JOIN statement
- $this->ar_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->ar_caching === TRUE)
+ if ($this->qb_caching === TRUE)
{
- $this->ar_cache_join[] = $join;
- $this->ar_cache_exists[] = 'join';
+ $this->qb_cache_join[] = $join;
+ $this->qb_cache_exists[] = 'join';
}
return $this;
@@ -420,7 +424,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
foreach ($key as $k => $v)
{
- $prefix = (count($this->ar_where) === 0 && count($this->ar_cache_where) === 0) ? '' : $type;
+ $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) ? '' : $type;
if (is_null($v) && ! $this->_has_operator($k))
{
@@ -446,11 +450,11 @@ abstract class CI_DB_active_record extends CI_DB_driver {
$k = $this->protect_identifiers($k, FALSE, $escape);
}
- $this->ar_where[] = $prefix.$k.$v;
- if ($this->ar_caching === TRUE)
+ $this->qb_where[] = $prefix.$k.$v;
+ if ($this->qb_caching === TRUE)
{
- $this->ar_cache_where[] = $prefix.$k.$v;
- $this->ar_cache_exists[] = 'where';
+ $this->qb_cache_where[] = $prefix.$k.$v;
+ $this->qb_cache_exists[] = 'where';
}
}
@@ -557,20 +561,20 @@ abstract class CI_DB_active_record extends CI_DB_driver {
foreach ($values as $value)
{
- $this->ar_wherein[] = $this->escape($value);
+ $this->qb_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).') ';
+ $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->ar_caching === TRUE)
+ if ($this->qb_caching === TRUE)
{
- $this->ar_cache_where[] = $where_in;
- $this->ar_cache_exists[] = 'where';
+ $this->qb_cache_where[] = $where_in;
+ $this->qb_cache_exists[] = 'where';
}
// reset the array for multiple calls
- $this->ar_wherein = array();
+ $this->qb_wherein = array();
return $this;
}
@@ -666,7 +670,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
foreach ($field as $k => $v)
{
$k = $this->protect_identifiers($k);
- $prefix = (count($this->ar_like) === 0) ? '' : $type;
+ $prefix = (count($this->qb_like) === 0) ? '' : $type;
$v = $this->escape_like_str($v);
if ($side === 'none')
@@ -692,11 +696,11 @@ abstract class CI_DB_active_record extends CI_DB_driver {
$like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_chr);
}
- $this->ar_like[] = $like_statement;
- if ($this->ar_caching === TRUE)
+ $this->qb_like[] = $like_statement;
+ if ($this->qb_caching === TRUE)
{
- $this->ar_cache_like[] = $like_statement;
- $this->ar_cache_exists[] = 'like';
+ $this->qb_cache_like[] = $like_statement;
+ $this->qb_cache_exists[] = 'like';
}
}
@@ -716,13 +720,14 @@ abstract class CI_DB_active_record extends CI_DB_driver {
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 && 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->qb_where_group_started = TRUE;
+ $prefix = (count($this->qb_where) === 0 && 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->ar_cache_where[] = $value;
+ $this->qb_cache_where[] = $value;
}
return $this;
@@ -773,12 +778,12 @@ abstract class CI_DB_active_record extends CI_DB_driver {
*/
public function group_end()
{
- $this->ar_where_group_started = FALSE;
- $this->ar_where[] = $value = str_repeat(' ', $this->ar_where_group_count--) . ')';
+ $this->qb_where_group_started = FALSE;
+ $this->qb_where[] = $value = str_repeat(' ', $this->qb_where_group_count--) . ')';
- if ($this->ar_caching)
+ if ($this->qb_caching)
{
- $this->ar_cache_where[] = $value;
+ $this->qb_cache_where[] = $value;
}
return $this;
@@ -796,10 +801,10 @@ abstract class CI_DB_active_record extends CI_DB_driver {
*/
protected function _group_get_type($type)
{
- if ($this->ar_where_group_started)
+ if ($this->qb_where_group_started)
{
$type = '';
- $this->ar_where_group_started = FALSE;
+ $this->qb_where_group_started = FALSE;
}
return $type;
@@ -826,12 +831,12 @@ abstract class CI_DB_active_record extends CI_DB_driver {
if ($val != '')
{
- $this->ar_groupby[] = $val = $this->protect_identifiers($val);
+ $this->qb_groupby[] = $val = $this->protect_identifiers($val);
- if ($this->ar_caching === TRUE)
+ if ($this->qb_caching === TRUE)
{
- $this->ar_cache_groupby[] = $val;
- $this->ar_cache_exists[] = 'groupby';
+ $this->qb_cache_groupby[] = $val;
+ $this->qb_cache_exists[] = 'groupby';
}
}
}
@@ -891,7 +896,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
foreach ($key as $k => $v)
{
- $prefix = (count($this->ar_having) === 0) ? '' : $type;
+ $prefix = (count($this->qb_having) === 0) ? '' : $type;
if ($escape === TRUE)
{
@@ -908,11 +913,11 @@ abstract class CI_DB_active_record extends CI_DB_driver {
$v = ' '.$this->escape($v);
}
- $this->ar_having[] = $prefix.$k.$v;
- if ($this->ar_caching === TRUE)
+ $this->qb_having[] = $prefix.$k.$v;
+ if ($this->qb_caching === TRUE)
{
- $this->ar_cache_having[] = $prefix.$k.$v;
- $this->ar_cache_exists[] = 'having';
+ $this->qb_cache_having[] = $prefix.$k.$v;
+ $this->qb_cache_exists[] = 'having';
}
}
@@ -948,7 +953,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
foreach (explode(',', $orderby) as $part)
{
$part = trim($part);
- if ( ! in_array($part, $this->ar_aliased_tables))
+ if ( ! in_array($part, $this->qb_aliased_tables))
{
$part = $this->protect_identifiers(trim($part));
}
@@ -966,12 +971,12 @@ abstract class CI_DB_active_record extends CI_DB_driver {
}
}
- $this->ar_orderby[] = $orderby_statement = $orderby.$direction;
+ $this->qb_orderby[] = $orderby_statement = $orderby.$direction;
- if ($this->ar_caching === TRUE)
+ if ($this->qb_caching === TRUE)
{
- $this->ar_cache_orderby[] = $orderby_statement;
- $this->ar_cache_exists[] = 'orderby';
+ $this->qb_cache_orderby[] = $orderby_statement;
+ $this->qb_cache_exists[] = 'orderby';
}
return $this;
@@ -988,11 +993,11 @@ abstract class CI_DB_active_record extends CI_DB_driver {
*/
public function limit($value, $offset = NULL)
{
- $this->ar_limit = (int) $value;
+ $this->qb_limit = (int) $value;
if ( ! is_null($offset))
{
- $this->ar_offset = (int) $offset;
+ $this->qb_offset = (int) $offset;
}
return $this;
@@ -1008,7 +1013,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
*/
public function offset($offset)
{
- $this->ar_offset = (int) $offset;
+ $this->qb_offset = (int) $offset;
return $this;
}
@@ -1035,11 +1040,11 @@ abstract class CI_DB_active_record extends CI_DB_driver {
{
if ($escape === FALSE)
{
- $this->ar_set[$this->protect_identifiers($k)] = $v;
+ $this->qb_set[$this->protect_identifiers($k)] = $v;
}
else
{
- $this->ar_set[$this->protect_identifiers($k, FALSE, TRUE)] = $this->escape($v);
+ $this->qb_set[$this->protect_identifiers($k, FALSE, TRUE)] = $this->escape($v);
}
}
@@ -1054,7 +1059,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
* Compiles a SELECT query string and returns the sql.
*
* @param string the table name to select from (optional)
- * @param bool TRUE: resets AR values; FALSE: leave AR vaules alone
+ * @param bool TRUE: resets QB values; FALSE: leave QB vaules alone
* @return string
*/
public function get_compiled_select($table = '', $reset = TRUE)
@@ -1110,7 +1115,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
* "Count All Results" query
*
* Generates a platform-specific query string that counts all records
- * returned by an Active Record query.
+ * returned by an Query Builder query.
*
* @param string
* @return string
@@ -1186,7 +1191,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
$this->set_insert_batch($set);
}
- if (count($this->ar_set) === 0)
+ if (count($this->qb_set) === 0)
{
if ($this->db_debug)
{
@@ -1198,18 +1203,18 @@ abstract class CI_DB_active_record extends CI_DB_driver {
if ($table == '')
{
- if ( ! isset($this->ar_from[0]))
+ if ( ! isset($this->qb_from[0]))
{
return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
- $table = $this->ar_from[0];
+ $table = $this->qb_from[0];
}
// Batch this baby
- for ($i = 0, $total = count($this->ar_set); $i < $total; $i += 100)
+ 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->ar_keys, array_slice($this->ar_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();
@@ -1261,7 +1266,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
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();
+ $this->qb_set[] = array();
return;
}
@@ -1269,7 +1274,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
if ($escape === FALSE)
{
- $this->ar_set[] = '('.implode(',', $row).')';
+ $this->qb_set[] = '('.implode(',', $row).')';
}
else
{
@@ -1279,13 +1284,13 @@ abstract class CI_DB_active_record extends CI_DB_driver {
$clean[] = $this->escape($value);
}
- $this->ar_set[] = '('.implode(',', $clean).')';
+ $this->qb_set[] = '('.implode(',', $clean).')';
}
}
foreach ($keys as $k)
{
- $this->ar_keys[] = $this->protect_identifiers($k);
+ $this->qb_keys[] = $this->protect_identifiers($k);
}
return $this;
@@ -1299,7 +1304,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
* Compiles an insert query and returns the sql
*
* @param string the table to insert into
- * @param bool TRUE: reset AR values; FALSE: leave AR values alone
+ * @param bool TRUE: reset QB values; FALSE: leave QB values alone
* @return string
*/
public function get_compiled_insert($table = '', $reset = TRUE)
@@ -1310,9 +1315,11 @@ abstract class CI_DB_active_record extends CI_DB_driver {
}
$sql = $this->_insert(
- $this->protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE),
- array_keys($this->ar_set),
- array_values($this->ar_set)
+ $this->protect_identifiers(
+ $this->qb_from[0], TRUE, NULL, FALSE
+ ),
+ array_keys($this->qb_set),
+ array_values($this->qb_set)
);
if ($reset === TRUE)
@@ -1347,9 +1354,11 @@ abstract class CI_DB_active_record extends CI_DB_driver {
}
$sql = $this->_insert(
- $this->protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE),
- array_keys($this->ar_set),
- array_values($this->ar_set)
+ $this->protect_identifiers(
+ $this->qb_from[0], TRUE, NULL, FALSE
+ ),
+ array_keys($this->qb_set),
+ array_values($this->qb_set)
);
$this->_reset_write();
@@ -1387,21 +1396,21 @@ abstract class CI_DB_active_record extends CI_DB_driver {
*/
protected function _validate_insert($table = '')
{
- if (count($this->ar_set) === 0)
+ if (count($this->qb_set) === 0)
{
return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
if ($table == '')
{
- if ( ! isset($this->ar_from[0]))
+ if ( ! isset($this->qb_from[0]))
{
return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
}
else
{
- $this->ar_from[0] = $table;
+ $this->qb_from[0] = $table;
}
return TRUE;
@@ -1425,22 +1434,23 @@ abstract class CI_DB_active_record extends CI_DB_driver {
$this->set($set);
}
- if (count($this->ar_set) === 0)
+ if (count($this->qb_set) === 0)
{
return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
if ($table == '')
{
- if ( ! isset($this->ar_from[0]))
+ if ( ! isset($this->qb_from[0]))
{
return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
- $table = $this->ar_from[0];
+ $table = $this->qb_from[0];
}
- $sql = $this->_replace($this->protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_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);
}
@@ -1470,7 +1480,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
* Compiles an update query and returns the sql
*
* @param string the table to update
- * @param bool TRUE: reset AR values; FALSE: leave AR values alone
+ * @param bool TRUE: reset QB values; FALSE: leave QB values alone
* @return string
*/
public function get_compiled_update($table = '', $reset = TRUE)
@@ -1483,7 +1493,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
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);
+ $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)
{
@@ -1530,7 +1540,8 @@ abstract class CI_DB_active_record extends CI_DB_driver {
$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);
+ $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);
}
@@ -1584,21 +1595,21 @@ abstract class CI_DB_active_record extends CI_DB_driver {
*/
protected function _validate_update($table = '')
{
- if (count($this->ar_set) == 0)
+ if (count($this->qb_set) == 0)
{
return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
if ($table == '')
{
- if ( ! isset($this->ar_from[0]))
+ if ( ! isset($this->qb_from[0]))
{
return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
}
else
{
- $this->ar_from[0] = $table;
+ $this->qb_from[0] = $table;
}
return TRUE;
@@ -1631,25 +1642,25 @@ abstract class CI_DB_active_record extends CI_DB_driver {
$this->set_update_batch($set, $index);
}
- if (count($this->ar_set) === 0)
+ if (count($this->qb_set) === 0)
{
return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
if ($table == '')
{
- if ( ! isset($this->ar_from[0]))
+ if ( ! isset($this->qb_from[0]))
{
return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
- $table = $this->ar_from[0];
+ $table = $this->qb_from[0];
}
// Batch this baby
- for ($i = 0, $total = count($this->ar_set); $i < $total; $i += 100)
+ 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->ar_set, $i, 100), $this->protect_identifiers($index), $this->ar_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();
@@ -1698,7 +1709,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
return $this->display_error('db_batch_missing_index');
}
- $this->ar_set[] = $clean;
+ $this->qb_set[] = $clean;
}
return $this;
@@ -1718,12 +1729,12 @@ abstract class CI_DB_active_record extends CI_DB_driver {
{
if ($table == '')
{
- if ( ! isset($this->ar_from[0]))
+ if ( ! isset($this->qb_from[0]))
{
return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
- $table = $this->ar_from[0];
+ $table = $this->qb_from[0];
}
else
{
@@ -1751,12 +1762,12 @@ abstract class CI_DB_active_record extends CI_DB_driver {
{
if ($table == '')
{
- if ( ! isset($this->ar_from[0]))
+ if ( ! isset($this->qb_from[0]))
{
return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
- $table = $this->ar_from[0];
+ $table = $this->qb_from[0];
}
else
{
@@ -1794,7 +1805,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
* Compiles a delete query string and returns the sql
*
* @param string the table to delete from
- * @param bool TRUE: reset AR values; FALSE: leave AR values alone
+ * @param bool TRUE: reset QB values; FALSE: leave QB values alone
* @return string
*/
public function get_compiled_delete($table = '', $reset = TRUE)
@@ -1825,12 +1836,12 @@ abstract class CI_DB_active_record extends CI_DB_driver {
if ($table == '')
{
- if ( ! isset($this->ar_from[0]))
+ if ( ! isset($this->qb_from[0]))
{
return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
- $table = $this->ar_from[0];
+ $table = $this->qb_from[0];
}
elseif (is_array($table))
{
@@ -1857,12 +1868,12 @@ abstract class CI_DB_active_record extends CI_DB_driver {
$this->limit($limit);
}
- if (count($this->ar_where) === 0 && count($this->ar_wherein) === 0 && count($this->ar_like) === 0)
+ 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->ar_where, $this->ar_like, $this->ar_limit);
+ $sql = $this->_delete($table, $this->qb_where, $this->qb_like, $this->qb_limit);
if ($reset_data)
{
$this->_reset_write();
@@ -1969,9 +1980,9 @@ abstract class CI_DB_active_record extends CI_DB_driver {
$table = trim(strrchr($table, ' '));
// Store the alias, if it doesn't already exist
- if ( ! in_array($table, $this->ar_aliased_tables))
+ if ( ! in_array($table, $this->qb_aliased_tables))
{
- $this->ar_aliased_tables[] = $table;
+ $this->qb_aliased_tables[] = $table;
}
}
}
@@ -1998,9 +2009,9 @@ abstract class CI_DB_active_record extends CI_DB_driver {
}
else
{
- $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';
+ $sql = ( ! $this->qb_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';
- if (count($this->ar_select) === 0)
+ if (count($this->qb_select) === 0)
{
$sql .= '*';
}
@@ -2009,73 +2020,73 @@ abstract class CI_DB_active_record extends CI_DB_driver {
// 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)
+ foreach ($this->qb_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);
+ $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->ar_select);
+ $sql .= implode(', ', $this->qb_select);
}
}
// Write the "FROM" portion of the query
- if (count($this->ar_from) > 0)
+ if (count($this->qb_from) > 0)
{
- $sql .= "\nFROM ".$this->_from_tables($this->ar_from);
+ $sql .= "\nFROM ".$this->_from_tables($this->qb_from);
}
// Write the "JOIN" portion of the query
- if (count($this->ar_join) > 0)
+ if (count($this->qb_join) > 0)
{
- $sql .= "\n".implode("\n", $this->ar_join);
+ $sql .= "\n".implode("\n", $this->qb_join);
}
// Write the "WHERE" portion of the query
- if (count($this->ar_where) > 0 OR count($this->ar_like) > 0)
+ if (count($this->qb_where) > 0 OR count($this->qb_like) > 0)
{
$sql .= "\nWHERE ";
}
- $sql .= implode("\n", $this->ar_where);
+ $sql .= implode("\n", $this->qb_where);
// Write the "LIKE" portion of the query
- if (count($this->ar_like) > 0)
+ if (count($this->qb_like) > 0)
{
- if (count($this->ar_where) > 0)
+ if (count($this->qb_where) > 0)
{
$sql .= "\nAND ";
}
- $sql .= implode("\n", $this->ar_like);
+ $sql .= implode("\n", $this->qb_like);
}
// Write the "GROUP BY" portion of the query
- if (count($this->ar_groupby) > 0)
+ if (count($this->qb_groupby) > 0)
{
- $sql .= "\nGROUP BY ".implode(', ', $this->ar_groupby);
+ $sql .= "\nGROUP BY ".implode(', ', $this->qb_groupby);
}
// Write the "HAVING" portion of the query
- if (count($this->ar_having) > 0)
+ if (count($this->qb_having) > 0)
{
- $sql .= "\nHAVING ".implode("\n", $this->ar_having);
+ $sql .= "\nHAVING ".implode("\n", $this->qb_having);
}
// Write the "ORDER BY" portion of the query
- if (count($this->ar_orderby) > 0)
+ if (count($this->qb_orderby) > 0)
{
- $sql .= "\nORDER BY ".implode(', ', $this->ar_orderby);
- if ($this->ar_order !== FALSE)
+ $sql .= "\nORDER BY ".implode(', ', $this->qb_orderby);
+ if ($this->qb_order !== FALSE)
{
- $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC';
+ $sql .= ($this->qb_order == 'desc') ? ' DESC' : ' ASC';
}
}
// Write the "LIMIT" portion of the query
- if (is_numeric($this->ar_limit))
+ if (is_numeric($this->qb_limit))
{
- return $this->_limit($sql."\n", $this->ar_limit, $this->ar_offset);
+ return $this->_limit($sql."\n", $this->qb_limit, $this->qb_offset);
}
return $sql;
@@ -2153,13 +2164,13 @@ abstract class CI_DB_active_record extends CI_DB_driver {
/**
* Start Cache
*
- * Starts AR caching
+ * Starts QB caching
*
* @return void
*/
public function start_cache()
{
- $this->ar_caching = TRUE;
+ $this->qb_caching = TRUE;
}
// --------------------------------------------------------------------
@@ -2167,13 +2178,13 @@ abstract class CI_DB_active_record extends CI_DB_driver {
/**
* Stop Cache
*
- * Stops AR caching
+ * Stops QB caching
*
* @return void
*/
public function stop_cache()
{
- $this->ar_caching = FALSE;
+ $this->qb_caching = FALSE;
}
// --------------------------------------------------------------------
@@ -2181,24 +2192,24 @@ abstract class CI_DB_active_record extends CI_DB_driver {
/**
* Flush Cache
*
- * Empties the AR cache
+ * Empties the QB cache
*
* @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()
+ '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()
));
}
@@ -2207,47 +2218,47 @@ abstract class CI_DB_active_record 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
*/
protected function _merge_cache()
{
- if (count($this->ar_cache_exists) === 0)
+ if (count($this->qb_cache_exists) === 0)
{
return;
}
- foreach ($this->ar_cache_exists as $val)
+ foreach ($this->qb_cache_exists as $val)
{
- $ar_variable = 'ar_'.$val;
- $ar_cache_var = 'ar_cache_'.$val;
+ $qb_variable = 'qb_'.$val;
+ $qb_cache_var = 'qb_cache_'.$val;
- if (count($this->$ar_cache_var) === 0)
+ if (count($this->$qb_cache_var) === 0)
{
continue;
}
- $this->$ar_variable = array_unique(array_merge($this->$ar_cache_var, $this->$ar_variable));
+ $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 && count($this->ar_cache_from) > 0)
+ if ($this->_protect_identifiers === TRUE && count($this->qb_cache_from) > 0)
{
- $this->_track_aliases($this->ar_from);
+ $this->_track_aliases($this->qb_from);
}
- $this->ar_no_escape = $this->ar_cache_no_escape;
+ $this->qb_no_escape = $this->qb_cache_no_escape;
}
// --------------------------------------------------------------------
/**
- * Reset Active Record values.
+ * Reset Query Builder values.
*
- * Publicly-visible method to reset the AR values.
+ * Publicly-visible method to reset the QB values.
*
* @return void
*/
@@ -2260,16 +2271,16 @@ abstract class CI_DB_active_record extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Resets the active record values. Called by the get() function
+ * Resets the query builder values. Called by the get() function
*
* @param array An array of fields to reset
* @return void
*/
- protected function _reset_run($ar_reset_items)
+ protected function _reset_run($qb_reset_items)
{
- foreach ($ar_reset_items as $item => $default_value)
+ foreach ($qb_reset_items as $item => $default_value)
{
- if ( ! in_array($item, $this->ar_store_array))
+ if ( ! in_array($item, $this->qb_store_array))
{
$this->$item = $default_value;
}
@@ -2279,28 +2290,28 @@ abstract class CI_DB_active_record extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Resets the active record values. Called by the get() function
+ * 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
+ '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
)
);
}
@@ -2308,7 +2319,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Resets the active record "write" values.
+ * Resets the query builder "write" values.
*
* Called by the insert() update() insert_batch() update_batch() and delete() functions
*
@@ -2317,19 +2328,19 @@ abstract class CI_DB_active_record 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
)
);
}
}
-/* End of file DB_active_rec.php */
-/* Location: ./system/database/DB_active_rec.php */ \ No newline at end of file
+/* End of file DB_query_builder.php */
+/* Location: ./system/database/DB_query_builder.php */ \ No newline at end of file
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index 7a5c048f9..c5018bf93 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -29,7 +29,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
@@ -508,7 +508,7 @@ class CI_DB_cubrid_driver extends CI_DB {
}
// --------------------------------------------------------------------
-
+
/**
* Limit string
*
@@ -549,4 +549,4 @@ class CI_DB_cubrid_driver extends CI_DB {
}
/* 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/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php
index 6587d72ff..1b18de803 100644
--- a/system/database/drivers/interbase/interbase_driver.php
+++ b/system/database/drivers/interbase/interbase_driver.php
@@ -29,7 +29,7 @@
* Firebird/Interbase 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/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 90609a84d..f60ec8168 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -29,7 +29,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
@@ -534,4 +534,4 @@ class CI_DB_mssql_driver extends CI_DB {
}
/* 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/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index c2fccc1f7..32c51865d 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
@@ -531,4 +531,4 @@ class CI_DB_mysql_driver extends CI_DB {
}
/* End of file mysql_driver.php */
-/* Location: ./system/database/drivers/mysql/mysql_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysql/mysql_driver.php */
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index a690682be..e2684e4f2 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
@@ -535,4 +535,4 @@ class CI_DB_mysqli_driver extends CI_DB {
}
/* End of file mysqli_driver.php */
-/* Location: ./system/database/drivers/mysqli/mysqli_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/mysqli/mysqli_driver.php */
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index 1b66178c6..33a89df94 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -29,7 +29,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
@@ -682,4 +682,4 @@ class CI_DB_oci8_driver extends CI_DB {
}
/* End of file oci8_driver.php */
-/* Location: ./system/database/drivers/oci8/oci8_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/oci8/oci8_driver.php */
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index 38416cf90..e36f2d233 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -29,7 +29,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
@@ -413,4 +413,4 @@ class CI_DB_odbc_driver extends CI_DB {
}
/* 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/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index 60151b900..89e69676d 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -29,7 +29,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
@@ -225,7 +225,7 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Reference: http://www.php.net/manual/en/ref.pdo-mysql.connection.php
*/
- if ($this->subdriver === 'mysql' && ! is_php('5.3.6') && ! empty($this->char_set))
+ if ($this->pdodriver === 'mysql' && ! is_php('5.3.6') && ! empty($this->char_set))
{
$this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES '.$this->char_set
.( ! empty($this->db_collat) ? " COLLATE '".$this->dbcollat."'" : '');
@@ -683,4 +683,4 @@ class CI_DB_pdo_driver extends CI_DB {
}
/* End of file pdo_driver.php */
-/* Location: ./system/database/drivers/pdo/pdo_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/pdo/pdo_driver.php */
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 14259be52..d858f01ea 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -29,7 +29,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
@@ -569,4 +569,4 @@ class CI_DB_postgre_driver extends CI_DB {
}
/* 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/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index 5021deb63..551704f83 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -29,7 +29,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
@@ -461,4 +461,4 @@ 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/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php
index fb45bee9c..d22f6a442 100644
--- a/system/database/drivers/sqlite3/sqlite3_driver.php
+++ b/system/database/drivers/sqlite3/sqlite3_driver.php
@@ -29,7 +29,7 @@
* SQLite3 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/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php
index c318f3060..8cc500f55 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_driver.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -29,7 +29,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
@@ -521,4 +521,4 @@ class CI_DB_sqlsrv_driver extends CI_DB {
}
/* End of file sqlsrv_driver.php */
-/* Location: ./system/database/drivers/sqlsrv/sqlsrv_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/sqlsrv/sqlsrv_driver.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 @@
+<?php
+
+class DB_driver_test extends CI_TestCase {
+
+ // ------------------------------------------------------------------------
+
+ public function test_initialize()
+ {
+ $config = Mock_Database_DB::config(DB_DRIVER);
+ $driver_name = current(explode('/', DB_DRIVER));
+ $driver = $this->$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/codeigniter/database/query_builder/.gitkeep b/tests/codeigniter/database/query_builder/.gitkeep
deleted file mode 100644
index e69de29bb..000000000
--- a/tests/codeigniter/database/query_builder/.gitkeep
+++ /dev/null
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..0751c9332
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/get_test.php
@@ -0,0 +1,53 @@
+<?php
+
+class Get_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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_get_simple()
+ {
+ $jobs = $this->db->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']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_get_where()
+ {
+ $job1 = $this->db->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/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php
new file mode 100644
index 000000000..53ce23c19
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/insert_test.php
@@ -0,0 +1,67 @@
+<?php
+
+class Insert_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ * @see ./mocks/schema/skeleton.php
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+
+ // Truncate the current datas
+ $this->db->truncate('job');
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_insert()
+ {
+ $job_data = array('id' => 1, 'name' => 'Grocery Sales', 'description' => 'Discount!');
+
+ // Do normal insert
+ $this->assertTrue($this->db->insert('job', $job_data));
+
+ $jobs = $this->db->get('job')->result_array();
+ $job1 = $jobs[0];
+
+ // Check the result
+ $this->assertEquals('Grocery Sales', $job1['name']);
+
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_insert_batch()
+ {
+ $job_datas = array(
+ array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'),
+ array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'),
+ );
+
+ // Do insert batch except for sqlite driver
+ if (strpos(DB_DRIVER, 'sqlite') === FALSE)
+ {
+ $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();
+
+ // Check the result
+ $this->assertEquals('Commedian', $job_2->name);
+ $this->assertEquals('Cab Driver', $job_3->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..dbf432a7c
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/select_test.php
@@ -0,0 +1,95 @@
+<?php
+
+class Select_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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_select_only_one_collumn()
+ {
+ $jobs_name = $this->db->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]));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_select_min()
+ {
+ $job_min = $this->db->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->db->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->db->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->db->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
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php
index dd5929206..f1bdb5d6f 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(array('CI_DB','active_record'), array('DB', 'active_rec'), $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;
}
-
+
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
--- a/tests/mocks/database/ci_test.sqlite
+++ b/tests/mocks/database/ci_test.sqlite
Binary files differ
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 @@
+<?php
+
+return array(
+
+ // Typical Database configuration
+ 'pdo/mysql' => 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..5196e9ad9
--- /dev/null
+++ b/tests/mocks/database/config/pdo/pgsql.php
@@ -0,0 +1,37 @@
+<?php
+
+return array(
+
+ // Typical Database configuration
+ 'pdo/pgsql' => array(
+ 'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;',
+ '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' => 'pgsql:host=localhost;port=5432;dbname=ci_test;',
+ '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..c68b4b213
--- /dev/null
+++ b/tests/mocks/database/config/pdo/sqlite.php
@@ -0,0 +1,37 @@
+<?php
+
+return array(
+
+ // Typical Database configuration
+ 'pdo/sqlite' => array(
+ '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: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',
+ 'hostname' => 'localhost',
+ 'username' => 'sqlite',
+ 'password' => 'sqlite',
+ 'database' => 'sqlite',
+ 'dbdriver' => 'pdo',
+ 'pdodriver' => 'sqlite',
+ ),
+ ),
+ ),
+); \ No newline at end of file
diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php
index 8665e208d..755ce2a3a 100644
--- a/tests/mocks/database/config/sqlite.php
+++ b/tests/mocks/database/config/sqlite.php
@@ -1,5 +1,4 @@
<?php
-$dbdriver = is_php('5.4') ? 'sqlite3' : 'sqlite';
return array(
@@ -10,7 +9,7 @@ return array(
'username' => 'sqlite',
'password' => 'sqlite',
'database' => realpath(__DIR__.'/..').'/ci_test.sqlite',
- 'dbdriver' => $dbdriver,
+ 'dbdriver' => 'sqlite3',
),
// Database configuration with failover
@@ -20,15 +19,15 @@ return array(
'username' => 'sqlite',
'password' => 'sqlite',
'database' => '../not_exists.sqlite',
- 'dbdriver' => $dbdriver,
+ 'dbdriver' => 'sqlite3',
'failover' => array(
array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'sqlite',
'password' => 'sqlite',
- 'database' => realpath(__DIR__.'/..').'/ci_testf.sqlite',
- 'dbdriver' => $dbdriver,
+ 'database' => realpath(__DIR__.'/..').'/ci_test.sqlite',
+ 'dbdriver' => 'sqlite3',
),
),
),
diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php
index 43a0d391f..59028ed9c 100644
--- a/tests/mocks/database/db.php
+++ b/tests/mocks/database/db.php
@@ -45,19 +45,18 @@ 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);
+ if ($dsnstring) $other_params['dsn'] = $dsnstring;
+ 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..cb1820277
--- /dev/null
+++ b/tests/mocks/database/db/driver.php
@@ -0,0 +1,36 @@
+<?php
+
+class Mock_Database_DB_Driver extends CI_DB_driver {
+
+ /**
+ * @var object The actual Driver
+ */
+ protected $ci_db_driver;
+
+ /**
+ * Instantiate the database driver
+ *
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
+ */
+ public function __construct($driver_class, $config = array())
+ {
+ if (is_string($driver_class)) $this->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 Mock_Database_DB_QueryBuilder {} \ 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 @@
+<?php
+
+if ( ! class_exists('CI_DB_query_builder'))
+{
+ class Mock_Database_DB_QueryBuilder extends CI_DB_active_record {}
+}
+else
+{
+ class Mock_Database_DB_QueryBuilder extends CI_DB_query_builder {}
+}
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 @@
+<?php
+
+class Mock_Database_Drivers_Mysql extends Mock_Database_DB_Driver {
+
+ /**
+ * Instantiate the database driver
+ *
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
+ */
+ public function __construct($config = array())
+ {
+ parent::__construct('CI_DB_mysql_driver', $config);
+ }
+} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/pdo.php b/tests/mocks/database/drivers/pdo.php
new file mode 100644
index 000000000..590e19552
--- /dev/null
+++ b/tests/mocks/database/drivers/pdo.php
@@ -0,0 +1,16 @@
+<?php
+
+class Mock_Database_Drivers_PDO extends Mock_Database_DB_Driver {
+
+ /**
+ * Instantiate the database driver
+ *
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
+ */
+ public function __construct($config = array())
+ {
+ parent::__construct('CI_DB_pdo_driver', $config);
+ }
+} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/postgre.php b/tests/mocks/database/drivers/postgre.php
new file mode 100644
index 000000000..0df905963
--- /dev/null
+++ b/tests/mocks/database/drivers/postgre.php
@@ -0,0 +1,16 @@
+<?php
+
+class Mock_Database_Drivers_Postgre extends Mock_Database_DB_Driver {
+
+ /**
+ * Instantiate the database driver
+ *
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
+ */
+ public function __construct($config = array())
+ {
+ parent::__construct('CI_DB_postgre_driver', $config);
+ }
+} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/sqlite.php b/tests/mocks/database/drivers/sqlite.php
new file mode 100644
index 000000000..76a182cbf
--- /dev/null
+++ b/tests/mocks/database/drivers/sqlite.php
@@ -0,0 +1,16 @@
+<?php
+
+class Mock_Database_Drivers_Sqlite extends Mock_Database_DB_Driver {
+
+ /**
+ * Instantiate the database driver
+ *
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
+ */
+ public function __construct($config = array())
+ {
+ parent::__construct('CI_DB_sqlite3_driver', $config);
+ }
+} \ 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
--- a/tests/mocks/database/schema/.gitkeep
+++ /dev/null
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
new file mode 100644
index 000000000..a3d5bac65
--- /dev/null
+++ b/tests/mocks/database/schema/skeleton.php
@@ -0,0 +1,98 @@
+<?php
+
+class Mock_Database_Schema_Skeleton {
+
+ /**
+ * @var object Database Holder
+ */
+ public static $db;
+
+ /**
+ * @var object Forge Holder
+ */
+ public static $forge;
+
+ /**
+ * @var object Driver Holder
+ */
+ public static $driver;
+
+ /**
+ * Initialize both database and forge components
+ */
+ public static function init($driver)
+ {
+ if (empty(static::$db) && empty(static::$forge))
+ {
+ $config = Mock_Database_DB::config($driver);
+ $connection = new Mock_Database_DB($config);
+ $db = Mock_Database_DB::DB($connection->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()
+ {
+ // Job Table
+ static::$forge->add_field(array(
+ 'id' => array(
+ 'type' => 'INTEGER',
+ 'constraint' => 3,
+ ),
+ 'name' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40,
+ ),
+ 'description' => array(
+ 'type' => 'TEXT',
+ ),
+ ));
+ static::$forge->add_key('id', TRUE);
+ static::$forge->create_table('job', (strpos(static::$driver, 'pgsql') === FALSE));
+ }
+
+ /**
+ * Create the dummy datas
+ *
+ * @return void
+ */
+ public static function create_data()
+ {
+ // 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)
+ {
+ static::$db->truncate($table);
+
+ foreach ($dummy_data as $single_dummy_data)
+ {
+ static::$db->insert($table, $single_dummy_data);
+ }
+ }
+ }
+} \ No newline at end of file
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 @@
<directory suffix=".php">PROJECT_BASE.'tests'</directory>
<directory suffix=".php">'../../system/core/CodeIgniter.php'</directory>
</blacklist>
- <whitelist>
- <!--
- <directory suffix=".php">'../system/core'</directory>
- -->
- </whitelist>
</filters>
</phpunit> \ 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..69eece24f
--- /dev/null
+++ b/tests/travis/pdo/mysql.phpunit.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit
+ bootstrap="../../Bootstrap.php"
+ colors="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnError="false"
+ stopOnFailure="false"
+ stopOnIncomplete="false"
+ stopOnSkipped="false">
+ <php>
+ <const name="DB_DRIVER" value="pdo/mysql"/>
+ </php>
+ <testsuites>
+ <testsuite name="CodeIgniter Core Test Suite">
+ <file>../../codeigniter/Setup_test.php</file>
+ <directory suffix="test.php">../../codeigniter/core</directory>
+ <directory suffix="test.php">../../codeigniter/helpers</directory>
+ <directory suffix="test.php">../../codeigniter/libraries</directory>
+ <directory suffix="test.php">../../codeigniter/database</directory>
+ </testsuite>
+ </testsuites>
+ <filters>
+ <blacklist>
+ <directory suffix=".php">PEAR_INSTALL_DIR</directory>
+ <directory suffix=".php">PHP_LIBDIR</directory>
+ <directory suffix=".php">PROJECT_BASE.'tests'</directory>
+ <directory suffix=".php">'../../../system/core/CodeIgniter.php'</directory>
+ </blacklist>
+ </filters>
+</phpunit> \ 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..e68c3e028
--- /dev/null
+++ b/tests/travis/pdo/pgsql.phpunit.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit
+ bootstrap="../../Bootstrap.php"
+ colors="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnError="false"
+ stopOnFailure="false"
+ stopOnIncomplete="false"
+ stopOnSkipped="false">
+ <php>
+ <const name="DB_DRIVER" value="pdo/pgsql"/>
+ </php>
+ <testsuites>
+ <testsuite name="CodeIgniter Core Test Suite">
+ <file>../../codeigniter/Setup_test.php</file>
+ <directory suffix="test.php">../../codeigniter/core</directory>
+ <directory suffix="test.php">../../codeigniter/helpers</directory>
+ <directory suffix="test.php">../../codeigniter/libraries</directory>
+ <directory suffix="test.php">../../codeigniter/database</directory>
+ </testsuite>
+ </testsuites>
+ <filters>
+ <blacklist>
+ <directory suffix=".php">PEAR_INSTALL_DIR</directory>
+ <directory suffix=".php">PHP_LIBDIR</directory>
+ <directory suffix=".php">PROJECT_BASE.'tests'</directory>
+ <directory suffix=".php">'../../../system/core/CodeIgniter.php'</directory>
+ </blacklist>
+ </filters>
+</phpunit> \ 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..1871f6221
--- /dev/null
+++ b/tests/travis/pdo/sqlite.phpunit.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit
+ bootstrap="../../Bootstrap.php"
+ colors="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnError="false"
+ stopOnFailure="false"
+ stopOnIncomplete="false"
+ stopOnSkipped="false">
+ <php>
+ <const name="DB_DRIVER" value="pdo/sqlite"/>
+ </php>
+ <testsuites>
+ <testsuite name="CodeIgniter Core Test Suite">
+ <file>../../codeigniter/Setup_test.php</file>
+ <directory suffix="test.php">../../codeigniter/core</directory>
+ <directory suffix="test.php">../../codeigniter/helpers</directory>
+ <directory suffix="test.php">../../codeigniter/libraries</directory>
+ <directory suffix="test.php">../../codeigniter/database</directory>
+ </testsuite>
+ </testsuites>
+ <filters>
+ <blacklist>
+ <directory suffix=".php">PEAR_INSTALL_DIR</directory>
+ <directory suffix=".php">PHP_LIBDIR</directory>
+ <directory suffix=".php">PROJECT_BASE.'tests'</directory>
+ <directory suffix=".php">'../../../system/core/CodeIgniter.php'</directory>
+ </blacklist>
+ </filters>
+</phpunit> \ 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 @@
<directory suffix=".php">PROJECT_BASE.'tests'</directory>
<directory suffix=".php">'../../system/core/CodeIgniter.php'</directory>
</blacklist>
- <whitelist>
- <!--
- <directory suffix=".php">'../system/core'</directory>
- -->
- </whitelist>
</filters>
</phpunit> \ 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 @@
<directory suffix=".php">PROJECT_BASE.'tests'</directory>
<directory suffix=".php">'../../system/core/CodeIgniter.php'</directory>
</blacklist>
- <whitelist>
- <!--
- <directory suffix=".php">'../system/core'</directory>
- -->
- </whitelist>
</filters>
</phpunit> \ No newline at end of file
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index ee530e6fd..03a020a45 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -55,8 +55,11 @@ Release Date: Not Released
- Database
- - Added the ability to insert objects with insert_batch() in :doc:`Active Record <database/active_record>`.
- - Added new :doc:`Active Record <database/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 <database/query_builder>` methods that return
+ - Added the ability to insert objects with insert_batch() in :doc:`Query Builder <database/query_builder>`.
+ - Added new :doc:`Query Builder <database/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().
- Adding $escape parameter to the order_by function, this enables ordering by custom fields.
@@ -201,6 +204,7 @@ Bug fixes for 3.0
- Fixed a bug (#23, #1238) - delete_all() in the `Database Caching Library <database/caching>` used to delete .htaccess and index.html files, which is a potential security risk.
- Fixed a bug in :doc:`Trackback Library <libraries/trackback>` 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.
+- 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 <libraries/zip>` 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.
- Fixed a bug in MSSQL and SQLSrv's _truncate() where the TABLE keyword was missing.
diff --git a/user_guide_src/source/database/configuration.rst b/user_guide_src/source/database/configuration.rst
index 3f3bae336..7a19c840f 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 <active_record>` is globally enabled or
-disabled by setting the $active_record variable in the database
+The :doc:`Query Builder Class <query_builder>` 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, postgre, 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 <active_record>` queries. This permits multiple CodeIgniter installations
+ `Query Builder <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 fb4524116..5822ca62c 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 <active_record>` gives you a simplified
+The :doc:`Query Builder Pattern <query_builder>` 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 <active_record>` class contains a full
+table. The :doc:`Query Builder <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 <queries>
Generating Query Results <results>
Query Helper Functions <helpers>
- Active Record Class <active_record>
+ Query Builder Class <query_builder>
Transactions <transactions>
Table MetaData <table_data>
Field MetaData <fields>
diff --git a/user_guide_src/source/database/queries.rst b/user_guide_src/source/database/queries.rst
index 15a73614a..d23efecb3 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/active_record.rst b/user_guide_src/source/database/query_builder.rst
index e328c11e2..54e8df6b5 100644
--- a/user_guide_src/source/database/active_record.rst
+++ b/user_guide_src/source/database/query_builder.rst
@@ -1,15 +1,15 @@
###################
-Active Record Class
+Query Builder 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 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 Active Record features
+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
@@ -67,8 +67,8 @@ Example::
// 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()`)::
+The second parameter enables you to set whether or not the query builder query
+will be reset (by default it will be&mdash;just like `$this->db->get()`)::
echo $this->db->limit(10,20)->get_compiled_select('mytable', FALSE);
// Produces string: SELECT * FROM mytable LIMIT 20, 10
@@ -512,7 +512,7 @@ $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
+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
@@ -636,7 +636,7 @@ Example::
// 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
+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);
@@ -928,12 +928,12 @@ multiple functions. Consider this example::
.. _ar-caching:
*********************
-Active Record Caching
+Query Builder Caching
*********************
-While not "true" caching, Active Record enables you to save (or "cache")
+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 Active Record call is completed,
+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.
@@ -944,7 +944,7 @@ There are three Caching functions available:
$this->db->start_cache()
========================
-This function must be called to begin caching. All Active Record queries
+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.
@@ -956,7 +956,7 @@ This function can be called to stop caching.
$this->db->flush_cache()
========================
-This function deletes all items from the Active Record cache.
+This function deletes all items from the Query Builder cache.
Here's a usage example::
@@ -983,12 +983,12 @@ Here's a usage example::
$this->db->reset_query()
========================
-Resetting Active Record allows you to start fresh with your query without
+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 `Active Record Caching`_.
+cached using `Query Builder Caching`_.
-This is useful in situations where you are using Active Record to generate SQL
+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::
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/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst
index 4c594ab17..e434e8d45 100644
--- a/user_guide_src/source/installation/upgrade_300.rst
+++ b/user_guide_src/source/installation/upgrade_300.rst
@@ -31,3 +31,13 @@ Step 3: Remove $autoload['core'] from your config/autoload.php
Use of the `$autoload['core']` config array has been deprecated as of CodeIgniter 1.4.1 and is now removed.
Move any entries that you might have listed there to `$autoload['libraries']` instead.
+
+Step 4: Update your config/database.php
+=======================================
+
+Due to 3.0.0's renaming of Active Record to Query Builder, inside your _config/database.php_, you will
+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
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
----------------