summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorJonathon Hill <jhill@brandmovers.com>2012-11-12 14:51:41 +0100
committerJonathon Hill <jhill@brandmovers.com>2012-11-12 14:51:41 +0100
commit3978fc33d82dd7f778d1adbf30744f4dfac41c25 (patch)
treef32be1ae610f0cfeff65c35abecd14e8ea5cadc6 /system
parent275cf274860c6ed181d50b398efd3a21d7ba9135 (diff)
parenta9ab46d7a031bda304eb9b6658ffaf693b8d9bcb (diff)
Merge remote-tracking branch 'upstream/develop' into develop
Conflicts: user_guide_src/source/changelog.rst Signed-off-by: Jonathon Hill <jhill@brandmovers.com>
Diffstat (limited to 'system')
-rw-r--r--system/core/Benchmark.php3
-rw-r--r--system/core/CodeIgniter.php96
-rw-r--r--system/core/Common.php52
-rw-r--r--system/core/Config.php3
-rw-r--r--system/core/Controller.php3
-rw-r--r--system/core/Exceptions.php3
-rw-r--r--system/core/Hooks.php3
-rw-r--r--system/core/Input.php54
-rw-r--r--system/core/Lang.php3
-rw-r--r--system/core/Loader.php111
-rw-r--r--system/core/Log.php (renamed from system/libraries/Log.php)5
-rw-r--r--system/core/Model.php3
-rw-r--r--system/core/Output.php3
-rw-r--r--system/core/Router.php144
-rw-r--r--system/core/Security.php3
-rw-r--r--system/core/URI.php128
-rw-r--r--system/core/Utf8.php3
-rw-r--r--system/database/DB.php46
-rw-r--r--system/database/DB_cache.php31
-rw-r--r--system/database/DB_driver.php312
-rw-r--r--system/database/DB_forge.php706
-rw-r--r--system/database/DB_query_builder.php486
-rw-r--r--system/database/DB_result.php203
-rw-r--r--system/database/DB_utility.php77
-rw-r--r--system/database/drivers/cubrid/cubrid_driver.php67
-rw-r--r--system/database/drivers/cubrid/cubrid_forge.php253
-rw-r--r--system/database/drivers/cubrid/cubrid_result.php9
-rw-r--r--system/database/drivers/cubrid/cubrid_utility.php5
-rw-r--r--system/database/drivers/ibase/ibase_driver.php62
-rw-r--r--system/database/drivers/ibase/ibase_forge.php214
-rw-r--r--system/database/drivers/ibase/ibase_result.php5
-rw-r--r--system/database/drivers/ibase/ibase_utility.php7
-rw-r--r--system/database/drivers/mssql/mssql_driver.php84
-rw-r--r--system/database/drivers/mssql/mssql_forge.php164
-rw-r--r--system/database/drivers/mssql/mssql_result.php9
-rw-r--r--system/database/drivers/mssql/mssql_utility.php20
-rw-r--r--system/database/drivers/mysql/mysql_driver.php84
-rw-r--r--system/database/drivers/mysql/mysql_forge.php231
-rw-r--r--system/database/drivers/mysql/mysql_result.php13
-rw-r--r--system/database/drivers/mysql/mysql_utility.php26
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php77
-rw-r--r--system/database/drivers/mysqli/mysqli_forge.php231
-rw-r--r--system/database/drivers/mysqli/mysqli_result.php9
-rw-r--r--system/database/drivers/mysqli/mysqli_utility.php26
-rw-r--r--system/database/drivers/oci8/oci8_driver.php131
-rw-r--r--system/database/drivers/oci8/oci8_forge.php151
-rw-r--r--system/database/drivers/oci8/oci8_result.php37
-rw-r--r--system/database/drivers/oci8/oci8_utility.php14
-rw-r--r--system/database/drivers/odbc/odbc_driver.php61
-rw-r--r--system/database/drivers/odbc/odbc_forge.php130
-rw-r--r--system/database/drivers/odbc/odbc_result.php17
-rw-r--r--system/database/drivers/odbc/odbc_utility.php11
-rw-r--r--system/database/drivers/pdo/pdo_driver.php62
-rw-r--r--system/database/drivers/pdo/pdo_forge.php129
-rw-r--r--system/database/drivers/pdo/pdo_result.php7
-rw-r--r--system/database/drivers/pdo/pdo_utility.php11
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_4d_driver.php36
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_4d_forge.php209
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php35
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php212
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php70
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php136
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php44
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php228
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php40
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php146
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_informix_driver.php34
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_informix_forge.php155
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php47
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php218
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_oci_driver.php62
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_oci_forge.php133
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php54
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php62
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php49
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php194
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php40
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php229
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php70
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php136
-rw-r--r--system/database/drivers/postgre/postgre_driver.php65
-rw-r--r--system/database/drivers/postgre/postgre_forge.php254
-rw-r--r--system/database/drivers/postgre/postgre_result.php9
-rw-r--r--system/database/drivers/postgre/postgre_utility.php22
-rw-r--r--system/database/drivers/sqlite/sqlite_driver.php42
-rw-r--r--system/database/drivers/sqlite/sqlite_forge.php195
-rw-r--r--system/database/drivers/sqlite/sqlite_result.php9
-rw-r--r--system/database/drivers/sqlite/sqlite_utility.php11
-rw-r--r--system/database/drivers/sqlite3/sqlite3_driver.php40
-rw-r--r--system/database/drivers/sqlite3/sqlite3_forge.php205
-rw-r--r--system/database/drivers/sqlite3/sqlite3_result.php16
-rw-r--r--system/database/drivers/sqlite3/sqlite3_utility.php11
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_driver.php90
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_forge.php164
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_result.php5
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_utility.php22
-rw-r--r--system/helpers/array_helper.php3
-rw-r--r--system/helpers/captcha_helper.php3
-rw-r--r--system/helpers/cookie_helper.php3
-rw-r--r--system/helpers/date_helper.php20
-rw-r--r--system/helpers/directory_helper.php14
-rw-r--r--system/helpers/download_helper.php3
-rw-r--r--system/helpers/email_helper.php15
-rw-r--r--system/helpers/file_helper.php37
-rw-r--r--system/helpers/form_helper.php87
-rw-r--r--system/helpers/html_helper.php9
-rw-r--r--system/helpers/inflector_helper.php24
-rw-r--r--system/helpers/language_helper.php3
-rw-r--r--system/helpers/number_helper.php3
-rw-r--r--system/helpers/path_helper.php3
-rw-r--r--system/helpers/security_helper.php3
-rw-r--r--system/helpers/smiley_helper.php8
-rw-r--r--system/helpers/string_helper.php10
-rw-r--r--system/helpers/text_helper.php3
-rw-r--r--system/helpers/typography_helper.php3
-rw-r--r--system/helpers/url_helper.php20
-rw-r--r--system/helpers/xml_helper.php3
-rw-r--r--system/language/english/calendar_lang.php1
-rw-r--r--system/language/english/date_lang.php1
-rw-r--r--system/language/english/db_lang.php5
-rw-r--r--system/language/english/email_lang.php1
-rw-r--r--system/language/english/form_validation_lang.php1
-rw-r--r--system/language/english/ftp_lang.php1
-rw-r--r--system/language/english/imglib_lang.php1
-rw-r--r--system/language/english/migration_lang.php2
-rw-r--r--system/language/english/number_lang.php1
-rw-r--r--system/language/english/profiler_lang.php1
-rw-r--r--system/language/english/unit_test_lang.php1
-rw-r--r--system/language/english/upload_lang.php1
-rw-r--r--system/libraries/Cache/Cache.php5
-rw-r--r--system/libraries/Cache/drivers/Cache_apc.php5
-rw-r--r--system/libraries/Cache/drivers/Cache_dummy.php5
-rw-r--r--system/libraries/Cache/drivers/Cache_file.php5
-rw-r--r--system/libraries/Cache/drivers/Cache_memcached.php5
-rw-r--r--system/libraries/Cache/drivers/Cache_redis.php5
-rw-r--r--system/libraries/Cache/drivers/Cache_wincache.php5
-rw-r--r--system/libraries/Calendar.php3
-rw-r--r--system/libraries/Cart.php20
-rw-r--r--system/libraries/Driver.php3
-rw-r--r--system/libraries/Email.php343
-rw-r--r--system/libraries/Encrypt.php3
-rw-r--r--system/libraries/Form_validation.php24
-rw-r--r--system/libraries/Ftp.php106
-rw-r--r--system/libraries/Image_lib.php17
-rw-r--r--system/libraries/Javascript.php20
-rw-r--r--system/libraries/Migration.php3
-rw-r--r--system/libraries/Pagination.php298
-rw-r--r--system/libraries/Parser.php3
-rw-r--r--system/libraries/Profiler.php34
-rwxr-xr-xsystem/libraries/Session/Session.php36
-rwxr-xr-xsystem/libraries/Session/drivers/Session_cookie.php41
-rwxr-xr-xsystem/libraries/Session/drivers/Session_native.php5
-rw-r--r--system/libraries/Table.php3
-rw-r--r--system/libraries/Trackback.php44
-rw-r--r--system/libraries/Typography.php3
-rw-r--r--system/libraries/Unit_test.php85
-rw-r--r--system/libraries/Upload.php243
-rw-r--r--system/libraries/User_agent.php3
-rwxr-xr-xsystem/libraries/Xmlrpc.php372
-rw-r--r--system/libraries/Xmlrpcs.php3
-rw-r--r--system/libraries/Zip.php3
-rw-r--r--system/libraries/javascript/Jquery.php97
162 files changed, 7927 insertions, 2854 deletions
diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php
index f94db2721..e80ee54dd 100644
--- a/system/core/Benchmark.php
+++ b/system/core/Benchmark.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Benchmark Class
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index f27086386..89081b572 100644
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* System Initialization File
@@ -255,23 +256,22 @@
* Security check
* ------------------------------------------------------
*
- * None of the functions in the app controller or the
+ * None of the methods in the app controller or the
* loader class can be called via the URI, nor can
- * controller functions that begin with an underscore
+ * controller functions that begin with an underscore.
*/
$class = $RTR->fetch_class();
$method = $RTR->fetch_method();
- if ( ! class_exists($class)
- OR strpos($method, '_') === 0
- OR in_array(strtolower($method), array_map('strtolower', get_class_methods('CI_Controller')))
- )
+ if ( ! class_exists($class) OR $method[0] === '_' OR method_exists('CI_Controller', $method))
{
if ( ! empty($RTR->routes['404_override']))
{
- $x = explode('/', $RTR->routes['404_override'], 2);
- $class = $x[0];
- $method = isset($x[1]) ? $x[1] : 'index';
+ if (sscanf($RTR->routes['404_override'], '%[^/]/%s', $class, $method) !== 2)
+ {
+ $method = 'index';
+ }
+
if ( ! class_exists($class))
{
if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
@@ -288,6 +288,42 @@
}
}
+ if (method_exists($class, '_remap'))
+ {
+ $params = array($method, array_slice($URI->rsegments, 2));
+ $method = '_remap';
+ }
+ else
+ {
+ // WARNING: It appears that there are issues with is_callable() even in PHP 5.2!
+ // Furthermore, there are bug reports and feature/change requests related to it
+ // that make it unreliable to use in this context. Please, DO NOT change this
+ // work-around until a better alternative is available.
+ if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($class)), TRUE))
+ {
+ if (empty($RTR->routes['404_override']))
+ {
+ show_404($class.'/'.$method);
+ }
+ elseif (sscanf($RTR->routes['404_override'], '%[^/]/%s', $class, $method) !== 2)
+ {
+ $method = 'index';
+ }
+
+ if ( ! class_exists($class))
+ {
+ if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
+ {
+ show_404($class.'/'.$method);
+ }
+
+ include_once(APPPATH.'controllers/'.$class.'.php');
+ }
+ }
+
+ $params = array_slice($URI->rsegments, 2);
+ }
+
/*
* ------------------------------------------------------
* Is there a "pre_controller" hook?
@@ -317,45 +353,7 @@
* Call the requested method
* ------------------------------------------------------
*/
- // Is there a "remap" function? If so, we call it instead
- if (method_exists($CI, '_remap'))
- {
- $CI->_remap($method, array_slice($URI->rsegments, 2));
- }
- else
- {
- // is_callable() returns TRUE on some versions of PHP 5 for private and protected
- // methods, so we'll use this workaround for consistent behavior
- if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
- {
- // Check and see if we are using a 404 override and use it.
- if ( ! empty($RTR->routes['404_override']))
- {
- $x = explode('/', $RTR->routes['404_override'], 2);
- $class = $x[0];
- $method = isset($x[1]) ? $x[1] : 'index';
- if ( ! class_exists($class))
- {
- if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
- {
- show_404($class.'/'.$method);
- }
-
- include_once(APPPATH.'controllers/'.$class.'.php');
- unset($CI);
- $CI = new $class();
- }
- }
- else
- {
- show_404($class.'/'.$method);
- }
- }
-
- // Call the requested method.
- // Any URI segments present (besides the class/function) will be passed to the method for convenience
- call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
- }
+ call_user_func_array(array(&$CI, $method), $params);
// Mark a benchmark end point
$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
diff --git a/system/core/Common.php b/system/core/Common.php
index 2dd31d3e9..7feb16bfd 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Common Functions
@@ -419,7 +420,7 @@ if ( ! function_exists('log_message'))
return;
}
- $_log =& load_class('Log');
+ $_log =& load_class('Log', 'core');
$_log->write_log($level, $message, $php_error);
}
}
@@ -650,5 +651,52 @@ if ( ! function_exists('_stringify_attributes'))
}
}
+// ------------------------------------------------------------------------
+
+if ( ! function_exists('function_usable'))
+{
+ /**
+ * Function usable
+ *
+ * Executes a function_exists() check, and if the Suhosin PHP
+ * extension is loaded - checks whether the function that is
+ * checked might be disabled in there as well.
+ *
+ * This is useful as function_exists() will return FALSE for
+ * functions disabled via the *disable_functions* php.ini
+ * setting, but not for *suhosin.executor.func.blacklist* and
+ * *suhosin.executor.disable_eval*. These settings will just
+ * terminate script execution if a disabled function is executed.
+ *
+ * @link http://www.hardened-php.net/suhosin/
+ * @param string $function_name Function to check for
+ * @return bool TRUE if the function exists and is safe to call,
+ * FALSE otherwise.
+ */
+ function function_usable($function_name)
+ {
+ static $_suhosin_func_blacklist;
+
+ if (function_exists($function_name))
+ {
+ if ( ! isset($_suhosin_func_blacklist))
+ {
+ $_suhosin_func_blacklist = extension_loaded('suhosin')
+ ? array()
+ : explode(',', trim(@ini_get('suhosin.executor.func.blacklist')));
+
+ if ( ! in_array('eval', $_suhosin_func_blacklist, TRUE) && @ini_get('suhosin.executor.disable_eval'))
+ {
+ $_suhosin_func_blacklist[] = 'eval';
+ }
+ }
+
+ return in_array($function_name, $_suhosin_func_blacklist, TRUE);
+ }
+
+ return FALSE;
+ }
+}
+
/* End of file Common.php */
/* Location: ./system/core/Common.php */ \ No newline at end of file
diff --git a/system/core/Config.php b/system/core/Config.php
index 642cee798..8250b5b1a 100644
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Config Class
diff --git a/system/core/Controller.php b/system/core/Controller.php
index 8c2ba893e..ee6fec8d5 100644
--- a/system/core/Controller.php
+++ b/system/core/Controller.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Application Controller Class
diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php
index 556257729..ced65ece4 100644
--- a/system/core/Exceptions.php
+++ b/system/core/Exceptions.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Exceptions Class
diff --git a/system/core/Hooks.php b/system/core/Hooks.php
index d60e9ac5d..3c28ec9ba 100644
--- a/system/core/Hooks.php
+++ b/system/core/Hooks.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Hooks Class
diff --git a/system/core/Input.php b/system/core/Input.php
index f6213c34e..adc5f7ac0 100644
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Input Class
@@ -99,6 +100,16 @@ class CI_Input {
protected $headers = array();
/**
+ * Input stream data
+ *
+ * Parsed from php://input at runtime
+ *
+ * @see CI_Input::input_stream()
+ * @var array
+ */
+ protected $_input_stream = NULL;
+
+ /**
* Class constructor
*
* Determines whether to globally enable the XSS processing
@@ -256,6 +267,37 @@ class CI_Input {
// ------------------------------------------------------------------------
/**
+ * Fetch an item from the php://input stream
+ *
+ * Useful when you need to access PUT, DELETE or PATCH request data.
+ *
+ * @param string $index Index for item to be fetched
+ * @param bool $xss_clean Whether to apply XSS filtering
+ * @return mixed
+ */
+ public function input_stream($index = '', $xss_clean = FALSE)
+ {
+ // The input stream can only be read once, so we'll need to check
+ // if we have already done that first.
+ if (is_array($this->_input_stream))
+ {
+ return $this->_fetch_from_array($this->_input_stream, $index, $xss_clean);
+ }
+
+ // Parse the input stream in our cache var
+ parse_str(file_get_contents('php://input'), $this->_input_stream);
+ if ( ! is_array($this->_input_stream))
+ {
+ $this->_input_stream = array();
+ return NULL;
+ }
+
+ return $this->_fetch_from_array($this->_input_stream, $index, $xss_clean);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
* Set cookie
*
* Accepts an arbitrary number of parameters (up to 7) or an associative
@@ -355,11 +397,7 @@ class CI_Input {
// Some proxies typically list the whole chain of IP
// addresses through which the client has reached us.
// e.g. client_ip, proxy_ip1, proxy_ip2, etc.
- if (strpos($spoof, ',') !== FALSE)
- {
- $spoof = explode(',', $spoof, 2);
- $spoof = $spoof[0];
- }
+ sscanf($spoof, '%[^,]', $spoof);
if ( ! $this->valid_ip($spoof))
{
@@ -429,7 +467,7 @@ class CI_Input {
}
// Split the netmask length off the network address
- list($netaddr, $masklen) = explode('/', $proxy_ips[$i], 2);
+ sscanf($proxy_ips[$i], '%[^/]/%d', $netaddr, $masklen);
// Again, an IPv6 address is most likely in a compressed form
if ($separator === ':')
@@ -694,7 +732,7 @@ class CI_Input {
*/
protected function _clean_input_keys($str)
{
- if ( ! preg_match('/^[a-z0-9:_\/-]+$/i', $str))
+ if ( ! preg_match('/^[a-z0-9:_\/|-]+$/i', $str))
{
set_status_header(503);
exit('Disallowed Key Characters.');
diff --git a/system/core/Lang.php b/system/core/Lang.php
index 251cf6ef1..896385134 100644
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Language Class
diff --git a/system/core/Loader.php b/system/core/Loader.php
index db56ab3ae..1e6eafe8a 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Loader Class
@@ -129,7 +130,7 @@ class CI_Loader {
/**
* Class constructor
*
- * Sets component load paths gets the initial output buffering level.
+ * Sets component load paths, gets the initial output buffering level.
*
* @return void
*/
@@ -147,21 +148,18 @@ class CI_Loader {
// --------------------------------------------------------------------
/**
- * Initialize the Loader
+ * Initializer
*
- * @used-by CI_Controller
+ * @todo Figure out a way to move this to the constructor
+ * without breaking *package_path*() methods.
* @uses CI_Loader::_ci_autoloader()
- * @return object $this
+ * @used-by CI_Controller::__construct()
+ * @return void
*/
public function initialize()
{
- $this->_ci_classes = array();
- $this->_ci_loaded_files = array();
- $this->_ci_models = array();
$this->_base_classes =& is_loaded();
-
$this->_ci_autoloader();
- return $this;
}
// --------------------------------------------------------------------
@@ -354,26 +352,30 @@ class CI_Loader {
/**
* Load the Database Utilities Class
*
- * @return void
+ * @param object $db Database object
+ * @param bool $return Whether to return the DB Forge class object or not
+ * @return void|object
*/
- public function dbutil()
+ public function dbutil($db = NULL, $return = FALSE)
{
- if ( ! class_exists('CI_DB'))
- {
- $this->database();
- }
-
$CI =& get_instance();
- // for backwards compatibility, load dbforge so we can extend dbutils off it
- // this use is deprecated and strongly discouraged
- $CI->load->dbforge();
+ if ( ! is_object($db) OR ! ($db instanceof CI_DB))
+ {
+ class_exists('CI_DB', FALSE) OR $this->database();
+ $db =& $CI->db;
+ }
require_once(BASEPATH.'database/DB_utility.php');
- require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility.php');
- $class = 'CI_DB_'.$CI->db->dbdriver.'_utility';
+ require_once(BASEPATH.'database/drivers/'.$db->dbdriver.'/'.$db->dbdriver.'_utility.php');
+ $class = 'CI_DB_'.$db->dbdriver.'_utility';
- $CI->dbutil = new $class();
+ if ($return === TRUE)
+ {
+ return new $class($db);
+ }
+
+ $CI->dbutil = new $class($db);
}
// --------------------------------------------------------------------
@@ -381,22 +383,42 @@ class CI_Loader {
/**
* Load the Database Forge Class
*
- * @return void
+ * @param object $db Database object
+ * @param bool $return Whether to return the DB Forge class object or not
+ * @return void|object
*/
- public function dbforge()
+ public function dbforge($db = NULL, $return = FALSE)
{
- if ( ! class_exists('CI_DB'))
+ $CI =& get_instance();
+ if ( ! is_object($db) OR ! ($db instanceof CI_DB))
{
- $this->database();
+ class_exists('CI_DB', FALSE) OR $this->database();
+ $db =& $CI->db;
}
- $CI =& get_instance();
-
require_once(BASEPATH.'database/DB_forge.php');
- require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge.php');
- $class = 'CI_DB_'.$CI->db->dbdriver.'_forge';
+ require_once(BASEPATH.'database/drivers/'.$db->dbdriver.'/'.$db->dbdriver.'_forge.php');
- $CI->dbforge = new $class();
+ if ( ! empty($db->subdriver))
+ {
+ $driver_path = BASEPATH.'database/drivers/'.$db->dbdriver.'/subdrivers/'.$db->dbdriver.'_'.$db->subdriver.'_forge.php';
+ if (file_exists($driver_path))
+ {
+ require_once($driver_path);
+ $class = 'CI_DB_'.$db->dbdriver.'_'.$db->subdriver.'_forge';
+ }
+ }
+ else
+ {
+ $class = 'CI_DB_'.$db->dbdriver.'_forge';
+ }
+
+ if ($return === TRUE)
+ {
+ return new $class($db);
+ }
+
+ $CI->dbforge = new $class($db);
}
// --------------------------------------------------------------------
@@ -510,27 +532,34 @@ class CI_Loader {
continue;
}
- $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.'.php';
-
// Is this a helper extension request?
- if (file_exists($ext_helper))
+ $ext_helper = config_item('subclass_prefix').$helper;
+ $ext_loaded = FALSE;
+ foreach ($this->_ci_helper_paths as $path)
{
- $base_helper = BASEPATH.'helpers/'.$helper.'.php';
+ if (file_exists($path.'helpers/'.$ext_helper.'.php'))
+ {
+ include_once($path.'helpers/'.$ext_helper.'.php');
+ $ext_loaded = TRUE;
+ }
+ }
+ // If we have loaded extensions - check if the base one is here
+ if ($ext_loaded === TRUE)
+ {
+ $base_helper = BASEPATH.'helpers/'.$helper.'.php';
if ( ! file_exists($base_helper))
{
show_error('Unable to load the requested file: helpers/'.$helper.'.php');
}
- include_once($ext_helper);
include_once($base_helper);
-
$this->_ci_helpers[$helper] = TRUE;
log_message('debug', 'Helper loaded: '.$helper);
continue;
}
- // Try to load the helper
+ // No extensions found ... try loading regular helpers and/or overrides
foreach ($this->_ci_helper_paths as $path)
{
if (file_exists($path.'helpers/'.$helper.'.php'))
@@ -849,7 +878,9 @@ class CI_Loader {
// If the PHP installation does not support short tags we'll
// do a little string replacement, changing the short tags
// to standard PHP echo statements.
- if ( ! is_php('5.4') && (bool) @ini_get('short_open_tag') === FALSE && config_item('rewrite_short_tags') === TRUE)
+ if ( ! is_php('5.4') && (bool) @ini_get('short_open_tag') === FALSE
+ && config_item('rewrite_short_tags') === TRUE && function_usable('eval')
+ )
{
echo eval('?>'.preg_replace('/;*\s*\?>/', '; ?>', str_replace('<?=', '<?php echo ', file_get_contents($_ci_path))));
}
diff --git a/system/libraries/Log.php b/system/core/Log.php
index baac80121..e66270840 100644
--- a/system/libraries/Log.php
+++ b/system/core/Log.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Logging Class
@@ -151,7 +152,7 @@ class CI_Log {
if ( ! file_exists($filepath))
{
$newfile = TRUE;
- $message .= '<'."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n";
+ $message .= '<'."?php defined('BASEPATH') OR exit('No direct script access allowed'); ?".">\n\n";
}
if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE))
diff --git a/system/core/Model.php b/system/core/Model.php
index 5a87ab153..28fdfbb69 100644
--- a/system/core/Model.php
+++ b/system/core/Model.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Model Class
diff --git a/system/core/Output.php b/system/core/Output.php
index 3bb8f8dc0..9300df356 100644
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Output Class
diff --git a/system/core/Router.php b/system/core/Router.php
index a5e29f1a3..01f44bc83 100644
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Router Class
@@ -53,13 +54,6 @@ class CI_Router {
public $routes = array();
/**
- * List of error routes
- *
- * @var array
- */
- public $error_routes = array();
-
- /**
* Current class name
*
* @var string
@@ -148,12 +142,12 @@ class CI_Router {
include(APPPATH.'config/routes.php');
}
- $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
+ $this->routes = (isset($route) && is_array($route)) ? $route : array();
unset($route);
// Set the default controller so we can display it in the event
// the URI doesn't correlated to a valid controller.
- $this->default_controller = empty($this->routes['default_controller']) ? FALSE : strtolower($this->routes['default_controller']);
+ $this->default_controller = empty($this->routes['default_controller']) ? FALSE : $this->routes['default_controller'];
// Were there any query string segments? If so, we'll validate them and bail out since we're done.
if (count($segments) > 0)
@@ -185,25 +179,21 @@ class CI_Router {
*/
protected function _set_default_controller()
{
- if ($this->default_controller === FALSE)
+ if (empty($this->default_controller))
{
show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
}
+
// Is the method being specified?
- if (strpos($this->default_controller, '/') !== FALSE)
- {
- $x = explode('/', $this->default_controller);
- $this->set_class($x[0]);
- $this->set_method($x[1]);
- $this->_set_request($x);
- }
- else
+ if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2)
{
- $this->set_class($this->default_controller);
- $this->set_method('index');
- $this->_set_request(array($this->default_controller, 'index'));
+ $method = 'index';
}
+ $this->set_class($class);
+ $this->set_method($method);
+ $this->_set_request(array($class, $method));
+
// re-index the routed segments array so it starts with 1 rather than 0
$this->uri->_reindex_segments();
@@ -232,17 +222,8 @@ class CI_Router {
$this->set_class($segments[0]);
- if (isset($segments[1]))
- {
- // A standard method request
- $this->set_method($segments[1]);
- }
- else
- {
- // This lets the "routed" segment array identify that the default
- // index method is being used.
- $segments[1] = 'index';
- }
+ isset($segments[1]) OR $segments[1] = 'index';
+ $this->set_method($segments[1]);
// Update our "routed" segment array to contain the segments.
// Note: If there is no custom routing, this array will be
@@ -267,9 +248,13 @@ class CI_Router {
return $segments;
}
+ $temp = str_replace('-', '_', $segments[0]);
+
// Does the requested controller exist in the root folder?
- if (file_exists(APPPATH.'controllers/'.$segments[0].'.php'))
+ if (file_exists(APPPATH.'controllers/'.$temp.'.php'))
{
+ $segments[0] = $temp;
+ empty($segments[1]) OR $segments[1] = str_replace('-', '_', $segments[1]);
return $segments;
}
@@ -277,22 +262,19 @@ class CI_Router {
if (is_dir(APPPATH.'controllers/'.$segments[0]))
{
// Set the directory and remove it from the segment array
- $this->set_directory($segments[0]);
- $segments = array_slice($segments, 1);
-
+ $this->set_directory(array_shift($segments));
if (count($segments) > 0)
{
+ $segments[0] = str_replace('-', '_', $segments[0]);
+ empty($segments[1]) OR $segments[1] = str_replace('-', '_', $segments[1]);
+
// Does the requested controller exist in the sub-folder?
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php'))
{
if ( ! empty($this->routes['404_override']))
{
- $x = explode('/', $this->routes['404_override']);
- $this->set_directory('');
- $this->set_class($x[0]);
- $this->set_method(isset($x[1]) ? $x[1] : 'index');
-
- return $x;
+ $this->directory = '';
+ return explode('/', $this->routes['404_override'], 2);
}
else
{
@@ -303,40 +285,26 @@ class CI_Router {
else
{
// Is the method being specified in the route?
- if (strpos($this->default_controller, '/') !== FALSE)
- {
- $x = explode('/', $this->default_controller);
- $this->set_class($x[0]);
- $this->set_method($x[1]);
- }
- else
- {
- $this->set_class($this->default_controller);
- $this->set_method('index');
- }
-
- // Does the default controller exist in the sub-folder?
- if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.'.php'))
+ $segments = explode('/', $this->default_controller);
+ if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php'))
{
$this->directory = '';
- return array();
}
-
}
return $segments;
}
-
// If we've gotten this far it means that the URI does not correlate to a valid
// controller class. We will now see if there is an override
if ( ! empty($this->routes['404_override']))
{
- $x = explode('/', $this->routes['404_override']);
- $this->set_class($x[0]);
- $this->set_method(isset($x[1]) ? $x[1] : 'index');
+ if (sscanf($this->routes['404_override'], '%[^/]/%s', $class, $method) !== 2)
+ {
+ $method = 'index';
+ }
- return $x;
+ return array($class, $method);
}
// Nothing else to do at this point but show a 404
@@ -359,7 +327,7 @@ class CI_Router {
$uri = implode('/', $this->uri->segments);
// Is there a literal match? If so we're done
- if (isset($this->routes[$uri]))
+ if (isset($this->routes[$uri]) && is_string($this->routes[$uri]))
{
return $this->_set_request(explode('/', $this->routes[$uri]));
}
@@ -371,10 +339,48 @@ class CI_Router {
$key = str_replace(array(':any', ':num'), array('[^/]+', '[0-9]+'), $key);
// Does the RegEx match?
- if (preg_match('#^'.$key.'$#', $uri))
+ if (preg_match('#^'.$key.'$#', $uri, $matches))
{
- // Do we have a back-reference?
- if (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE)
+ // Are we using callbacks to process back-references?
+ if ( ! is_string($val) && is_callable($val))
+ {
+ // Remove the original string from the matches array.
+ array_shift($matches);
+
+ // Get the match count.
+ $match_count = count($matches);
+
+ // Determine how many parameters the callback has.
+ $reflection = new ReflectionFunction($val);
+ $param_count = $reflection->getNumberOfParameters();
+
+ // Are there more parameters than matches?
+ if ($param_count > $match_count)
+ {
+ // Any params without matches will be set to an empty string.
+ $matches = array_merge($matches, array_fill($match_count, $param_count - $match_count, ''));
+
+ $match_count = $param_count;
+ }
+
+ // Get the parameters so we can use their default values.
+ $params = $reflection->getParameters();
+
+ for ($m = 0; $m < $match_count; $m++)
+ {
+ // Is the match empty and does a default value exist?
+ if (empty($matches[$m]) && $params[$m]->isDefaultValueAvailable())
+ {
+ // Substitute the empty match for the default value.
+ $matches[$m] = $params[$m]->getDefaultValue();
+ }
+ }
+
+ // Execute the callback using the values in matches as its parameters.
+ $val = call_user_func_array($val, $matches);
+ }
+ // Are we using the default routing method for back-references?
+ elseif (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE)
{
$val = preg_replace('#^'.$key.'$#', $val, $uri);
}
@@ -493,7 +499,7 @@ class CI_Router {
if (isset($routing['function']))
{
- $routing['function'] = ($routing['function'] == '') ? 'index' : $routing['function'];
+ $routing['function'] = empty($routing['function']) ? 'index' : $routing['function'];
$this->set_method($routing['function']);
}
}
diff --git a/system/core/Security.php b/system/core/Security.php
index 50d0ce052..b8e66c087 100644
--- a/system/core/Security.php
+++ b/system/core/Security.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Security Class
diff --git a/system/core/URI.php b/system/core/URI.php
index d67a35d4b..91740254c 100644
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* URI Class
@@ -98,31 +99,28 @@ class CI_URI {
// Is the request coming from the command line?
if ($this->_is_cli_request())
{
- $this->_set_uri_string($this->_parse_cli_args());
+ $this->_set_uri_string($this->_parse_argv());
return;
}
- // Let's try the REQUEST_URI first, this will work in most situations
- if ($uri = $this->_detect_uri())
+ // Is there a PATH_INFO variable? This should be the easiest solution.
+ if (isset($_SERVER['PATH_INFO']))
{
- $this->_set_uri_string($uri);
+ $this->_set_uri_string($_SERVER['PATH_INFO']);
return;
}
- // Is there a PATH_INFO variable?
- // Note: some servers seem to have trouble with getenv() so we'll test it two ways
- $path = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
- if (trim($path, '/') !== '' && $path !== '/'.SELF)
+ // Let's try REQUEST_URI then, this will work in most situations
+ if (($uri = $this->_parse_request_uri()) !== '')
{
- $this->_set_uri_string($path);
+ $this->_set_uri_string($uri);
return;
}
- // No PATH_INFO?... What about QUERY_STRING?
- $path = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
- if (trim($path, '/') !== '')
+ // No REQUEST_URI either?... What about QUERY_STRING?
+ if (($uri = $this->_parse_query_string()) !== '')
{
- $this->_set_uri_string($path);
+ $this->_set_uri_string($uri);
return;
}
@@ -140,19 +138,19 @@ class CI_URI {
$uri = strtoupper($this->config->item('uri_protocol'));
- if ($uri === 'REQUEST_URI')
+ if ($uri === 'CLI')
{
- $this->_set_uri_string($this->_detect_uri());
+ $this->_set_uri_string($this->_parse_argv());
return;
}
- elseif ($uri === 'CLI')
+ elseif (method_exists($this, ($method = '_parse_'.strtolower($uri))))
{
- $this->_set_uri_string($this->_parse_cli_args());
+ $this->_set_uri_string($this->$method());
return;
}
- $path = isset($_SERVER[$uri]) ? $_SERVER[$uri] : @getenv($uri);
- $this->_set_uri_string($path);
+ $uri = isset($_SERVER[$uri]) ? $_SERVER[$uri] : @getenv($uri);
+ $this->_set_uri_string($uri);
}
// --------------------------------------------------------------------
@@ -172,59 +170,54 @@ class CI_URI {
// --------------------------------------------------------------------
/**
- * Detects URI
+ * Parse REQUEST_URI
*
- * Will detect the URI automatically and fix the query string if necessary.
+ * Will parse REQUEST_URI and automatically detect the URI from it,
+ * while fixing the query string if necessary.
*
+ * @used-by CI_URI::_fetch_uri_string()
* @return string
*/
- protected function _detect_uri()
+ protected function _parse_request_uri()
{
if ( ! isset($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']))
{
return '';
}
- if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0)
- {
- $uri = substr($_SERVER['REQUEST_URI'], strlen($_SERVER['SCRIPT_NAME']));
- }
- elseif (strpos($_SERVER['REQUEST_URI'], dirname($_SERVER['SCRIPT_NAME'])) === 0)
+ $uri = parse_url($_SERVER['REQUEST_URI']);
+ $query = isset($uri['query']) ? $uri['query'] : '';
+ $uri = isset($uri['path']) ? rawurldecode($uri['path']) : '';
+
+ if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
{
- $uri = substr($_SERVER['REQUEST_URI'], strlen(dirname($_SERVER['SCRIPT_NAME'])));
+ $uri = (string) substr($uri, strlen($_SERVER['SCRIPT_NAME']));
}
- else
+ elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0)
{
- $uri = $_SERVER['REQUEST_URI'];
+ $uri = (string) substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
}
// This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct
// URI is found, and also fixes the QUERY_STRING server var and $_GET array.
- if (strpos($uri, '?/') === 0)
+ if (trim($uri, '/') === '' && strncmp($query, '/', 1) === 0)
{
- $uri = substr($uri, 2);
- }
-
- $parts = explode('?', $uri, 2);
- $uri = $parts[0];
- if (isset($parts[1]))
- {
- $_SERVER['QUERY_STRING'] = $parts[1];
- parse_str($_SERVER['QUERY_STRING'], $_GET);
+ $query = explode('?', $query, 2);
+ $uri = rawurldecode($query[0]);
+ $_SERVER['QUERY_STRING'] = isset($query[1]) ? $query[1] : '';
}
else
{
- $_SERVER['QUERY_STRING'] = '';
- $_GET = array();
+ $_SERVER['QUERY_STRING'] = $query;
}
+ parse_str($_SERVER['QUERY_STRING'], $_GET);
+
if ($uri === '/' OR $uri === '')
{
return '/';
}
- $uri = parse_url('pseudo://hostname/'.$uri, PHP_URL_PATH);
-
// Do some final cleaning of the URI and return it
return str_replace(array('//', '../'), '/', trim($uri, '/'));
}
@@ -232,6 +225,36 @@ class CI_URI {
// --------------------------------------------------------------------
/**
+ * Parse QUERY_STRING
+ *
+ * Will parse QUERY_STRING and automatically detect the URI from it.
+ *
+ * @used-by CI_URI::_fetch_uri_string()
+ * @return string
+ */
+ protected function _parse_query_string()
+ {
+ $uri = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
+
+ if (trim($uri, '/') === '')
+ {
+ return '';
+ }
+ elseif (strncmp($uri, '/', 1) === 0)
+ {
+ $uri = explode('?', $uri, 2);
+ $_SERVER['QUERY_STRING'] = isset($uri[1]) ? $uri[1] : '';
+ $uri = rawurldecode($uri[0]);
+ }
+
+ parse_str($_SERVER['QUERY_STRING'], $_GET);
+
+ return str_replace(array('//', '../'), '/', trim($uri, '/'));
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Is CLI Request?
*
* Duplicate of method from the Input class to test to see if
@@ -255,10 +278,10 @@ class CI_URI {
*
* @return string
*/
- protected function _parse_cli_args()
+ protected function _parse_argv()
{
$args = array_slice($_SERVER['argv'], 1);
- return $args ? '/'.implode('/', $args) : '';
+ return $args ? implode('/', $args) : '';
}
// --------------------------------------------------------------------
@@ -278,7 +301,7 @@ class CI_URI {
{
// preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards
// compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern
- if ( ! preg_match('|^['.str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-')).']+$|i', urldecode($str)))
+ if ( ! preg_match('|^['.str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-')).']+$|i', $str))
{
show_error('The URI you submitted has disallowed characters.', 400);
}
@@ -673,7 +696,14 @@ class CI_URI {
*/
public function ruri_string()
{
- return implode('/', $this->rsegment_array());
+ global $RTR;
+
+ if (($dir = $RTR->fetch_directory()) === '/')
+ {
+ $dir = '';
+ }
+
+ return $dir.implode('/', $this->rsegment_array());
}
}
diff --git a/system/core/Utf8.php b/system/core/Utf8.php
index efe3c10dc..5bc2dd5c9 100644
--- a/system/core/Utf8.php
+++ b/system/core/Utf8.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Utf8 Class
diff --git a/system/database/DB.php b/system/database/DB.php
index d751325ce..f4062fa73 100644
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Initialize the database
@@ -31,8 +32,10 @@
* @category Database
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
- * @param string
- * @param bool Determines if query builder should be used or not
+ *
+ * @param string|string[] $params
+ * @param bool $query_builder_override
+ * Determines if query builder should be used or not
*/
function &DB($params = '', $query_builder_override = NULL)
{
@@ -47,18 +50,18 @@ function &DB($params = '', $query_builder_override = NULL)
}
include($file_path);
- //make packages contain database config files
- foreach(get_instance()->load->get_package_paths() as $path)
+ // Make packages contain database config files
+ foreach (get_instance()->load->get_package_paths() as $path)
{
if ($path !== APPPATH)
{
- if (file_exists ($file_path = $path.'config/'.ENVIRONMENT.'/database.php'))
+ if (file_exists($file_path = $path.'config/'.ENVIRONMENT.'/database.php'))
{
- include ($file_path);
+ include($file_path);
}
- elseif ( file_exists ($file_path = $path.'config/database.php'))
+ elseif (file_exists($file_path = $path.'config/database.php'))
{
- include ($file_path);
+ include($file_path);
}
}
}
@@ -82,12 +85,12 @@ function &DB($params = '', $query_builder_override = NULL)
}
elseif (is_string($params))
{
-
- /* parse the URL from the DSN string
- * Database settings can be passed as discreet
- * parameters or as a data source name in the first
- * parameter. DSNs must have this prototype:
- * $dsn = 'driver://username:password@hostname/database';
+ /**
+ * Parse the URL from the DSN string
+ * Database settings can be passed as discreet
+ * parameters or as a data source name in the first
+ * parameter. DSNs must have this prototype:
+ * $dsn = 'driver://username:password@hostname/database';
*/
if (($dsn = @parse_url($params)) === FALSE)
{
@@ -103,7 +106,7 @@ function &DB($params = '', $query_builder_override = NULL)
'database' => isset($dsn['path']) ? rawurldecode(substr($dsn['path'], 1)) : ''
);
- // were additional config items set?
+ // Were additional config items set?
if (isset($dsn['query']))
{
parse_str($dsn['query'], $extra);
@@ -148,11 +151,22 @@ function &DB($params = '', $query_builder_override = NULL)
require_once(BASEPATH.'database/DB_query_builder.php');
if ( ! class_exists('CI_DB'))
{
+ /**
+ * CI_DB
+ *
+ * Acts as an alias for both CI_DB_driver and CI_DB_query_builder.
+ *
+ * @see CI_DB_query_builder
+ * @see CI_DB_driver
+ */
class CI_DB extends CI_DB_query_builder { }
}
}
elseif ( ! class_exists('CI_DB'))
{
+ /**
+ * @ignore
+ */
class CI_DB extends CI_DB_driver { }
}
diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php
index d07c755c6..1be80c5c7 100644
--- a/system/database/DB_cache.php
+++ b/system/database/DB_cache.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Database Cache Class
@@ -34,8 +35,24 @@
*/
class CI_DB_Cache {
+ /**
+ * CI Singleton
+ *
+ * @var object
+ */
public $CI;
- public $db; // allows passing of db object so that multiple database connections and returned db objects can be supported
+
+ /**
+ * Database object
+ *
+ * Allows passing of DB object so that multiple database connections
+ * and returned DB objects can be supported.
+ *
+ * @var object
+ */
+ public $db;
+
+ // --------------------------------------------------------------------
/**
* Constructor
@@ -58,7 +75,7 @@ class CI_DB_Cache {
/**
* Set Cache Directory Path
*
- * @param string the path to the cache directory
+ * @param string $path Path to the cache directory
* @return bool
*/
public function check_path($path = '')
@@ -94,7 +111,7 @@ class CI_DB_Cache {
* Retrieve a cached query
*
* The URI being requested will become the name of the cache sub-folder.
- * An MD5 hash of the SQL statement will become the cache file name
+ * An MD5 hash of the SQL statement will become the cache file name.
*
* @param string $sql
* @return string
@@ -153,8 +170,8 @@ class CI_DB_Cache {
/**
* Delete cache files within a particular directory
*
- * @param string $segment_one = ''
- * @param string $segment_two = ''
+ * @param string $segment_one
+ * @param string $segment_two
* @return void
*/
public function delete($segment_one = '', $segment_two = '')
@@ -182,7 +199,7 @@ class CI_DB_Cache {
*/
public function delete_all()
{
- delete_files($this->db->cachedir, TRUE, 0, TRUE);
+ delete_files($this->db->cachedir, TRUE, TRUE);
}
}
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index e8286aaa1..dfaf0e0c1 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Database Driver Class
@@ -40,60 +41,314 @@
*/
abstract class CI_DB_driver {
+ /**
+ * Data Source Name / Connect string
+ *
+ * @var string
+ */
public $dsn;
+
+ /**
+ * Username
+ *
+ * @var string
+ */
public $username;
+
+ /**
+ * Password
+ *
+ * @var string
+ */
public $password;
+
+ /**
+ * Hostname
+ *
+ * @var string
+ */
public $hostname;
+
+ /**
+ * Database name
+ *
+ * @var string
+ */
public $database;
+
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'mysqli';
+
+ /**
+ * Sub-driver
+ *
+ * @used-by CI_DB_pdo_driver
+ * @var string
+ */
public $subdriver;
+
+ /**
+ * Table prefix
+ *
+ * @var string
+ */
public $dbprefix = '';
+
+ /**
+ * Character set
+ *
+ * @var string
+ */
public $char_set = 'utf8';
+
+ /**
+ * Collation
+ *
+ * @var string
+ */
public $dbcollat = 'utf8_general_ci';
- public $autoinit = TRUE; // Whether to automatically initialize the DB
+
+ /**
+ * Auto-init flag
+ *
+ * Whether to automatically initialize the DB connection.
+ *
+ * @var bool
+ */
+ public $autoinit = TRUE;
+
+ /**
+ * Encryption flag/data
+ *
+ * @var mixed
+ */
public $encrypt = FALSE;
+
+ /**
+ * Swap Prefix
+ *
+ * @var string
+ */
public $swap_pre = '';
+
+ /**
+ * Database port
+ *
+ * @var int
+ */
public $port = '';
+
+ /**
+ * Persistent connection flag
+ *
+ * @var bool
+ */
public $pconnect = FALSE;
+
+ /**
+ * Connection ID
+ *
+ * @var object|resource
+ */
public $conn_id = FALSE;
+
+ /**
+ * Result ID
+ *
+ * @var object|resource
+ */
public $result_id = FALSE;
+
+ /**
+ * Debug flag
+ *
+ * Whether to display error messages.
+ *
+ * @var bool
+ */
public $db_debug = FALSE;
+
+ /**
+ * Benchmark time
+ *
+ * @var int
+ */
public $benchmark = 0;
+
+ /**
+ * Executed queries count
+ *
+ * @var int
+ */
public $query_count = 0;
+
+ /**
+ * Bind marker
+ *
+ * Character used to identify values in a prepared statement.
+ *
+ * @var string
+ */
public $bind_marker = '?';
+
+ /**
+ * Save queries flag
+ *
+ * Whether to keep an in-memory history of queries for debugging purposes.
+ *
+ * @var bool
+ */
public $save_queries = TRUE;
+
+ /**
+ * Queries list
+ *
+ * @see CI_DB_driver::$save_queries
+ * @var string[]
+ */
public $queries = array();
+
+ /**
+ * Query times
+ *
+ * A list of times that queries took to execute.
+ *
+ * @var array
+ */
public $query_times = array();
+
+ /**
+ * Data cache
+ *
+ * An internal generic value cache.
+ *
+ * @var array
+ */
public $data_cache = array();
+ /**
+ * Transaction enabled flag
+ *
+ * @var bool
+ */
public $trans_enabled = TRUE;
+
+ /**
+ * Strict transaction mode flag
+ *
+ * @var bool
+ */
public $trans_strict = TRUE;
+
+ /**
+ * Transaction depth level
+ *
+ * @var int
+ */
protected $_trans_depth = 0;
- protected $_trans_status = TRUE; // Used with transactions to determine if a rollback should occur
+ /**
+ * Transaction status flag
+ *
+ * Used with transactions to determine if a rollback should occur.
+ *
+ * @var bool
+ */
+ protected $_trans_status = TRUE;
+
+ /**
+ * Cache On flag
+ *
+ * @var bool
+ */
public $cache_on = FALSE;
+
+ /**
+ * Cache directory path
+ *
+ * @var bool
+ */
public $cachedir = '';
+
+ /**
+ * Cache auto-delete flag
+ *
+ * @var bool
+ */
public $cache_autodel = FALSE;
- public $CACHE; // The cache class object
+ /**
+ * DB Cache object
+ *
+ * @see CI_DB_cache
+ * @var object
+ */
+ public $CACHE;
+
+ /**
+ * Protect identifiers flag
+ *
+ * @var bool
+ */
protected $_protect_identifiers = TRUE;
- protected $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped
- // clause and character used for LIKE escape sequences
+ /**
+ * List of reserved identifiers
+ *
+ * Identifiers that must NOT be escaped.
+ *
+ * @var string[]
+ */
+ protected $_reserved_identifiers = array('*');
+
+ /**
+ * Identifier escape character
+ *
+ * @var string
+ */
+ protected $_escape_char = '"';
+
+ /**
+ * ESCAPE statement string
+ *
+ * @var string
+ */
protected $_like_escape_str = " ESCAPE '%s' ";
+
+ /**
+ * ESCAPE character
+ *
+ * @var string
+ */
protected $_like_escape_chr = '!';
/**
- * The syntax to count rows is slightly different across different
- * database engines, so this string appears in each driver and is
- * used for the count_all() and count_all_results() functions.
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
+ protected $_random_keyword = ' RAND()';
+
+ /**
+ * COUNT string
+ *
+ * @used-by CI_DB_driver::count_all()
+ * @used-by CI_DB_query_builder::count_all_results()
+ *
+ * @var string
*/
protected $_count_string = 'SELECT COUNT(*) AS ';
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Class constructor
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -981,7 +1236,7 @@ abstract class CI_DB_driver {
*/
public function escape_identifiers($item)
{
- if ($this->_escape_char === '' OR empty($item))
+ if ($this->_escape_char === '' OR empty($item) OR in_array($item, $this->_reserved_identifiers))
{
return $item;
}
@@ -1080,43 +1335,19 @@ abstract class CI_DB_driver {
*/
public function update_string($table, $data, $where)
{
- if ($where === '')
+ if (empty($where))
{
return FALSE;
}
+ $this->where($where);
+
$fields = array();
foreach ($data as $key => $val)
{
$fields[$this->protect_identifiers($key)] = $this->escape($val);
}
- if ( ! is_array($where))
- {
- $dest = array($where);
- }
- else
- {
- $dest = array();
- foreach ($where as $key => $val)
- {
- $prefix = (count($dest) === 0) ? '' : ' AND ';
- $key = $this->protect_identifiers($key);
-
- if ($val !== '')
- {
- if ( ! $this->_has_operator($key))
- {
- $key .= ' =';
- }
-
- $val = ' '.$this->escape($val);
- }
-
- $dest[] = $prefix.$key.$val;
- }
- }
-
return $this->_update($this->protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest);
}
@@ -1198,8 +1429,7 @@ abstract class CI_DB_driver {
/**
* Enables a native PHP function to be run, using a platform agnostic wrapper.
*
- * @param string $function the function name
- * @param mixed $param,... optional parameters needed by the function
+ * @param string $function Function name
* @return mixed
*/
public function call_function($function)
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php
index 119d78d38..21046012a 100644
--- a/system/database/DB_forge.php
+++ b/system/database/DB_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Database Forge Class
@@ -34,27 +35,127 @@
*/
abstract class CI_DB_forge {
+ /**
+ * Database object
+ *
+ * @var object
+ */
+ protected $db;
+
+ /**
+ * Fields data
+ *
+ * @var array
+ */
public $fields = array();
+
+ /**
+ * Keys data
+ *
+ * @var array
+ */
public $keys = array();
+
+ /**
+ * Primary Keys data
+ *
+ * @var array
+ */
public $primary_keys = array();
+
+ /**
+ * Database character set
+ *
+ * @var string
+ */
public $db_char_set = '';
- // Platform specific SQL strings
+ // --------------------------------------------------------------------
+
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
protected $_create_database = 'CREATE DATABASE %s';
+
+ /**
+ * DROP DATABASE statement
+ *
+ * @var string
+ */
protected $_drop_database = 'DROP DATABASE %s';
- protected $_drop_table = 'DROP TABLE IF EXISTS %s';
- protected $_rename_table = 'ALTER TABLE %s RENAME TO %s';
/**
- * Constructor
+ * CREATE TABLE statement
*
+ * @var string
+ */
+ protected $_create_table = "%s %s (%s\n)";
+
+ /**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
+
+ /**
+ * CREATE TABLE keys flag
+ *
+ * Whether table keys are created from within the
+ * CREATE TABLE statement.
+ *
+ * @var bool
+ */
+ protected $_create_table_keys = FALSE;
+
+ /**
+ * DROP TABLE IF EXISTS statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = 'DROP TABLE IF EXISTS';
+
+ /**
+ * RENAME TABLE statement
+ *
+ * @var string
+ */
+ protected $_rename_table = 'ALTER TABLE %s RENAME TO %s;';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var bool|array
+ */
+ protected $_unsigned = TRUE;
+
+ /**
+ * NULL value representatin in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = '';
+
+ /**
+ * DEFAULT value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_default = ' DEFAULT ';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * @param object &$db Database object
* @return void
*/
- public function __construct()
+ public function __construct(&$db)
{
- // Assign the main database object to $this->db
- $CI =& get_instance();
- $this->db =& $CI->db;
+ $this->db =& $db;
log_message('debug', 'Database Forge Class Initialized');
}
@@ -63,14 +164,14 @@ abstract class CI_DB_forge {
/**
* Create database
*
- * @param string the database name
+ * @param string $db_name
* @return bool
*/
public function create_database($db_name)
{
if ($this->_create_database === FALSE)
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
}
elseif ( ! $this->db->query(sprintf($this->_create_database, $db_name, $this->db->char_set, $this->db->dbcollat)))
{
@@ -90,7 +191,7 @@ abstract class CI_DB_forge {
/**
* Drop database
*
- * @param string the database name
+ * @param string $db_name
* @return bool
*/
public function drop_database($db_name)
@@ -102,7 +203,7 @@ abstract class CI_DB_forge {
}
elseif ($this->_drop_database === FALSE)
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
}
elseif ( ! $this->db->query(sprintf($this->_drop_database, $db_name)))
{
@@ -126,25 +227,25 @@ abstract class CI_DB_forge {
/**
* Add Key
*
- * @param string key
- * @param string type
+ * @param string $key
+ * @param bool $primary
* @return object
*/
public function add_key($key = '', $primary = FALSE)
{
- if (is_array($key))
+ if (empty($key))
+ {
+ show_error('Key information is required for that operation.');
+ }
+
+ if ($primary === TRUE && is_array($key))
{
foreach ($key as $one)
{
$this->add_key($one, $primary);
}
- return;
- }
-
- if ($key === '')
- {
- show_error('Key information is required for that operation.');
+ return $this;
}
if ($primary === TRUE)
@@ -164,12 +265,12 @@ abstract class CI_DB_forge {
/**
* Add Field
*
- * @param string collation
+ * @param array $field
* @return object
*/
public function add_field($field = '')
{
- if ($field === '')
+ if (empty($field))
{
show_error('Field information is required.');
}
@@ -211,8 +312,8 @@ abstract class CI_DB_forge {
/**
* Create Table
*
- * @param string $table = ''
- * @param bool $if_not_exists = FALSE
+ * @param string $table Table name
+ * @param bool $if_not_exists Whether to add IF NOT EXISTS condition
* @return bool
*/
public function create_table($table = '', $if_not_exists = FALSE)
@@ -221,51 +322,129 @@ abstract class CI_DB_forge {
{
show_error('A table name is required for that operation.');
}
+ else
+ {
+ $table = $this->db->dbprefix.$table;
+ }
if (count($this->fields) === 0)
{
show_error('Field information is required.');
}
- $sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists);
- $this->_reset();
+ $sql = $this->_create_table($table, $if_not_exists);
if (is_bool($sql))
{
- return $sql;
+ $this->_reset();
+ if ($sql === FALSE)
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
}
- if (($result = $this->db->query($sql)) !== FALSE && ! empty($this->db->data_cache['table_names']))
+ if (($result = $this->db->query($sql)) !== FALSE)
{
- $this->db->data_cache['table_names'][] = $this->db->dbprefix.$table;
+ empty($this->db->data_cache['table_names']) OR $this->db->data_cache['table_names'][] = $table;
+
+ // Most databases don't support creating indexes from within the CREATE TABLE statement
+ if ( ! empty($this->keys))
+ {
+ for ($i = 0, $sqls = $this->_process_indexes($table), $c = count($sqls); $i < $c; $i++)
+ {
+ $this->db->query($sqls[$i]);
+ }
+ }
}
+ $this->_reset();
return $result;
}
// --------------------------------------------------------------------
/**
+ * Create Table
+ *
+ * @param string $table Table name
+ * @param bool $if_not_exists Whether to add 'IF NOT EXISTS' condition
+ * @return mixed
+ */
+ protected function _create_table($table, $if_not_exists)
+ {
+ if ($if_not_exists === TRUE && $this->_create_table_if === FALSE)
+ {
+ if ($this->db->table_exists($table))
+ {
+ return TRUE;
+ }
+ else
+ {
+ $if_not_exists = FALSE;
+ }
+ }
+
+ $sql = ($if_not_exists)
+ ? sprintf($this->_create_table_if, $this->db->escape_identifiers($table))
+ : 'CREATE TABLE';
+
+ $columns = $this->_process_fields(TRUE);
+ for ($i = 0, $c = count($columns); $i < $c; $i++)
+ {
+ $columns[$i] = ($columns[$i]['_literal'] !== FALSE)
+ ? "\n\t".$columns[$i]['_literal']
+ : "\n\t".$this->_process_column($columns[$i]);
+ }
+
+ $columns = implode(',', $columns)
+ .$this->_process_primary_keys($table);
+
+ // Are indexes created from within the CREATE TABLE statement? (e.g. in MySQL)
+ if ($this->_create_table_keys === TRUE)
+ {
+ $columns .= $this->_process_indexes();
+ }
+
+ // _create_table will usually have the following format: "%s %s (%s\n)"
+ $sql = sprintf($this->_create_table.';',
+ $sql,
+ $this->db->escape_identifiers($table),
+ $columns
+ );
+
+ return $sql;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Drop Table
*
- * @param string the table name
+ * @param string $table_name Table name
+ * @param bool $if_exists Whether to add an IF EXISTS condition
* @return bool
*/
- public function drop_table($table_name)
+ public function drop_table($table_name, $if_exists = FALSE)
{
if ($table_name === '')
{
return ($this->db->db_debug) ? $this->db->display_error('db_table_name_required') : FALSE;
}
- elseif ($this->_drop_table === FALSE)
+
+ $query = $this->_drop_table($this->db->dbprefix.$table_name, $if_exists);
+ if ($query === FALSE)
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
+ elseif ($query === TRUE)
+ {
+ return TRUE;
}
- $result = $this->db->query(sprintf($this->_drop_table, $this->db->escape_identifiers($this->db->dbprefix.$table_name)));
+ $query = $this->db->query($query);
// Update table list cache
- if ($result && ! empty($this->db->data_cache['table_names']))
+ if ($query && ! empty($this->db->data_cache['table_names']))
{
$key = array_search(strtolower($this->db->dbprefix.$table_name), array_map('strtolower', $this->db->data_cache['table_names']), TRUE);
if ($key !== FALSE)
@@ -274,7 +453,40 @@ abstract class CI_DB_forge {
}
}
- return $result;
+ return $query;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Drop Table
+ *
+ * Generates a platform-specific DROP TABLE string
+ *
+ * @param string $table Table name
+ * @param bool $if_exists Whether to add an IF EXISTS condition
+ * @return string
+ */
+ protected function _drop_table($table, $if_exists)
+ {
+ $sql = 'DROP TABLE';
+
+ if ($if_exists)
+ {
+ if ($this->_drop_table_if === FALSE)
+ {
+ if ( ! $this->db->table_exists($table))
+ {
+ return TRUE;
+ }
+ }
+ else
+ {
+ $sql = sprintf($this->_drop_table_if, $this->db->escape_identifiers($table));
+ }
+ }
+
+ return $sql.' '.$this->db->escape_identifiers($table);
}
// --------------------------------------------------------------------
@@ -282,8 +494,8 @@ abstract class CI_DB_forge {
/**
* Rename Table
*
- * @param string the old table name
- * @param string the new table name
+ * @param string $table_name Old table name
+ * @param string $new_table_name New table name
* @return bool
*/
public function rename_table($table_name, $new_table_name)
@@ -295,7 +507,7 @@ abstract class CI_DB_forge {
}
elseif ($this->_rename_table === FALSE)
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
}
$result = $this->db->query(sprintf($this->_rename_table,
@@ -320,33 +532,46 @@ abstract class CI_DB_forge {
/**
* Column Add
*
- * @param string the table name
- * @param string the column name
- * @param string the column definition
+ * @todo Remove deprecated $_after option in 3.1+
+ * @param string $table Table name
+ * @param array $field Column definition
+ * @param string $_after Column for AFTER clause (deprecated)
* @return bool
*/
- public function add_column($table = '', $field = array(), $after_field = '')
+ public function add_column($table = '', $field = array(), $_after = NULL)
{
if ($table === '')
{
show_error('A table name is required for that operation.');
}
- // add field info into field array, but we can only do one at a time
- // so we cycle through
- foreach (array_keys($field) as $k)
+ // Work-around for literal column definitions
+ if ( ! is_array($field))
{
- $this->add_field(array($k => $field[$k]));
+ $field = array($field);
+ }
- if (count($this->fields) === 0)
+ foreach (array_keys($field) as $k)
+ {
+ // Backwards-compatibility work-around for MySQL/CUBRID AFTER clause (remove in 3.1+)
+ if ($_after !== NULL && is_array($field[$k]) && ! isset($field[$k]['after']))
{
- show_error('Field information is required.');
+ $field[$k]['after'] = $_after;
}
- $sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field);
- $this->_reset();
+ $this->add_field(array($k => $field[$k]));
+ }
+
+ $sqls = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->_process_fields());
+ $this->_reset();
+ if ($sqls === FALSE)
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
- if ($this->db->query($sql) === FALSE)
+ for ($i = 0, $c = count($sqls); $i < $c; $i++)
+ {
+ if ($this->db->query($sqls[$i]) === FALSE)
{
return FALSE;
}
@@ -360,8 +585,8 @@ abstract class CI_DB_forge {
/**
* Column Drop
*
- * @param string the table name
- * @param string the column name
+ * @param string $table Table name
+ * @param string $column_name Column name
* @return bool
*/
public function drop_column($table = '', $column_name = '')
@@ -376,7 +601,13 @@ abstract class CI_DB_forge {
show_error('A column name is required for that operation.');
}
- return $this->db->query($this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name));
+ $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name);
+ if ($sql === FALSE)
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
+
+ return $this->db->query($sql);
}
// --------------------------------------------------------------------
@@ -384,8 +615,8 @@ abstract class CI_DB_forge {
/**
* Column Modify
*
- * @param string $table = ''
- * @param string $field = array() column definition
+ * @param string $table Table name
+ * @param string $field Column definition
* @return bool
*/
public function modify_column($table = '', $field = array())
@@ -395,32 +626,363 @@ abstract class CI_DB_forge {
show_error('A table name is required for that operation.');
}
- // add field info into field array, but we can only do one at a time
- // so we cycle through
+ // Work-around for literal column definitions
+ if ( ! is_array($field))
+ {
+ $field = array($field);
+ }
+
foreach (array_keys($field) as $k)
{
- // If no name provided, use the current name
- if ( ! isset($field[$k]['name']))
+ $this->add_field(array($k => $field[$k]));
+ }
+
+ if (count($this->fields) === 0)
+ {
+ show_error('Field information is required.');
+ }
+
+ $sqls = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields);
+ $this->_reset();
+ if ($sqls === FALSE)
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
+
+ for ($i = 0, $c = count($sqls); $i < $c; $i++)
+ {
+ if ($this->db->query($sqls[$i]) === FALSE)
{
- $field[$k]['name'] = $k;
+ return FALSE;
}
+ }
- $this->add_field(array($k => $field[$k]));
- if (count($this->fields) === 0)
+ return TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ';
+
+ // DROP has everything it needs now.
+ if ($alter_type === 'DROP')
+ {
+ return $sql.'DROP COLUMN '.$this->db->escape_identifiers($field);
+ }
+
+ $sqls = array();
+ for ($i = 0, $c = count($field), $sql .= $alter_type.' COLUMN '; $i < $c; $i++)
+ {
+ $sqls[] = $sql
+ .($field[$i]['_literal'] !== FALSE ? $field[$i]['_literal'] : $this->_process_column($field[$i]));
+ }
+
+ return $sqls;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process fields
+ *
+ * @param bool $create_table
+ * @return array
+ */
+ protected function _process_fields($create_table = FALSE)
+ {
+ $fields = array();
+
+ foreach ($this->fields as $key => $attributes)
+ {
+ if (is_int($key) && ! is_array($attributes))
{
- show_error('Field information is required.');
+ $fields[] = array('_literal' => $attributes);
+ continue;
}
- $sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields);
- $this->_reset();
+ $attributes = array_change_key_case($attributes, CASE_UPPER);
- if ($this->db->query($sql) === FALSE)
+ if ($create_table === TRUE && empty($attributes['TYPE']))
{
- return FALSE;
+ continue;
+ }
+
+ if (isset($attributes['TYPE']))
+ {
+ $this->_attr_type($attributes);
+ $this->_attr_unsigned($attributes, $field);
}
+
+ $field = array(
+ 'name' => $key,
+ 'new_name' => isset($attributes['NAME']) ? $attributes['NAME'] : NULL,
+ 'type' => isset($attributes['TYPE']) ? $attributes['TYPE'] : NULL,
+ 'length' => '',
+ 'unsigned' => '',
+ 'null' => '',
+ 'unique' => '',
+ 'default' => '',
+ 'auto_increment' => '',
+ '_literal' => FALSE
+ );
+
+ $this->_attr_default($attributes, $field);
+
+ if (isset($attributes['NULL']))
+ {
+ if ($attributes['NULL'] === TRUE)
+ {
+ $field['null'] = empty($this->_null) ? '' : ' '.$this->_null;
+ }
+ elseif ($create_table === TRUE)
+ {
+ $field['null'] = ' NOT NULL';
+ }
+ }
+
+ $this->_attr_auto_increment($attributes, $field);
+ $this->_attr_unique($attributes, $field);
+
+ if (isset($attributes['TYPE']) && ! empty($attributes['CONSTRAINT']))
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'ENUM':
+ case 'SET':
+ $attributes['CONSTRAINT'] = $this->db->escape($attributes['CONSTRAINT']);
+ default:
+ $field['length'] = is_array($attributes['CONSTRAINT'])
+ ? '('.implode(',', $attributes['CONSTRAINT']).')'
+ : '('.$attributes['CONSTRAINT'].')';
+ break;
+ }
+ }
+
+ $fields[] = $field;
}
- return TRUE;
+ return $fields;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ return $this->db->escape_identifiers($field['name'])
+ .' '.$field['type'].$field['length']
+ .$field['unsigned']
+ .$field['default']
+ .$field['null']
+ .$field['auto_increment']
+ .$field['unique'];
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ // Usually overriden by drivers
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute UNSIGNED
+ *
+ * Depending on the _unsigned property value:
+ *
+ * - TRUE will always set $field['unsigned'] to 'UNSIGNED'
+ * - FALSE will always set $field['unsigned'] to ''
+ * - array(TYPE) will set $field['unsigned'] to 'UNSIGNED',
+ * if $attributes['TYPE'] is found in the array
+ * - array(TYPE => UTYPE) will change $field['type'],
+ * from TYPE to UTYPE in case of a match
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_unsigned(&$attributes, &$field)
+ {
+ if (empty($attributes['UNSIGNED']) OR $attributes['UNSIGNED'] !== TRUE)
+ {
+ return;
+ }
+
+ // Reset the attribute in order to avoid issues if we do type conversion
+ $attributes['UNSIGNED'] = FALSE;
+
+ if (is_array($this->_unsigned))
+ {
+ foreach (array_keys($this->_unsigned) as $key)
+ {
+ if (is_int($key) && strcasecmp($attributes['TYPE'], $this->_unsigned[$key]) === 0)
+ {
+ $field['unsigned'] = ' UNSIGNED';
+ return;
+ }
+ elseif (is_string($key) && strcasecmp($attributes['TYPE'], $key) === 0)
+ {
+ $field['type'] = $key;
+ return;
+ }
+ }
+
+ return;
+ }
+
+ $field['unsigned'] = ($this->_unsigned === TRUE) ? ' UNSIGNED' : '';
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute DEFAULT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_default(&$attributes, &$field)
+ {
+ if ($this->_default === FALSE)
+ {
+ return;
+ }
+
+ if (array_key_exists('DEFAULT', $attributes))
+ {
+ if ($attributes['DEFAULT'] === NULL)
+ {
+ $field['default'] = empty($this->_null) ? '' : $this->_default.$this->_null;
+
+ // Override the NULL attribute if that's our default
+ $attributes['NULL'] = NULL;
+ $field['null'] = empty($this->_null) ? '' : ' '.$this->_null;
+ }
+ else
+ {
+ $field['default'] = $this->_default.$this->db->escape($attributes['DEFAULT']);
+ }
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute UNIQUE
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_unique(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
+ {
+ $field['unique'] = ' UNIQUE';
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
+ {
+ $field['auto_increment'] = ' AUTO_INCREMENT';
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process primary keys
+ *
+ * @param string $table Table name
+ * @return string
+ */
+ protected function _process_primary_keys($table)
+ {
+ $sql = '';
+
+ for ($i = 0, $c = count($this->primary_keys); $i < $c; $i++)
+ {
+ if ( ! isset($this->fields[$this->primary_keys[$i]]))
+ {
+ unset($this->primary_keys[$i]);
+ }
+ }
+
+ if (count($this->primary_keys) > 0)
+ {
+ $sql .= ",\n\tCONSTRAINT ".$this->db->escape_identifiers('pk_'.$table)
+ .' PRIMARY KEY('.implode(', ', $this->db->escape_identifiers($this->primary_keys)).')';
+ }
+
+ return $sql;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process indexes
+ *
+ * @param string $table
+ * @return string
+ */
+ protected function _process_indexes($table = NULL)
+ {
+ $table = $this->db->escape_identifiers($table);
+ $sqls = array();
+
+ for ($i = 0, $c = count($this->keys); $i < $c; $i++)
+ {
+ if ( ! isset($this->fields[$this->keys[$i]]))
+ {
+ unset($this->keys[$i]);
+ continue;
+ }
+
+ is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
+
+ $sqls[] = 'CREATE INDEX '.$this->db->escape_identifiers(implode('_', $this->keys[$i]))
+ .' ON '.$this->db->escape_identifiers($table)
+ .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).');';
+ }
+
+ return $sqls;
}
// --------------------------------------------------------------------
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index a3585586e..364397721 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Query Builder Class
@@ -39,42 +40,213 @@
abstract class CI_DB_query_builder extends CI_DB_driver {
+ /**
+ * Return DELETE SQL flag
+ *
+ * @var bool
+ */
protected $return_delete_sql = FALSE;
+
+ /**
+ * Reset DELETE data flag
+ *
+ * @var bool
+ */
protected $reset_delete_data = FALSE;
+ /**
+ * QB SELECT data
+ *
+ * @var array
+ */
protected $qb_select = array();
+
+ /**
+ * QB DISTINCT flag
+ *
+ * @var bool
+ */
protected $qb_distinct = FALSE;
+
+ /**
+ * QB FROM data
+ *
+ * @var array
+ */
protected $qb_from = array();
+
+ /**
+ * QB JOIN data
+ *
+ * @var array
+ */
protected $qb_join = array();
+
+ /**
+ * QB WHERE data
+ *
+ * @var array
+ */
protected $qb_where = array();
+
+ /**
+ * QB GROUP BY data
+ *
+ * @var array
+ */
protected $qb_groupby = array();
+
+ /**
+ * QB HAVING data
+ *
+ * @var array
+ */
protected $qb_having = array();
+
+ /**
+ * QB keys
+ *
+ * @var array
+ */
protected $qb_keys = array();
+
+ /**
+ * QB LIMIT data
+ *
+ * @var int
+ */
protected $qb_limit = FALSE;
+
+ /**
+ * QB OFFSET data
+ *
+ * @var int
+ */
protected $qb_offset = FALSE;
+
+ /**
+ * QB ORDER BY data
+ *
+ * @var array
+ */
protected $qb_orderby = array();
+
+ /**
+ * QB data sets
+ *
+ * @var array
+ */
protected $qb_set = array();
+
+ /**
+ * QB aliased tables list
+ *
+ * @var array
+ */
protected $qb_aliased_tables = array();
- protected $qb_store_array = array();
+
+ /**
+ * QB WHERE group started flag
+ *
+ * @var bool
+ */
protected $qb_where_group_started = FALSE;
+
+ /**
+ * QB WHERE group count
+ *
+ * @var int
+ */
protected $qb_where_group_count = 0;
// Query Builder Caching variables
+
+ /**
+ * QB Caching flag
+ *
+ * @var bool
+ */
protected $qb_caching = FALSE;
+
+ /**
+ * QB Cache exists list
+ *
+ * @var array
+ */
protected $qb_cache_exists = array();
+
+ /**
+ * QB Cache SELECT data
+ *
+ * @var array
+ */
protected $qb_cache_select = array();
+
+ /**
+ * QB Cache FROM data
+ *
+ * @var array
+ */
protected $qb_cache_from = array();
+
+ /**
+ * QB Cache JOIN data
+ *
+ * @var array
+ */
protected $qb_cache_join = array();
+
+ /**
+ * QB Cache WHERE data
+ *
+ * @var array
+ */
protected $qb_cache_where = array();
- protected $qb_cache_like = array();
+
+ /**
+ * QB Cache GROUP BY data
+ *
+ * @var array
+ */
protected $qb_cache_groupby = array();
+
+ /**
+ * QB Cache HAVING data
+ *
+ * @var array
+ */
protected $qb_cache_having = array();
+
+ /**
+ * QB Cache ORDER BY data
+ *
+ * @var array
+ */
protected $qb_cache_orderby = array();
+
+ /**
+ * QB Cache data sets
+ *
+ * @var array
+ */
protected $qb_cache_set = array();
+ /**
+ * QB No Escape data
+ *
+ * @var array
+ */
protected $qb_no_escape = array();
+
+ /**
+ * QB Cache No Escape data
+ *
+ * @var array
+ */
protected $qb_cache_no_escape = array();
+ // --------------------------------------------------------------------
+
/**
* Select
*
@@ -182,17 +354,16 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Processing Function for the following functions:
- *
- * select_max()
- * select_min()
- * select_avg()
- * select_sum()
+ * SELECT [MAX|MIN|AVG|SUM]()
*
+ * @used-by select_max()
+ * @used-by select_min()
+ * @used-by select_avg()
+ * @used-by select_sum()
*
- * @param string $select = '' field name
- * @param string $alias = ''
- * @param string $type = 'MAX'
+ * @param string $select Field name
+ * @param string $alias
+ * @param string $type
* @return object
*/
protected function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX')
@@ -233,7 +404,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
/**
* Determines the alias name based on the table
*
- * @param string
+ * @param string $item
* @return string
*/
protected function _create_alias_from_table($item)
@@ -254,7 +425,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* Sets a flag which tells the query string compiler to add DISTINCT
*
- * @param bool
+ * @param bool $val
* @return object
*/
public function distinct($val = TRUE)
@@ -270,7 +441,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* Generates the FROM portion of the query
*
- * @param mixed can be a string or array
+ * @param mixed $from can be a string or array
* @return object
*/
public function from($from)
@@ -317,7 +488,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Join
+ * JOIN
*
* Generates the JOIN portion of the query
*
@@ -405,10 +576,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Where
+ * WHERE
*
- * Generates the WHERE portion of the query. Separates
- * multiple calls with AND
+ * Generates the WHERE portion of the query.
+ * Separates multiple calls with 'AND'.
*
* @param mixed
* @param mixed
@@ -423,10 +594,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * OR Where
+ * OR WHERE
*
- * Generates the WHERE portion of the query. Separates
- * multiple calls with OR
+ * Generates the WHERE portion of the query.
+ * Separates multiple calls with 'OR'.
*
* @param mixed
* @param mixed
@@ -443,13 +614,16 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
/**
* WHERE, HAVING
*
- * Called by where(), or_where(), having(), or_having()
+ * @used-by where()
+ * @used-by or_where()
+ * @used-by having()
+ * @used-by or_having()
*
- * @param string 'qb_where' or 'qb_having'
- * @param mixed
- * @param mixed
- * @param string
- * @param bool
+ * @param string $qb_key 'qb_where' or 'qb_having'
+ * @param mixed $key
+ * @param mixed $value
+ * @param string $type
+ * @param bool $escape
* @return object
*/
protected function _wh($qb_key, $key, $value = NULL, $type = 'AND ', $escape = NULL)
@@ -504,14 +678,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Where_in
+ * WHERE IN
*
- * Generates a WHERE field IN('item', 'item') SQL query joined with
- * AND if appropriate
+ * Generates a WHERE field IN('item', 'item') SQL query,
+ * joined with 'AND' if appropriate.
*
- * @param string $key = NULL The field to search
- * @param array $values = NULL The values searched on
- * @param bool $escape = NULL
+ * @param string $key The field to search
+ * @param array $values The values searched on
+ * @param bool $escape
* @return object
*/
public function where_in($key = NULL, $values = NULL, $escape = NULL)
@@ -522,14 +696,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Or_where_in
+ * OR WHERE IN
*
- * Generates a WHERE field IN('item', 'item') SQL query joined with
- * OR if appropriate
+ * Generates a WHERE field IN('item', 'item') SQL query,
+ * joined with 'OR' if appropriate.
*
- * @param string $key = NULL The field to search
- * @param array $values = NULL The values searched on
- * @param bool $escape = NULL
+ * @param string $key The field to search
+ * @param array $values The values searched on
+ * @param bool $escape
* @return object
*/
public function or_where_in($key = NULL, $values = NULL, $escape = NULL)
@@ -540,14 +714,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Where_not_in
+ * WHERE NOT IN
*
- * Generates a WHERE field NOT IN('item', 'item') SQL query joined
- * with AND if appropriate
+ * Generates a WHERE field NOT IN('item', 'item') SQL query,
+ * joined with 'AND' if appropriate.
*
- * @param string $key = NULL The field to search
- * @param array $values = NULL The values searched on
- * @param bool $escape = NULL
+ * @param string $key The field to search
+ * @param array $values The values searched on
+ * @param bool $escape
* @return object
*/
public function where_not_in($key = NULL, $values = NULL, $escape = NULL)
@@ -558,14 +732,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Or_where_not_in
+ * OR WHERE NOT IN
*
- * Generates a WHERE field NOT IN('item', 'item') SQL query joined
- * with OR if appropriate
+ * Generates a WHERE field NOT IN('item', 'item') SQL query,
+ * joined with 'OR' if appropriate.
*
- * @param string $key = NULL The field to search
- * @param array $values = NULL The values searched on
- * @param bool $escape = NULL
+ * @param string $key The field to search
+ * @param array $values The values searched on
+ * @param bool $escape
* @return object
*/
public function or_where_not_in($key = NULL, $values = NULL, $escape = NULL)
@@ -576,15 +750,18 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Where_in
+ * Internal WHERE IN
*
- * Called by where_in(), or_where_in(), where_not_in(), or_where_not_in()
+ * @used-by where_in()
+ * @used-by or_where_in()
+ * @used-by where_not_in()
+ * @used-by or_where_not_in()
*
- * @param string $key = NULL The field to search
- * @param array $values = NULL The values searched on
- * @param bool $not = FALSE If the statement would be IN or NOT IN
- * @param string $type = 'AND '
- * @param bool $escape = NULL
+ * @param string $key The field to search
+ * @param array $values The values searched on
+ * @param bool $not If the statement would be IN or NOT IN
+ * @param string $type
+ * @param bool $escape
* @return object
*/
protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ', $escape = NULL)
@@ -628,15 +805,15 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Like
+ * LIKE
*
- * Generates a %LIKE% portion of the query. Separates
- * multiple calls with AND
+ * Generates a %LIKE% portion of the query.
+ * Separates multiple calls with 'AND'.
*
- * @param mixed
- * @param string
- * @param string
- * @param bool
+ * @param mixed $field
+ * @param string $match
+ * @param string $side
+ * @param bool $escape
* @return object
*/
public function like($field, $match = '', $side = 'both', $escape = NULL)
@@ -647,15 +824,15 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Not Like
+ * NOT LIKE
*
- * Generates a NOT LIKE portion of the query. Separates
- * multiple calls with AND
+ * Generates a NOT LIKE portion of the query.
+ * Separates multiple calls with 'AND'.
*
- * @param mixed
- * @param string
- * @param string
- * @param bool
+ * @param mixed $field
+ * @param string $match
+ * @param string $side
+ * @param bool $escape
* @return object
*/
public function not_like($field, $match = '', $side = 'both', $escape = NULL)
@@ -666,15 +843,15 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * OR Like
+ * OR LIKE
*
- * Generates a %LIKE% portion of the query. Separates
- * multiple calls with OR
+ * Generates a %LIKE% portion of the query.
+ * Separates multiple calls with 'OR'.
*
- * @param mixed
- * @param string
- * @param string
- * @param bool
+ * @param mixed $field
+ * @param string $match
+ * @param string $side
+ * @param bool $escape
* @return object
*/
public function or_like($field, $match = '', $side = 'both', $escape = NULL)
@@ -685,15 +862,15 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * OR Not Like
+ * OR NOT LIKE
*
- * Generates a NOT LIKE portion of the query. Separates
- * multiple calls with OR
+ * Generates a NOT LIKE portion of the query.
+ * Separates multiple calls with 'OR'.
*
- * @param mixed
- * @param string
- * @param string
- * @param bool
+ * @param mixed $field
+ * @param string $match
+ * @param string $side
+ * @param bool $escape
* @return object
*/
public function or_not_like($field, $match = '', $side = 'both', $escape = NULL)
@@ -704,16 +881,19 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Like
+ * Internal LIKE
*
- * Called by like(), or_like(), not_like, or_not_like()
+ * @used-by like()
+ * @used-by or_like()
+ * @used-by not_like()
+ * @used-by or_not_like()
*
- * @param mixed
- * @param string
- * @param string
- * @param string
- * @param string
- * @param bool
+ * @param mixed $field
+ * @param string $match
+ * @param string $type
+ * @param string $side
+ * @param string $not
+ * @param bool $escape
* @return object
*/
protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '', $escape = NULL)
@@ -770,8 +950,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
/**
* Starts a query group.
*
- * @param string (Internal use only)
- * @param string (Internal use only)
+ * @param string $not (Internal use only)
+ * @param string $type (Internal use only)
* @return object
*/
public function group_start($not = '', $type = 'AND ')
@@ -859,9 +1039,12 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
/**
* Group_get_type
*
- * Called by group_start(), _like(), _where() and _where_in()
+ * @used-by group_start()
+ * @used-by _like()
+ * @used-by _wh()
+ * @used-by _where_in()
*
- * @param string
+ * @param string $type
* @return string
*/
protected function _group_get_type($type)
@@ -880,8 +1063,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
/**
* GROUP BY
*
- * @param string
- * @param bool
+ * @param string $by
+ * @param bool $escape
* @return object
*/
public function group_by($by, $escape = NULL)
@@ -918,13 +1101,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Sets the HAVING value
+ * HAVING
*
- * Separates multiple calls with AND
+ * Separates multiple calls with 'AND'.
*
- * @param string
- * @param string
- * @param bool
+ * @param string $key
+ * @param string $value
+ * @param bool $escape
* @return object
*/
public function having($key, $value = NULL, $escape = NULL)
@@ -935,13 +1118,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Sets the OR HAVING value
+ * OR HAVING
*
- * Separates multiple calls with OR
+ * Separates multiple calls with 'OR'.
*
- * @param string
- * @param string
- * @param bool
+ * @param string $key
+ * @param string $value
+ * @param bool $escape
* @return object
*/
public function or_having($key, $value = NULL, $escape = NULL)
@@ -952,11 +1135,11 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Sets the ORDER BY value
+ * ORDER BY
*
- * @param string
- * @param string direction: ASC or DESC
- * @param bool enable field name escaping
+ * @param string $orderby
+ * @param string $direction ASC or DESC
+ * @param bool $escape
* @return object
*/
public function order_by($orderby, $direction = '', $escape = NULL)
@@ -1008,10 +1191,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Sets the LIMIT value
+ * LIMIT
*
- * @param int the limit value
- * @param int the offset value
+ * @param int $value LIMIT value
+ * @param int $offset OFFSET value
* @return object
*/
public function limit($value, $offset = FALSE)
@@ -1027,7 +1210,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
/**
* Sets the OFFSET value
*
- * @param int the offset value
+ * @param int $offset OFFSET value
* @return object
*/
public function offset($offset)
@@ -1039,11 +1222,11 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT string
*
- * Generates a platform-specific LIMIT clause
+ * Generates a platform-specific LIMIT clause.
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
@@ -1183,10 +1366,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* Allows the where clause, limit and offset to be added directly
*
- * @param string $table = ''
- * @param string $where = NULL
- * @param int $limit = NULL
- * @param int $offset = NULL
+ * @param string $table
+ * @param string $where
+ * @param int $limit
+ * @param int $offset
* @return object
*/
public function get_where($table = '', $where = NULL, $limit = NULL, $offset = NULL)
@@ -1218,15 +1401,16 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* Compiles batch insert strings and runs the queries
*
- * @param string $table = '' table to insert into
- * @param array $set an associative array of insert values
- * @return int number of rows inserted or FALSE on failure
+ * @param string $table Table to insert into
+ * @param array $set An associative array of insert values
+ * @param bool $escape Whether to escape values and identifiers
+ * @return int Number of rows inserted or FALSE on failure
*/
- public function insert_batch($table = '', $set = NULL)
+ public function insert_batch($table = '', $set = NULL, $escape = NULL)
{
if ( ! is_null($set))
{
- $this->set_insert_batch($set);
+ $this->set_insert_batch($set, '', $escape);
}
if (count($this->qb_set) === 0)
@@ -1249,7 +1433,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$affected_rows = 0;
for ($i = 0, $total = count($this->qb_set); $i < $total; $i += 100)
{
- $this->query($this->_insert_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), $this->qb_keys, array_slice($this->qb_set, $i, 100)));
+ $this->query($this->_insert_batch($this->protect_identifiers($table, TRUE, $escape, FALSE), $this->qb_keys, array_slice($this->qb_set, $i, 100)));
$affected_rows += $this->affected_rows();
}
@@ -1260,13 +1444,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Insert_batch statement
+ * Insert batch statement
*
* Generates a platform-specific insert string from the supplied data.
*
- * @param string the table name
- * @param array the insert keys
- * @param array the insert values
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
* @return string
*/
protected function _insert_batch($table, $keys, $values)
@@ -1375,13 +1559,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*
* @param string the table to insert data into
* @param array an associative array of insert values
+ * @param bool $escape Whether to escape values and identifiers
* @return object
*/
- public function insert($table = '', $set = NULL)
+ public function insert($table = '', $set = NULL, $escape = NULL)
{
if ( ! is_null($set))
{
- $this->set($set);
+ $this->set($set, '', $escape);
}
if ($this->_validate_insert($table) === FALSE)
@@ -1391,7 +1576,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$sql = $this->_insert(
$this->protect_identifiers(
- $this->qb_from[0], TRUE, NULL, FALSE
+ $this->qb_from[0], TRUE, $escape, FALSE
),
array_keys($this->qb_set),
array_values($this->qb_set)
@@ -1539,14 +1724,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// --------------------------------------------------------------------
/**
- * Update
+ * UPDATE
*
- * Compiles an update string and runs the query
+ * Compiles an update string and runs the query.
*
- * @param string $table = ''
- * @param array $set = NULL an associative array of update values
- * @param mixed $where = NULL
- * @param int $limit = NULL
+ * @param string $table
+ * @param array $set An associative array of update values
+ * @param mixed $where
+ * @param int $limit
* @return object
*/
public function update($table = '', $set = NULL, $where = NULL, $limit = NULL)
@@ -1575,7 +1760,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
}
$sql = $this->_update($this->protect_identifiers($this->qb_from[0], TRUE, NULL, FALSE), $this->qb_set);
-
$this->_reset_write();
return $this->query($sql);
}
@@ -1980,7 +2164,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* Generates a query string based on which functions were used.
* Should not be called directly.
*
- * @param bool $select_override = FALSE
+ * @param bool $select_override
* @return string
*/
protected function _compile_select($select_override = FALSE)
@@ -2053,7 +2237,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* where(), or_where(), having(), or_having are called prior to from(),
* join() and dbprefix is added only if needed.
*
- * @param string 'qb_where' or 'qb_having'
+ * @param string $qb_key 'qb_where' or 'qb_having'
* @return string SQL statement
*/
protected function _compile_wh($qb_key)
@@ -2291,7 +2475,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
'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(),
@@ -2398,10 +2581,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
{
foreach ($qb_reset_items as $item => $default_value)
{
- if ( ! in_array($item, $this->qb_store_array))
- {
- $this->$item = $default_value;
- }
+ $this->$item = $default_value;
}
}
diff --git a/system/database/DB_result.php b/system/database/DB_result.php
index 76093f918..9d19075ba 100644
--- a/system/database/DB_result.php
+++ b/system/database/DB_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Database Result Class
@@ -38,19 +39,68 @@
*/
class CI_DB_result {
+ /**
+ * Connection ID
+ *
+ * @var resource|object
+ */
public $conn_id;
+
+ /**
+ * Result ID
+ *
+ * @var resource|object
+ */
public $result_id;
+
+ /**
+ * Result Array
+ *
+ * @var array[]
+ */
public $result_array = array();
+
+ /**
+ * Result Object
+ *
+ * @var object[]
+ */
public $result_object = array();
+
+ /**
+ * Custom Result Object
+ *
+ * @var object[]
+ */
public $custom_result_object = array();
+
+ /**
+ * Current Row index
+ *
+ * @var int
+ */
public $current_row = 0;
+
+ /**
+ * Number of rows
+ *
+ * @var int
+ */
public $num_rows;
+
+ /**
+ * Row data
+ *
+ * @var array
+ */
public $row_data;
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
- * @param object
+ * @param object $driver_object
* @return void
*/
public function __construct(&$driver_object)
@@ -89,7 +139,7 @@ class CI_DB_result {
/**
* Query result. Acts as a wrapper function for the following functions.
*
- * @param string 'object', 'array' or a custom class name
+ * @param string $type 'object', 'array' or a custom class name
* @return array
*/
public function result($type = 'object')
@@ -113,8 +163,8 @@ class CI_DB_result {
/**
* Custom query result.
*
- * @param string A string that represents the type of object you want back
- * @return array of objects
+ * @param string $class_name
+ * @return array
*/
public function custom_result_object($class_name)
{
@@ -249,10 +299,12 @@ class CI_DB_result {
// --------------------------------------------------------------------
/**
- * Query result. Acts as a wrapper function for the following functions.
+ * Row
+ *
+ * A wrapper method.
*
- * @param mixed $n = 0
- * @param string $type = 'object' 'object' or 'array'
+ * @param mixed $n
+ * @param string $type 'object' or 'array'
* @return mixed
*/
public function row($n = 0, $type = 'object')
@@ -339,7 +391,7 @@ class CI_DB_result {
/**
* Returns a single result row - object version
*
- * @param int $n = 0
+ * @param int $n
* @return object
*/
public function row_object($n = 0)
@@ -363,7 +415,7 @@ class CI_DB_result {
/**
* Returns a single result row - array version
*
- * @param int $n = 0
+ * @param int $n
* @return array
*/
public function row_array($n = 0)
@@ -387,7 +439,7 @@ class CI_DB_result {
/**
* Returns the "first" row
*
- * @param string $type = 'object'
+ * @param string $type
* @return mixed
*/
public function first_row($type = 'object')
@@ -401,7 +453,7 @@ class CI_DB_result {
/**
* Returns the "last" row
*
- * @param string $type = 'object'
+ * @param string $type
* @return mixed
*/
public function last_row($type = 'object')
@@ -415,7 +467,7 @@ class CI_DB_result {
/**
* Returns the "next" row
*
- * @param string $type = 'object'
+ * @param string $type
* @return mixed
*/
public function next_row($type = 'object')
@@ -439,7 +491,7 @@ class CI_DB_result {
/**
* Returns the "previous" row
*
- * @param string $type = 'object'
+ * @param string $type
* @return mixed
*/
public function previous_row($type = 'object')
@@ -462,7 +514,7 @@ class CI_DB_result {
/**
* Returns an unbuffered row and move pointer to next row
*
- * @param string $type = 'object' 'array', 'object' or a custom class name
+ * @param string $type 'array', 'object' or a custom class name
* @return mixed
*/
public function unbuffered_row($type = 'object')
@@ -482,7 +534,7 @@ class CI_DB_result {
// --------------------------------------------------------------------
/**
- * The following functions are normally overloaded by the identically named
+ * The following methods are normally overloaded by the identically named
* methods in the platform-specific driver -- except when query caching
* is used. When caching is enabled we do not load the other driver.
* These functions are primarily here to prevent undefined function errors
@@ -490,13 +542,118 @@ class CI_DB_result {
* operational due to the unavailability of the database resource IDs with
* cached results.
*/
- public function num_fields() { return 0; }
- public function list_fields() { return array(); }
- public function field_data() { return array(); }
- public function free_result() { $this->result_id = FALSE; }
- protected function _data_seek() { return FALSE; }
- protected function _fetch_assoc() { return array(); }
- protected function _fetch_object() { return array(); }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Number of fields in the result set
+ *
+ * Overriden by driver result classes.
+ *
+ * @return int
+ */
+ public function num_fields()
+ {
+ return 0;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch Field Names
+ *
+ * Generates an array of column names.
+ *
+ * Overriden by driver result classes.
+ *
+ * @return array
+ */
+ public function list_fields()
+ {
+ return array();
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field data
+ *
+ * Generates an array of objects containing field meta-data.
+ *
+ * Overriden by driver result classes.
+ *
+ * @return array
+ */
+ public function field_data()
+ {
+ return array();
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Free the result
+ *
+ * Overriden by driver result classes.
+ *
+ * @return void
+ */
+ public function free_result()
+ {
+ $this->result_id = FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Data Seek
+ *
+ * Moves the internal pointer to the desired offset. We call
+ * this internally before fetching results to make sure the
+ * result set starts at zero.
+ *
+ * Overriden by driver result classes.
+ *
+ * @param int $n
+ * @return bool
+ */
+ protected function _data_seek($n = 0)
+ {
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Result - associative array
+ *
+ * Returns the result set as an array.
+ *
+ * Overriden by driver result classes.
+ *
+ * @return array
+ */
+ protected function _fetch_assoc()
+ {
+ return array();
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Result - object
+ *
+ * Returns the result set as an object.
+ *
+ * Overriden by driver result classes.
+ *
+ * @param string $class_name
+ * @return object
+ */
+ protected function _fetch_object($class_name = 'stdClass')
+ {
+ return array();
+ }
}
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index 8078e2bf6..488ebf3ac 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Database Utility Class
@@ -32,25 +33,49 @@
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
*/
-abstract class CI_DB_utility extends CI_DB_forge {
+abstract class CI_DB_utility {
- public $db;
+ /**
+ * Database object
+ *
+ * @var object
+ */
+ protected $db;
+
+ // --------------------------------------------------------------------
- // Platform specific SQL strings
- // Just setting those defaults to FALSE as they are mostly MySQL-specific
+ /**
+ * List databases statement
+ *
+ * @var string
+ */
+ protected $_list_databases = FALSE;
+
+ /**
+ * OPTIMIZE TABLE statement
+ *
+ * @var string
+ */
protected $_optimize_table = FALSE;
+
+ /**
+ * REPAIR TABLE statement
+ *
+ * @var string
+ */
protected $_repair_table = FALSE;
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Class constructor
*
+ * @param object &$db Database object
* @return void
*/
- public function __construct()
+ public function __construct(&$db)
{
- // Assign the main database object to $this->db
- $CI =& get_instance();
- $this->db =& $CI->db;
+ $this->db =& $db;
log_message('debug', 'Database Utility Class Initialized');
}
@@ -70,7 +95,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
}
elseif ($this->_list_databases === FALSE)
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
}
$this->db->data_cache['db_names'] = array();
@@ -94,7 +119,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
/**
* Determine if a particular database exists
*
- * @param string
+ * @param string $database_name
* @return bool
*/
public function database_exists($database_name)
@@ -107,14 +132,14 @@ abstract class CI_DB_utility extends CI_DB_forge {
/**
* Optimize Table
*
- * @param string the table name
+ * @param string $table_name
* @return mixed
*/
public function optimize_table($table_name)
{
if ($this->_optimize_table === FALSE)
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
}
$query = $this->db->query(sprintf($this->_optimize_table, $this->db->escape_identifiers($table_name)));
@@ -138,7 +163,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
{
if ($this->_optimize_table === FALSE)
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
}
$result = array();
@@ -168,14 +193,14 @@ abstract class CI_DB_utility extends CI_DB_forge {
/**
* Repair Table
*
- * @param string the table name
+ * @param string $table_name
* @return mixed
*/
public function repair_table($table_name)
{
if ($this->_repair_table === FALSE)
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
}
$query = $this->db->query(sprintf($this->_repair_table, $this->db->escape_identifiers($table_name)));
@@ -193,10 +218,10 @@ abstract class CI_DB_utility extends CI_DB_forge {
/**
* Generate CSV from a query result object
*
- * @param object The query result object
- * @param string The delimiter - comma by default
- * @param string The newline character - \n by default
- * @param string The enclosure - double quote by default
+ * @param object $query Query result object
+ * @param string $delim Delimiter (default: ,)
+ * @param string $newline Newline character (default: \n)
+ * @param string $enclosure Enclosure (default: ")
* @return string
*/
public function csv_from_result($query, $delim = ',', $newline = "\n", $enclosure = '"')
@@ -233,8 +258,8 @@ abstract class CI_DB_utility extends CI_DB_forge {
/**
* Generate XML data from a query result object
*
- * @param object The query result object
- * @param array Any preferences
+ * @param object $query Query result object
+ * @param array $params Any preferences
* @return string
*/
public function xml_from_result($query, $params = array())
@@ -280,7 +305,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
/**
* Database Backup
*
- * @param array $params = array()
+ * @param array $params
* @return void
*/
public function backup($params = array())
@@ -293,8 +318,6 @@ abstract class CI_DB_utility extends CI_DB_forge {
$params = array('tables' => $params);
}
- // ------------------------------------------------------
-
// Set up our default preferences
$prefs = array(
'tables' => array(),
@@ -338,7 +361,7 @@ abstract class CI_DB_utility extends CI_DB_forge {
{
if ($this->db->db_debug)
{
- return $this->db->display_error('db_unsuported_compression');
+ return $this->db->display_error('db_unsupported_compression');
}
$prefs['format'] = 'txt';
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index 8e77d8396..c89a924d3 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.1
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CUBRID Database Adapter Class
@@ -40,18 +41,33 @@
*/
class CI_DB_cubrid_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'cubrid';
- // The character used for escaping - no need in CUBRID
- protected $_escape_char = '`';
+ /**
+ * Auto-commit flag
+ *
+ * @var bool
+ */
+ public $auto_commit = TRUE;
- protected $_random_keyword = ' RAND()'; // database specific random keyword
+ // --------------------------------------------------------------------
- // CUBRID-specific properties
- public $auto_commit = TRUE;
+ /**
+ * Identifier escape character
+ *
+ * @var string
+ */
+ protected $_escape_char = '`';
+
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* @param array $params
* @return void
@@ -113,7 +129,7 @@ class CI_DB_cubrid_driver extends CI_DB {
* Except for determining if a persistent connection should be used,
* the rest of the logic is the same for db_connect() and db_pconnect().
*
- * @param bool
+ * @param bool $persistent
* @return resource
*/
protected function _cubrid_connect($persistent = FALSE)
@@ -163,9 +179,18 @@ class CI_DB_cubrid_driver extends CI_DB {
*/
public function version()
{
- return isset($this->data_cache['version'])
- ? $this->data_cache['version']
- : $this->data_cache['version'] = cubrid_get_server_info($this->conn_id);
+ if (isset($this->data_cache['version']))
+ {
+ return $this->data_cache['version'];
+ }
+ elseif ( ! $this->conn_id)
+ {
+ $this->initialize();
+ }
+
+ return ( ! $this->conn_id OR ($version = cubrid_get_server_info($this->conn_id)) === FALSE)
+ ? FALSE
+ : $this->data_cache['version'] = $version;
}
// --------------------------------------------------------------------
@@ -173,7 +198,7 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return resource
*/
protected function _execute($sql)
@@ -186,7 +211,7 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -265,8 +290,8 @@ class CI_DB_cubrid_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -332,7 +357,7 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -354,7 +379,7 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -369,7 +394,7 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -399,9 +424,9 @@ class CI_DB_cubrid_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @param string the table name
- * @param array the update data
- * @param string the where key
+ * @param string $table Table name
+ * @param array $values Update data
+ * @param string $index WHERE key
* @return string
*/
protected function _update_batch($table, $values, $index)
diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php
index d328aa241..05762ba5a 100644
--- a/system/database/drivers/cubrid/cubrid_forge.php
+++ b/system/database/drivers/cubrid/cubrid_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.1
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CUBRID Forge Class
@@ -34,181 +35,175 @@
*/
class CI_DB_cubrid_forge extends CI_DB_forge {
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
protected $_create_database = FALSE;
+
+ /**
+ * CREATE TABLE keys flag
+ *
+ * Whether table keys are created from within the
+ * CREATE TABLE statement.
+ *
+ * @var bool
+ */
+ protected $_create_table_keys = TRUE;
+
+ /**
+ * DROP DATABASE statement
+ *
+ * @var string
+ */
protected $_drop_database = FALSE;
/**
- * Process Fields
+ * CREATE TABLE IF statement
*
- * @param mixed the fields
- * @return string
+ * @var string
+ */
+ protected $_create_table_if = FALSE;
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'SHORT' => 'INTEGER',
+ 'SMALLINT' => 'INTEGER',
+ 'INT' => 'BIGINT',
+ 'INTEGER' => 'BIGINT',
+ 'BIGINT' => 'NUMERIC',
+ 'FLOAT' => 'DOUBLE',
+ 'REAL' => 'DOUBLE'
+ );
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
*/
- protected function _process_fields($fields)
+ protected function _alter_table($alter_type, $table, $field)
{
- $current_field_count = 0;
- $sql = '';
+ if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
- foreach ($fields as $field => $attributes)
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ $sqls = array();
+ for ($i = 0, $c = count($field); $i < $c; $i++)
{
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
+ if ($field[$i]['_literal'] !== FALSE)
{
- $sql .= "\n\t".$attributes;
+ $sqls[] = $sql.' CHANGE '.$field[$i]['_literal'];
}
else
{
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field);
-
- empty($attributes['NAME']) OR $sql .= ' '.$this->db->escape_identifiers($attributes['NAME']).' ';
-
- if ( ! empty($attributes['TYPE']))
- {
- $sql .= ' '.$attributes['TYPE'];
-
- if ( ! empty($attributes['CONSTRAINT']))
- {
- switch (strtolower($attributes['TYPE']))
- {
- case 'decimal':
- case 'float':
- case 'numeric':
- $sql .= '('.implode(',', $attributes['CONSTRAINT']).')';
- break;
- case 'enum':
- // Will be supported in the future as part a part of
- // MySQL compatibility features.
- break;
- case 'set':
- $sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")';
- break;
- default:
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
- }
- }
-
- /* As of version 8.4.1 CUBRID does not support UNSIGNED INTEGER data type.
- * Will be supported in the next release as a part of MySQL Compatibility.
- *
- if (isset($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
- */
-
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
-
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
-
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
+ $sqls[] = $sql.' CHANGE '.$this->_process_column($field[$i]);
+ if ( ! empty($field[$i]['new_name']))
{
- $sql .= ' AUTO_INCREMENT';
+ $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
+ .' AS '.$this->db->escape_identifiers($field[$i]['name']);
}
-
- if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
- {
- $sql .= ' UNIQUE';
- }
- }
-
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
}
}
- return $sql;
+ return $sqls;
}
// --------------------------------------------------------------------
/**
- * Create Table
+ * Process column
*
- * @param string the table name
- * @param mixed the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @param array $field
+ * @return string
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ protected function _process_column($field)
{
- $sql = 'CREATE TABLE ';
+ $extra_clause = isset($field['after'])
+ ? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
- /* As of version 8.4.1 CUBRID does not support this SQL syntax.
- if ($if_not_exists === TRUE)
+ if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
{
- $sql .= 'IF NOT EXISTS ';
+ $extra_clause = ' FIRST';
}
- */
- $sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields);
+ return $this->db->escape_identifiers($field['name'])
+ .(empty($field['new_name']) ? '' : $this->db->escape_identifiers($field['new_name']))
+ .' '.$field['type'].$field['length']
+ .$field['unsigned']
+ .$field['null']
+ .$field['default']
+ .$field['auto_increment']
+ .$field['unique']
+ .$extra_clause;
+ }
- // If there is a PK defined
- if (count($primary_keys) > 0)
- {
- $key_name = $this->db->escape_identifiers('pk_'.$table.'_'.implode('_', $primary_keys));
- $sql .= ",\n\tCONSTRAINT ".$key_name.' PRIMARY KEY('.implode(', ', $this->db->escape_identifiers($primary_keys)).')';
- }
+ // --------------------------------------------------------------------
- if (is_array($keys) && count($keys) > 0)
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
{
- foreach ($keys as $key)
- {
- if (is_array($key))
- {
- $key_name = $this->db->escape_identifiers('idx_'.$table.implode('_', $key));
- $key = $this->db->escape_identifiers($key);
- }
- else
- {
- $key_name = $this->db->escape_identifiers('idx_'.$table.$key);
- $key = array($key_name);
- }
-
- $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')';
- }
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ default: return;
}
-
- return $sql."\n);";
}
// --------------------------------------------------------------------
/**
- * Alter table query
- *
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * Process indexes
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param array fields
- * @param string the field after which we should add the new field
+ * @param string $table (ignored)
* @return string
*/
- protected function _alter_table($alter_type, $table, $fields, $after_field = '')
+ protected function _process_indexes($table = NULL)
{
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' ';
+ $sql = '';
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
+ for ($i = 0, $c = count($this->keys); $i < $c; $i++)
{
- return $sql.$this->db->escape_identifiers($fields);
+ if ( ! isset($this->fields[$this->keys[$i]]))
+ {
+ unset($this->keys[$i]);
+ continue;
+ }
+
+ is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
+
+ $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
+ .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
}
- return $sql.$this->_process_fields($fields)
- .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
+ $this->keys = array();
+
+ return $sql;
}
}
diff --git a/system/database/drivers/cubrid/cubrid_result.php b/system/database/drivers/cubrid/cubrid_result.php
index 360c50dc2..30aed38d9 100644
--- a/system/database/drivers/cubrid/cubrid_result.php
+++ b/system/database/drivers/cubrid/cubrid_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.1
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CUBRID Result Class
@@ -130,9 +131,9 @@ class CI_DB_cubrid_result extends CI_DB_result {
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
- * result set starts at zero
+ * result set starts at zero.
*
- * @param int $n = 0
+ * @param int $n
* @return bool
*/
protected function _data_seek($n = 0)
@@ -161,7 +162,7 @@ class CI_DB_cubrid_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/cubrid/cubrid_utility.php b/system/database/drivers/cubrid/cubrid_utility.php
index ea8feb4e2..d76eca432 100644
--- a/system/database/drivers/cubrid/cubrid_utility.php
+++ b/system/database/drivers/cubrid/cubrid_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.1
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CUBRID Utility Class
@@ -62,7 +63,7 @@ class CI_DB_cubrid_utility extends CI_DB_utility {
// No SQL based support in CUBRID as of version 8.4.0. Database or
// table backup can be performed using CUBRID Manager
// database administration tool.
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/database/drivers/ibase/ibase_driver.php b/system/database/drivers/ibase/ibase_driver.php
index c3be519bf..fc1c28f31 100644
--- a/system/database/drivers/ibase/ibase_driver.php
+++ b/system/database/drivers/ibase/ibase_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Firebird/Interbase Database Adapter Class
@@ -40,15 +41,30 @@
*/
class CI_DB_ibase_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'ibase';
- // The character used to escape with
- protected $_escape_char = '"';
+ // --------------------------------------------------------------------
+
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
+ protected $_random_keyword = ' Random()';
- protected $_random_keyword = ' Random()'; // database specific random keyword
+ /**
+ * IBase Transaction status flag
+ *
+ * @var resource
+ */
+ protected $_ibase_trans;
- // Keeps track of the resource for the current transaction
- protected $trans;
+ // --------------------------------------------------------------------
/**
* Non-persistent database connection
@@ -103,7 +119,7 @@ class CI_DB_ibase_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return resource
*/
protected function _execute($sql)
@@ -116,7 +132,7 @@ class CI_DB_ibase_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -132,7 +148,7 @@ class CI_DB_ibase_driver extends CI_DB {
// even if the queries produce a successful result.
$this->_trans_failure = ($test_mode === TRUE);
- $this->trans = @ibase_trans($this->conn_id);
+ $this->_ibase_trans = @ibase_trans($this->conn_id);
return TRUE;
}
@@ -152,7 +168,7 @@ class CI_DB_ibase_driver extends CI_DB {
return TRUE;
}
- return @ibase_commit($this->trans);
+ return @ibase_commit($this->_ibase_trans);
}
// --------------------------------------------------------------------
@@ -170,7 +186,7 @@ class CI_DB_ibase_driver extends CI_DB {
return TRUE;
}
- return @ibase_rollback($this->trans);
+ return @ibase_rollback($this->_ibase_trans);
}
// --------------------------------------------------------------------
@@ -178,8 +194,8 @@ class CI_DB_ibase_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -239,7 +255,7 @@ class CI_DB_ibase_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -262,7 +278,7 @@ class CI_DB_ibase_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -277,7 +293,7 @@ class CI_DB_ibase_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -310,8 +326,8 @@ class CI_DB_ibase_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -327,10 +343,10 @@ class CI_DB_ibase_driver extends CI_DB {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -345,7 +361,7 @@ class CI_DB_ibase_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -357,11 +373,11 @@ class CI_DB_ibase_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/ibase/ibase_forge.php b/system/database/drivers/ibase/ibase_forge.php
index da75eb9c3..a0c4e6563 100644
--- a/system/database/drivers/ibase/ibase_forge.php
+++ b/system/database/drivers/ibase/ibase_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Interbase/Firebird Forge Class
@@ -34,12 +35,51 @@
*/
class CI_DB_ibase_forge extends CI_DB_forge {
- protected $_drop_table = 'DROP TABLE %s';
+ /**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = FALSE;
+
+ /**
+ * RENAME TABLE statement
+ *
+ * @var string
+ */
+ protected $_rename_table = FALSE;
+
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = FALSE;
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'SMALLINT' => 'INTEGER',
+ 'INTEGER' => 'INT64',
+ 'FLOAT' => 'DOUBLE PRECISION'
+ );
+
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
+
+ // --------------------------------------------------------------------
/**
* Create database
*
- * @param string the database name
+ * @param string $db_name
* @return string
*/
public function create_database($db_name)
@@ -57,8 +97,7 @@ class CI_DB_ibase_forge extends CI_DB_forge {
/**
* Drop database
*
- * @param string the database name
- * - not used in this driver, the current db is dropped
+ * @param string $db_name (ignored)
* @return bool
*/
public function drop_database($db_name = '')
@@ -82,110 +121,119 @@ class CI_DB_ibase_forge extends CI_DB_forge {
// --------------------------------------------------------------------
/**
- * Create Table
+ * ALTER TABLE
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return string
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
- {
- $sql = 'CREATE TABLE ';
-
- $sql .= $this->db->escape_identifiers($table).'(';
- $current_field_count = 0;
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
- foreach ($fields as $field => $attributes)
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ $sqls = array();
+ for ($i = 0, $c = count($field), $sql .= $alter_type.' '; $i < $c; $i++)
{
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
+ if ($field[$i]['_literal'] !== FALSE)
{
- $sql .= "\n\t".$attributes;
+ return FALSE;
}
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
-
- empty($attributes['CONSTRAINT']) OR $sql .= '('.$attributes['CONSTRAINT'].')';
-
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
-
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
-
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
+ if (isset($field[$i]['type']))
+ {
+ $sqls[] = $sql.' TYPE '.$field[$i]['type'].$field[$i]['length'];
}
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
+ if ( ! empty($field[$i]['default']))
{
- $sql .= ',';
+ $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
+ .' SET '.$field[$i]['default'];
}
- }
- if (count($primary_keys) > 0)
- {
- $primary_keys = $this->db->escape_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')';
- }
-
- if (is_array($keys) && count($keys) > 0)
- {
- foreach ($keys as $key)
+ if (isset($field[$i]['null']))
{
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->db->escape_identifiers($key));
+ $sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = '
+ .($field[$i]['null'] === TRUE ? 'NULL' : '1')
+ .' WHERE "RDB$FIELD_NAME" = '.$this->db->escape($field[$i]['name'])
+ .' AND "RDB$RELATION_NAME" = '.$this->db->escape($table);
+ }
- $sql .= ",\n\tUNIQUE (".implode(', ', $key).')';
+ if ( ! empty($field[$i]['new_name']))
+ {
+ $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
+ .' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
}
}
- return $sql."\n)";
+ return $sqls;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ return $this->db->escape_identifiers($field['name'])
+ .' '.$field['type'].$field['length']
+ .$field['null']
+ .$field['unique']
+ .$field['default'];
}
// --------------------------------------------------------------------
/**
- * Alter table query
+ * Field attribute TYPE
*
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * Performs a data type mapping between different databases.
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param string the table name
- * @param string the column definition
- * @param string the default value
- * @param bool should 'NOT NULL' be added
- * @param string the field after which we should add the new field
- * @return string
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'INT':
+ $attributes['TYPE'] = 'INTEGER';
+ return;
+ case 'BIGINT':
+ $attributes['TYPE'] = 'INT64';
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
*/
- protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ protected function _attr_auto_increment(&$attributes, &$field)
{
- return 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name)
- .' '.$column_definition
- .($default_value !== '' ? ' DEFAULT "'.$default_value.'"' : '')
- .($null === NULL ? ' NULL' : ' NOT NULL')
- .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
+ // Not supported
}
}
diff --git a/system/database/drivers/ibase/ibase_result.php b/system/database/drivers/ibase/ibase_result.php
index 95e55710b..bbad9d895 100644
--- a/system/database/drivers/ibase/ibase_result.php
+++ b/system/database/drivers/ibase/ibase_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Interbase/Firebird Result Class
@@ -128,7 +129,7 @@ class CI_DB_ibase_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/ibase/ibase_utility.php b/system/database/drivers/ibase/ibase_utility.php
index d0e84a7b2..5eb209ae1 100644
--- a/system/database/drivers/ibase/ibase_utility.php
+++ b/system/database/drivers/ibase/ibase_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Interbase/Firebird Utility Class
@@ -34,10 +35,8 @@
*/
class CI_DB_ibase_utility extends CI_DB_utility {
- protected $_list_databases = FALSE;
-
/**
- * Interbase/Firebird Export
+ * Export
*
* @param string $filename
* @return mixed
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 2063dad90..a9d53fb57 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MS SQL Database Adapter Class
@@ -40,18 +41,36 @@
*/
class CI_DB_mssql_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'mssql';
- // The character used for escaping
- protected $_escape_char = '"';
+ // --------------------------------------------------------------------
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
protected $_random_keyword = ' NEWID()';
- // MSSQL-specific properties
+ /**
+ * Quoted identifier flag
+ *
+ * Whether to use SQL-92 standard quoted identifier
+ * (double quotes) or brackets for identifier escaping.
+ *
+ * @var bool
+ */
protected $_quoted_identifier = TRUE;
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Class constructor
*
* Appends the port number to the hostname, if needed.
*
@@ -73,7 +92,7 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Non-persistent database connection
*
- * @param bool
+ * @param bool $persistent
* @return resource
*/
public function db_connect($persistent = FALSE)
@@ -113,7 +132,7 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Select the database
*
- * @param string database name
+ * @param string $database
* @return bool
*/
public function db_select($database = '')
@@ -139,7 +158,7 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return mixed resource if rows are returned, bool otherwise
*/
protected function _execute($sql)
@@ -152,7 +171,7 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -212,8 +231,8 @@ class CI_DB_mssql_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -295,7 +314,7 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -320,7 +339,7 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -335,7 +354,7 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -367,8 +386,8 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -385,10 +404,10 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -403,7 +422,7 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -419,11 +438,11 @@ class CI_DB_mssql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
@@ -470,6 +489,29 @@ class CI_DB_mssql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
+ * Insert batch statement
+ *
+ * Generates a platform-specific insert string from the supplied data.
+ *
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
+ * @return string|bool
+ */
+ protected function _insert_batch($table, $keys, $values)
+ {
+ // Multiple-value inserts are only supported as of SQL Server 2008
+ if (version_compare($this->version(), '10', '>='))
+ {
+ return parent::_insert_batch($table, $keys, $values);
+ }
+
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Close DB Connection
*
* @return void
diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php
index 3a3528f7b..5eebedbf7 100644
--- a/system/database/drivers/mssql/mssql_forge.php
+++ b/system/database/drivers/mssql/mssql_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MS SQL Forge Class
@@ -34,124 +35,99 @@
*/
class CI_DB_mssql_forge extends CI_DB_forge {
- protected $_drop_table = 'DROP TABLE %s';
-
/**
- * Create Table
+ * CREATE TABLE IF statement
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return string
+ * @var string
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
- {
- $sql = ($if_not_exists === TRUE)
- ? "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'".$table."') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\n"
- : '';
-
- $sql .= 'CREATE TABLE '.$this->db->escape_identifiers($table).' (';
-
- $current_field_count = 0;
- foreach ($fields as $field => $attributes)
- {
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
- {
- $sql .= "\n\t".$attributes;
- }
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
-
- if (stripos($attributes['TYPE'], 'INT') === FALSE && ! empty($attributes['CONSTRAINT']))
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
-
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
+ protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE";
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
-
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE";
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
- }
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'TINYINT' => 'SMALLINT',
+ 'SMALLINT' => 'INT',
+ 'INT' => 'BIGINT',
+ 'REAL' => 'FLOAT'
+ );
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
- }
- }
+ // --------------------------------------------------------------------
- if (count($primary_keys) > 0)
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
{
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
+ return parent::_alter_table($alter_type, $table, $field);
}
- if (is_array($keys) && count($keys) > 0)
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN ';
+ $sqls = array();
+ for ($i = 0, $c = count($field); $i < $c; $i++)
{
- foreach ($keys as $key)
- {
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->db->escape_identifiers($key));
-
- $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
- }
+ $sqls[] = $sql.$this->_process_column($field[$i]);
}
- return $sql."\n)";
+ return $sqls;
}
// --------------------------------------------------------------------
/**
- * Alter table query
+ * Field attribute TYPE
*
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * Performs a data type mapping between different databases.
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param string the table name
- * @param string the column definition
- * @param string the default value
- * @param bool should 'NOT NULL' be added
- * @param string the field after which we should add the new field
- * @return string
+ * @param array &$attributes
+ * @return void
*/
- protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ protected function _attr_type(&$attributes)
{
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name);
-
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
+ switch (strtoupper($attributes['TYPE']))
{
- return $sql;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'INTEGER':
+ $attributes['TYPE'] = 'INT';
+ return;
+ default: return;
}
+ }
- return $sql.' '.$column_definition
- .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '')
- .($null === NULL ? ' NULL' : ' NOT NULL')
- .($after_field != '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
+ {
+ $field['auto_increment'] = ' IDENTITY(1,1)';
+ }
}
}
diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php
index 84d2814f1..c74c70abf 100644
--- a/system/database/drivers/mssql/mssql_result.php
+++ b/system/database/drivers/mssql/mssql_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MSSQL Result Class
@@ -131,9 +132,9 @@ class CI_DB_mssql_result extends CI_DB_result {
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
- * result set starts at zero
+ * result set starts at zero.
*
- * @param int $n = 0
+ * @param int $n
* @return bool
*/
protected function _data_seek($n = 0)
@@ -162,7 +163,7 @@ class CI_DB_mssql_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php
index 69fcec5f6..76c7cb9c2 100644
--- a/system/database/drivers/mssql/mssql_utility.php
+++ b/system/database/drivers/mssql/mssql_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MS SQL Utility Class
@@ -34,19 +35,30 @@
*/
class CI_DB_mssql_utility extends CI_DB_utility {
+ /**
+ * List databases statement
+ *
+ * @var string
+ */
protected $_list_databases = 'EXEC sp_helpdb'; // Can also be: EXEC sp_databases
+
+ /**
+ * OPTIMIZE TABLE statement
+ *
+ * @var string
+ */
protected $_optimize_table = 'ALTER INDEX all ON %s REORGANIZE';
/**
- * MSSQL Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return bool
*/
protected function _backup($params = array())
{
// Currently unsupported
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index f82e775e6..b1edc2925 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MySQL Database Adapter Class
@@ -40,25 +41,46 @@
*/
class CI_DB_mysql_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'mysql';
- public $compress = FALSE;
- // The character used for escaping
- protected $_escape_char = '`';
-
- protected $_random_keyword = ' RAND()'; // database specific random keyword
+ /**
+ * Compression flag
+ *
+ * @var bool
+ */
+ public $compress = FALSE;
/**
+ * DELETE hack flag
+ *
* Whether to use the MySQL "delete hack" which allows the number
* of affected rows to be shown. Uses a preg_replace when enabled,
* adding a bit more processing to all queries.
+ *
+ * @var bool
*/
public $delete_hack = TRUE;
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Identifier escape character
*
- * @param array
+ * @var string
+ */
+ protected $_escape_char = '`';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -76,7 +98,7 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Non-persistent database connection
*
- * @param bool
+ * @param bool $persistent
* @return resource
*/
public function db_connect($persistent = FALSE)
@@ -128,7 +150,7 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Select the database
*
- * @param string database name
+ * @param string $database
* @return bool
*/
public function db_select($database = '')
@@ -152,7 +174,7 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Set client character set
*
- * @param string
+ * @param string $charset
* @return bool
*/
protected function _db_set_charset($charset)
@@ -169,9 +191,21 @@ class CI_DB_mysql_driver extends CI_DB {
*/
public function version()
{
- return isset($this->data_cache['version'])
- ? $this->data_cache['version']
- : $this->data_cache['version'] = @mysql_get_server_info($this->conn_id);
+ if (isset($this->data_cache['version']))
+ {
+ return $this->data_cache['version'];
+ }
+ elseif ( ! $this->conn_id)
+ {
+ $this->initialize();
+ }
+
+ if ( ! $this->conn_id OR ($version = @mysql_get_server_info($this->conn_id)) === FALSE)
+ {
+ return FALSE;
+ }
+
+ return $this->data_cache['version'] = $version;
}
// --------------------------------------------------------------------
@@ -179,7 +213,7 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return mixed
*/
protected function _execute($sql)
@@ -194,7 +228,7 @@ class CI_DB_mysql_driver extends CI_DB {
*
* If needed, each database adapter can prep the query string
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return string
*/
protected function _prep_query($sql)
@@ -214,7 +248,7 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -280,8 +314,8 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -340,7 +374,7 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -362,7 +396,7 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -375,7 +409,7 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Returns an object with field data
*
- * @param string the table name
+ * @param string $table
* @return object
*/
public function field_data($table = '')
@@ -426,9 +460,9 @@ class CI_DB_mysql_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @param string the table name
- * @param array the update data
- * @param string the where key
+ * @param string $table Table name
+ * @param array $values Update data
+ * @param string $index WHERE key
* @return string
*/
protected function _update_batch($table, $values, $index)
diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php
index 2ac75bad2..6c5dfc665 100644
--- a/system/database/drivers/mysql/mysql_forge.php
+++ b/system/database/drivers/mysql/mysql_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MySQL Forge Class
@@ -34,165 +35,167 @@
*/
class CI_DB_mysql_forge extends CI_DB_forge {
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s';
/**
- * Process Fields
+ * CREATE TABLE keys flag
*
- * @param mixed the fields
- * @return string
+ * Whether table keys are created from within the
+ * CREATE TABLE statement.
+ *
+ * @var bool
*/
- protected function _process_fields($fields)
- {
- $current_field_count = 0;
- $sql = '';
-
- foreach ($fields as $field => $attributes)
- {
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
- {
- $sql .= "\n\t".$attributes;
- }
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field);
-
- empty($attributes['NAME']) OR $sql .= ' '.$this->db->escape_identifiers($attributes['NAME']).' ';
-
- if ( ! empty($attributes['TYPE']))
- {
- $sql .= ' '.$attributes['TYPE'];
-
- if ( ! empty($attributes['CONSTRAINT']))
- {
- switch (strtolower($attributes['TYPE']))
- {
- case 'decimal':
- case 'float':
- case 'numeric':
- $sql .= '('.implode(',', $attributes['CONSTRAINT']).')';
- break;
- case 'enum':
- case 'set':
- $sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")';
- break;
- default:
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
- }
- }
+ protected $_create_table_keys = TRUE;
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'TINYINT',
+ 'SMALLINT',
+ 'MEDIUMINT',
+ 'INT',
+ 'INTEGER',
+ 'BIGINT',
+ 'REAL',
+ 'DOUBLE',
+ 'DOUBLE PRECISION',
+ 'FLOAT',
+ 'DECIMAL',
+ 'NUMERIC'
+ );
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
- }
+ // --------------------------------------------------------------------
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
- }
- }
+ /**
+ * Class constructor
+ *
+ * @param object &$db Database object
+ * @return void
+ */
+ public function __construct(&$db)
+ {
+ parent::__construct($db);
- return $sql;
+ $this->_create_table .= ' DEFAULT CHARSET '.$this->db->char_set.' COLLATE '.$this->db->dbcollat;
}
// --------------------------------------------------------------------
/**
- * Create Table
+ * ALTER TABLE
*
- * @param string the table name
- * @param mixed the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ protected function _alter_table($alter_type, $table, $field)
{
- $sql = 'CREATE TABLE ';
-
- if ($if_not_exists === TRUE)
- {
- $sql .= 'IF NOT EXISTS ';
- }
-
- $sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields);
-
- if (count($primary_keys) > 0)
+ if ($alter_type === 'DROP')
{
- $key_name = $this->db->escape_identifiers(implode('_', $primary_keys));
- $sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->escape_identifiers($primary_keys)).')';
+ return parent::_alter_table($alter_type, $table, $field);
}
- if (is_array($keys) && count($keys) > 0)
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ for ($i = 0, $c = count($field); $i < $c; $i++)
{
- foreach ($keys as $key)
+ if ($field[$i]['_literal'] !== FALSE)
{
- if (is_array($key))
+ $field[$i] = ($alter_type === 'ADD')
+ ? "\n\tADD ".$field[$i]['_literal']
+ : "\n\tMODIFY ".$field[$i]['_literal'];
+ }
+ else
+ {
+ if ($alter_type === 'ADD')
{
- $key_name = $this->db->escape_identifiers(implode('_', $key));
- $key = $this->db->escape_identifiers($key);
+ $field[$i]['_literal'] = "\n\tADD ";
}
else
{
- $key_name = $this->db->escape_identifiers($key);
- $key = array($key_name);
+ $field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE ";
}
- $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')';
+ $field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]);
}
}
- return $sql."\n) DEFAULT CHARACTER SET ".$this->db->char_set.' COLLATE '.$this->db->dbcollat.';';
+ return array($sql.implode(',', $field));
}
// --------------------------------------------------------------------
/**
- * Alter table query
+ * Process column
*
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column() and column_alter()
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ $extra_clause = isset($field['after'])
+ ? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
+
+ if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
+ {
+ $extra_clause = ' FIRST';
+ }
+
+ return $this->db->escape_identifiers($field['name'])
+ .(empty($field['new_name']) ? '' : $this->db->escape_identifiers($field['new_name']))
+ .' '.$field['type'].$field['length']
+ .$field['unsigned']
+ .$field['null']
+ .$field['default']
+ .$field['auto_increment']
+ .$field['unique']
+ .$extra_clause;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process indexes
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param array fields
- * @param string the field after which we should add the new field
+ * @param string $table (ignored)
* @return string
*/
- protected function _alter_table($alter_type, $table, $fields, $after_field = '')
+ protected function _process_indexes($table = NULL)
{
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' ';
+ $sql = '';
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
+ for ($i = 0, $c = count($this->keys); $i < $c; $i++)
{
- return $sql.$this->db->escape_identifiers($fields);
+ if ( ! isset($this->fields[$this->keys[$i]]))
+ {
+ unset($this->keys[$i]);
+ continue;
+ }
+
+ is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
+
+ $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
+ .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
}
- return $sql.$this->_process_fields($fields)
- .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
+ $this->keys = array();
+
+ return $sql;
}
}
diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php
index b3f669e40..4bfa0ae35 100644
--- a/system/database/drivers/mysql/mysql_result.php
+++ b/system/database/drivers/mysql/mysql_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MySQL Result Class
@@ -38,9 +39,9 @@
class CI_DB_mysql_result extends CI_DB_result {
/**
- * Constructor
+ * Class constructor
*
- * @param object
+ * @param object &$driver_object
* @return void
*/
public function __construct(&$driver_object)
@@ -144,9 +145,9 @@ class CI_DB_mysql_result extends CI_DB_result {
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
- * result set starts at zero
+ * result set starts at zero.
*
- * @param int $n = 0
+ * @param int $n
* @return bool
*/
protected function _data_seek($n = 0)
@@ -177,7 +178,7 @@ class CI_DB_mysql_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php
index f0bbc665e..8aa051755 100644
--- a/system/database/drivers/mysql/mysql_utility.php
+++ b/system/database/drivers/mysql/mysql_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MySQL Utility Class
@@ -34,14 +35,33 @@
*/
class CI_DB_mysql_utility extends CI_DB_utility {
+ /**
+ * List databases statement
+ *
+ * @var string
+ */
protected $_list_databases = 'SHOW DATABASES';
+
+ /**
+ * OPTIMIZE TABLE statement
+ *
+ * @var string
+ */
protected $_optimize_table = 'OPTIMIZE TABLE %s';
+
+ /**
+ * REPAIR TABLE statement
+ *
+ * @var string
+ */
protected $_repair_table = 'REPAIR TABLE %s';
+ // --------------------------------------------------------------------
+
/**
- * MySQL Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return mixed
*/
protected function _backup($params = array())
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index 6c4f87513..ae17703ac 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MySQLi Database Adapter Class
@@ -40,25 +41,46 @@
*/
class CI_DB_mysqli_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'mysqli';
- public $compress = FALSE;
- // The character used for escaping
- protected $_escape_char = '`';
-
- protected $_random_keyword = ' RAND()'; // database specific random keyword
+ /**
+ * Compression flag
+ *
+ * @var bool
+ */
+ public $compress = FALSE;
/**
+ * DELETE hack flag
+ *
* Whether to use the MySQL "delete hack" which allows the number
* of affected rows to be shown. Uses a preg_replace when enabled,
* adding a bit more processing to all queries.
+ *
+ * @var bool
*/
public $delete_hack = TRUE;
+ // --------------------------------------------------------------------
+
/**
- * Non-persistent database connection
+ * Identifier escape character
*
- * @param bool
+ * @var string
+ */
+ protected $_escape_char = '`';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Database connection
+ *
+ * @param bool $persistent
* @return object
* @todo SSL support
*/
@@ -110,7 +132,7 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Select the database
*
- * @param string database name
+ * @param string $database
* @return bool
*/
public function db_select($database = '')
@@ -134,7 +156,7 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Set client character set
*
- * @param string
+ * @param string $charset
* @return bool
*/
protected function _db_set_charset($charset)
@@ -151,9 +173,16 @@ class CI_DB_mysqli_driver extends CI_DB {
*/
public function version()
{
- return isset($this->data_cache['version'])
- ? $this->data_cache['version']
- : $this->data_cache['version'] = $this->conn_id->server_info;
+ if (isset($this->data_cache['version']))
+ {
+ return $this->data_cache['version'];
+ }
+ elseif ( ! $this->conn_id)
+ {
+ $this->initialize();
+ }
+
+ return $this->data_cache['version'] = $this->conn_id->server_info;
}
// --------------------------------------------------------------------
@@ -161,7 +190,7 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return mixed
*/
protected function _execute($sql)
@@ -176,7 +205,7 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* If needed, each database adapter can prep the query string
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return string
*/
protected function _prep_query($sql)
@@ -196,7 +225,7 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -262,8 +291,8 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -322,7 +351,7 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -344,7 +373,7 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -357,7 +386,7 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Returns an object with field data
*
- * @param string the table name
+ * @param string $table
* @return object
*/
public function field_data($table = '')
@@ -416,9 +445,9 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @param string the table name
- * @param array the update data
- * @param string the where key
+ * @param string $table Table name
+ * @param array $values Update data
+ * @param string $index WHERE key
* @return string
*/
protected function _update_batch($table, $values, $index)
diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php
index b74c775b2..a70eef88f 100644
--- a/system/database/drivers/mysqli/mysqli_forge.php
+++ b/system/database/drivers/mysqli/mysqli_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MySQLi Forge Class
@@ -34,165 +35,167 @@
*/
class CI_DB_mysqli_forge extends CI_DB_forge {
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s';
/**
- * Process Fields
+ * CREATE TABLE keys flag
*
- * @param mixed the fields
- * @return string
+ * Whether table keys are created from within the
+ * CREATE TABLE statement.
+ *
+ * @var bool
*/
- protected function _process_fields($fields)
- {
- $current_field_count = 0;
- $sql = '';
-
- foreach ($fields as $field => $attributes)
- {
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
- {
- $sql .= "\n\t".$attributes;
- }
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field);
-
- empty($attributes['NAME']) OR $sql .= ' '.$this->db->escape_identifiers($attributes['NAME']).' ';
-
- if ( ! empty($attributes['TYPE']))
- {
- $sql .= ' '.$attributes['TYPE'];
-
- if ( ! empty($attributes['CONSTRAINT']))
- {
- switch (strtolower($attributes['TYPE']))
- {
- case 'decimal':
- case 'float':
- case 'numeric':
- $sql .= '('.implode(',', $attributes['CONSTRAINT']).')';
- break;
- case 'enum':
- case 'set':
- $sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")';
- break;
- default:
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
- }
- }
+ protected $_create_table_keys = TRUE;
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'TINYINT',
+ 'SMALLINT',
+ 'MEDIUMINT',
+ 'INT',
+ 'INTEGER',
+ 'BIGINT',
+ 'REAL',
+ 'DOUBLE',
+ 'DOUBLE PRECISION',
+ 'FLOAT',
+ 'DECIMAL',
+ 'NUMERIC'
+ );
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
- }
+ // --------------------------------------------------------------------
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
- }
- }
+ /**
+ * Class constructor
+ *
+ * @param object &$db Database object
+ * @return void
+ */
+ public function __construct(&$db)
+ {
+ parent::__construct($db);
- return $sql;
+ $this->_create_table .= ' DEFAULT CHARSET '.$this->db->char_set.' COLLATE '.$this->db->dbcollat;
}
// --------------------------------------------------------------------
/**
- * Create Table
+ * ALTER TABLE
*
- * @param string the table name
- * @param mixed the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ protected function _alter_table($alter_type, $table, $field)
{
- $sql = 'CREATE TABLE ';
-
- if ($if_not_exists === TRUE)
- {
- $sql .= 'IF NOT EXISTS ';
- }
-
- $sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields);
-
- if (count($primary_keys) > 0)
+ if ($alter_type === 'DROP')
{
- $key_name = $this->db->escape_identifiers(implode('_', $primary_keys));
- $sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->escape_identifiers($primary_keys)).')';
+ return parent::_alter_table($alter_type, $table, $field);
}
- if (is_array($keys) && count($keys) > 0)
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ for ($i = 0, $c = count($field); $i < $c; $i++)
{
- foreach ($keys as $key)
+ if ($field[$i]['_literal'] !== FALSE)
{
- if (is_array($key))
+ $field[$i] = ($alter_type === 'ADD')
+ ? "\n\tADD ".$field[$i]['_literal']
+ : "\n\tMODIFY ".$field[$i]['_literal'];
+ }
+ else
+ {
+ if ($alter_type === 'ADD')
{
- $key_name = $this->db->escape_identifiers(implode('_', $key));
- $key = $this->db->escape_identifiers($key);
+ $field[$i]['_literal'] = "\n\tADD ";
}
else
{
- $key_name = $this->db->escape_identifiers($key);
- $key = array($key_name);
+ $field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE ";
}
- $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')';
+ $field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]);
}
}
- return $sql."\n) DEFAULT CHARACTER SET ".$this->db->char_set.' COLLATE '.$this->db->dbcollat.';';
+ return array($sql.implode(',', $field));
}
// --------------------------------------------------------------------
/**
- * Alter table query
+ * Process column
*
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ $extra_clause = isset($field['after'])
+ ? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
+
+ if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
+ {
+ $extra_clause = ' FIRST';
+ }
+
+ return $this->db->escape_identifiers($field['name'])
+ .(empty($field['new_name']) ? '' : $this->db->escape_identifiers($field['new_name']))
+ .' '.$field['type'].$field['length']
+ .$field['unsigned']
+ .$field['null']
+ .$field['default']
+ .$field['auto_increment']
+ .$field['unique']
+ .$extra_clause;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process indexes
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param array fields
- * @param string the field after which we should add the new field
+ * @param string $table (ignored)
* @return string
*/
- protected function _alter_table($alter_type, $table, $fields, $after_field = '')
+ protected function _process_indexes($table = NULL)
{
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' ';
+ $sql = '';
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
+ for ($i = 0, $c = count($this->keys); $i < $c; $i++)
{
- return $sql.$this->db->escape_identifiers($fields);
+ if ( ! isset($this->fields[$this->keys[$i]]))
+ {
+ unset($this->keys[$i]);
+ continue;
+ }
+
+ is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
+
+ $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
+ .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
}
- return $sql.$this->_process_fields($fields)
- .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
+ $this->keys = array();
+
+ return $sql;
}
}
diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php
index f036302bb..15e15cd5f 100644
--- a/system/database/drivers/mysqli/mysqli_result.php
+++ b/system/database/drivers/mysqli/mysqli_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MySQLi Result Class
@@ -130,9 +131,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
- * result set starts at zero
+ * result set starts at zero.
*
- * @param int $n = 0
+ * @param int $n
* @return bool
*/
protected function _data_seek($n = 0)
@@ -161,7 +162,7 @@ class CI_DB_mysqli_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php
index 5d2bdbce0..345691e84 100644
--- a/system/database/drivers/mysqli/mysqli_utility.php
+++ b/system/database/drivers/mysqli/mysqli_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MySQLi Utility Class
@@ -34,14 +35,33 @@
*/
class CI_DB_mysqli_utility extends CI_DB_utility {
+ /**
+ * List databases statement
+ *
+ * @var string
+ */
protected $_list_databases = 'SHOW DATABASES';
+
+ /**
+ * OPTIMIZE TABLE statement
+ *
+ * @var string
+ */
protected $_optimize_table = 'OPTIMIZE TABLE %s';
+
+ /**
+ * REPAIR TABLE statement
+ *
+ * @var string
+ */
protected $_repair_table = 'REPAIR TABLE %s';
+ // --------------------------------------------------------------------
+
/**
- * MySQLi Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return mixed
*/
protected function _backup($params = array())
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index 81d73d073..eb01dd17e 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* oci8 Database Adapter Class
@@ -49,34 +50,76 @@
*/
class CI_DB_oci8_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'oci8';
- // The character used for excaping
- protected $_escape_char = '"';
+ /**
+ * Statement ID
+ *
+ * @var resource
+ */
+ public $stmt_id;
/**
- * The syntax to count rows is slightly different across different
- * database engines, so this string appears in each driver and is
- * used for the count_all() and count_all_results() functions.
+ * Cursor ID
+ *
+ * @var resource
*/
- protected $_count_string = 'SELECT COUNT(1) AS ';
- protected $_random_keyword = ' ASC'; // not currently supported
+ public $curs_id;
+
+ /**
+ * Commit mode flag
+ *
+ * @var int
+ */
+ public $commit_mode = OCI_COMMIT_ON_SUCCESS;
+ /**
+ * Limit used flag
+ *
+ * If we use LIMIT, we'll add a field that will
+ * throw off num_fields later.
+ *
+ * @var bool
+ */
+ public $limit_used;
+
+ // --------------------------------------------------------------------
+
+ /**
+ * List of reserved identifiers
+ *
+ * Identifiers that must NOT be escaped.
+ *
+ * @var string[]
+ */
protected $_reserved_identifiers = array('*', 'rownum');
- // Set "auto commit" by default
- public $commit_mode = OCI_COMMIT_ON_SUCCESS;
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
+ protected $_random_keyword = ' ASC'; // not currently supported
- // need to track statement id and cursor id
- public $stmt_id;
- public $curs_id;
+ /**
+ * COUNT string
+ *
+ * @used-by CI_DB_driver::count_all()
+ * @used-by CI_DB_query_builder::count_all_results()
+ *
+ * @var string
+ */
+ protected $_count_string = 'SELECT COUNT(1) AS ';
- // if we use a limit, we will add a field that will
- // throw off num_fields later
- public $limit_used;
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* @param array $params
* @return void
@@ -197,9 +240,21 @@ class CI_DB_oci8_driver extends CI_DB {
*/
public function version()
{
- return isset($this->data_cache['version'])
- ? $this->data_cache['version']
- : $this->data_cache['version'] = oci_server_version($this->conn_id);
+ if (isset($this->data_cache['version']))
+ {
+ return $this->data_cache['version'];
+ }
+ elseif ( ! $this->conn_id)
+ {
+ $this->initialize();
+ }
+
+ if ( ! $this->conn_id OR ($version = oci_server_version($this->conn_id)) === FALSE)
+ {
+ return FALSE;
+ }
+
+ return $this->data_cache['version'] = $version;
}
// --------------------------------------------------------------------
@@ -207,7 +262,7 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return resource
*/
protected function _execute($sql)
@@ -226,7 +281,7 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Generate a statement ID
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return void
*/
protected function _set_stmt_id($sql)
@@ -306,7 +361,7 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Bind parameters
*
- * @param array
+ * @param array $params
* @return void
*/
protected function _bind_params($params)
@@ -335,7 +390,7 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -408,8 +463,8 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -469,7 +524,7 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -492,7 +547,7 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -507,7 +562,7 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -549,13 +604,13 @@ class CI_DB_oci8_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Insert_batch statement
+ * Insert batch statement
*
* Generates a platform-specific insert string from the supplied data
*
- * @param string the table name
- * @param array the insert keys
- * @param array the insert values
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
* @return string
*/
protected function _insert_batch($table, $keys, $values)
@@ -578,10 +633,10 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -596,7 +651,7 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -613,11 +668,11 @@ class CI_DB_oci8_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php
index 92e8c02ed..bd9d2df3c 100644
--- a/system/database/drivers/oci8/oci8_forge.php
+++ b/system/database/drivers/oci8/oci8_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Oracle Forge Class
@@ -34,122 +35,96 @@
*/
class CI_DB_oci8_forge extends CI_DB_forge {
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
protected $_create_database = FALSE;
+
+ /**
+ * DROP DATABASE statement
+ *
+ * @var string
+ */
protected $_drop_database = FALSE;
- protected $_drop_table = 'DROP TABLE %s';
/**
- * Create Table
+ * DROP TABLE IF statement
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return string
+ * @var string
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
- {
- $sql = 'CREATE TABLE ';
+ protected $_drop_table_if = FALSE;
+
+ /**
+ * UNSIGNED support
+ *
+ * @var bool|array
+ */
+ protected $_unsigned = FALSE;
- if ($if_not_exists === TRUE)
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if ($alter_type === 'DROP')
{
- $sql .= 'IF NOT EXISTS ';
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+ elseif ($alter_type === 'CHANGE')
+ {
+ $alter_type = 'MODIFY';
}
- $sql .= $this->db->escape_identifiers($table).' (';
- $current_field_count = 0;
-
- foreach ($fields as $field => $attributes)
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ $sqls = array();
+ for ($i = 0, $c = count($field); $i < $c; $i++)
{
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
+ if ($field[$i]['_literal'] !== FALSE)
{
- $sql .= "\n\t".$attributes;
+ $field[$i] = "\n\t".$field[$i]['_literal'];
}
else
{
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
-
- if (isset($attributes['UNSINGED']) && $attributes['UNSIGNED'] === TRUE)
+ $field[$i]['_literal'] = "\n\t".$this->_process_column($field[$i]);
+ if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name']))
{
- $sql .= ' UNSIGNED';
+ $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
+ .' '.$this->db->escape_identifiers($field[$i]['new_name']);
}
-
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
-
- $sql .= (isset($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? '' : ' NOT NULL';
-
- empty($attributes['CONSTRAINT']) OR ' CONSTRAINT '.$attributes['CONSTRAINT'];
- }
-
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
}
}
- if (count($primary_keys) > 0)
- {
- $sql .= ",\n\tCONSTRAINT ".$table.' PRIMARY KEY ('.implode(', ', $this->db->escape_identifiers($primary_keys)).')';
- }
+ $sql .= ' '.$alter_type.' ';
+ $sql .= (count($field) === 1)
+ ? $fields[0]
+ : '('.implode(',', $field).')';
- if (is_array($keys) && count($keys) > 0)
- {
- foreach ($keys as $key)
- {
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->db->escape_identifiers($key));
-
- $sql .= ",\n\tUNIQUE COLUMNS (".implode(', ', $key).')';
- }
- }
-
- return $sql."\n)";
+ // RENAME COLUMN must be executed after MODIFY
+ array_unshift($sqls, $sql);
+ return $sql;
}
// --------------------------------------------------------------------
/**
- * Alter table query
- *
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * Field attribute AUTO_INCREMENT
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param string the table name
- * @param string the column definition
- * @param string the default value
- * @param bool should 'NOT NULL' be added
- * @param string the field after which we should add the new field
- * @return string
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
*/
- protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ protected function _attr_auto_increment(&$attributes, &$field)
{
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name);
-
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
- {
- return $sql;
- }
-
- return $sql.' '.$column_definition
- .($default_value !== '' ? ' DEFAULT "'.$default_value.'"' : '')
- .($null === NULL ? ' NULL' : ' NOT NULL')
- .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
-
+ // Not supported - sequences and triggers must be used instead
}
}
diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php
index ade186be7..7d5bf5172 100644
--- a/system/database/drivers/oci8/oci8_result.php
+++ b/system/database/drivers/oci8/oci8_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* oci8 Result Class
@@ -37,15 +38,40 @@
*/
class CI_DB_oci8_result extends CI_DB_result {
+ /**
+ * Statement ID
+ *
+ * @var resource
+ */
public $stmt_id;
+
+ /**
+ * Cursor ID
+ *
+ * @var resource
+ */
public $curs_id;
+
+ /**
+ * Limit used flag
+ *
+ * @var bool
+ */
public $limit_used;
+
+ /**
+ * Commit mode flag
+ *
+ * @var int
+ */
public $commit_mode;
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Class constructor
*
- * @param object
+ * @param object &$driver_object
* @return void
*/
public function __construct(&$driver_object)
@@ -167,7 +193,7 @@ class CI_DB_oci8_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
@@ -211,9 +237,10 @@ class CI_DB_oci8_result extends CI_DB_result {
* some point in the future, but it will only work for resetting the
* pointer to zero.
*
+ * @param int $n (ignored)
* @return bool
*/
- protected function _data_seek()
+ protected function _data_seek($n = 0)
{
/* The PHP manual says that if OCI_NO_AUTO_COMMIT mode
* is used, and oci_rollback() and/or oci_commit() are
diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php
index 0183eda26..d15537fdf 100644
--- a/system/database/drivers/oci8/oci8_utility.php
+++ b/system/database/drivers/oci8/oci8_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Oracle Utility Class
@@ -34,18 +35,23 @@
*/
class CI_DB_oci8_utility extends CI_DB_utility {
+ /**
+ * List databases statement
+ *
+ * @var string
+ */
protected $_list_databases = 'SELECT username FROM dba_users'; // Schemas are actual usernames
/**
- * Oracle Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return mixed
*/
protected function _backup($params = array())
{
// Currently unsupported
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index f6ea412ad..1710aafae 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* ODBC Database Adapter Class
@@ -40,24 +41,42 @@
*/
class CI_DB_odbc_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'odbc';
- // the character used to excape - not necessary for ODBC
- protected $_escape_char = '';
+ /**
+ * Database schema
+ *
+ * @var string
+ */
+ public $schema = 'public';
- protected $_like_escape_str = " {escape '%s'} ";
+ // --------------------------------------------------------------------
- protected $_random_keyword;
+ /**
+ * Identifier escape character
+ *
+ * Must be empty for ODBC.
+ *
+ * @var string
+ */
+ protected $_escape_char = '';
/**
- * Database schema
+ * ESCAPE statement string
*
* @var string
*/
- public $schema = 'public';
+ protected $_like_escape_str = " {escape '%s'} ";
+
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* @param array $params
* @return void
@@ -104,7 +123,7 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return resource
*/
protected function _execute($sql)
@@ -117,7 +136,7 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -181,8 +200,8 @@ class CI_DB_odbc_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -231,7 +250,7 @@ class CI_DB_odbc_driver extends CI_DB {
*/
public function insert_id()
{
- return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
}
// --------------------------------------------------------------------
@@ -241,7 +260,7 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool $prefix_limit = FALSE
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -264,7 +283,7 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -279,7 +298,7 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -309,8 +328,8 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -327,10 +346,10 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -345,7 +364,7 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php
index d17b046ee..fb16ca5cf 100644
--- a/system/database/drivers/odbc/odbc_forge.php
+++ b/system/database/drivers/odbc/odbc_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* ODBC Forge Class
@@ -34,124 +35,39 @@
*/
class CI_DB_odbc_forge extends CI_DB_forge {
- protected $_drop_table = 'DROP TABLE %s';
-
/**
- * Create Table
+ * CREATE TABLE IF statement
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @var string
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
- {
- $sql = 'CREATE TABLE ';
-
- if ($if_not_exists === TRUE)
- {
- $sql .= 'IF NOT EXISTS ';
- }
-
- $sql .= $this->db->escape_identifiers($table).' (';
- $current_field_count = 0;
-
- foreach ($fields as $field => $attributes)
- {
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
- {
- $sql .= "\n\t".$attributes;
- }
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
-
- empty($attributes['CONSTRAINT']) OR $sql .= '('.$attributes['CONSTRAINT'].')';
-
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
-
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
-
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
- }
-
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
- }
- }
+ protected $_create_table_if = FALSE;
- if (count($primary_keys) > 0)
- {
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->escape_identifiers($primary_keys)).')';
- }
-
- if (is_array($keys) && count($keys) > 0)
- {
- foreach ($keys as $key)
- {
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->db->escape_identifiers($key));
-
- $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
- }
- }
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = FALSE;
- return $sql."\n)";
- }
+ /**
+ * UNSIGNED support
+ *
+ * @var bool|array
+ */
+ protected $_unsigned = FALSE;
// --------------------------------------------------------------------
/**
- * Alter table query
+ * Field attribute AUTO_INCREMENT
*
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
- *
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param string the table name
- * @param string the column definition
- * @param string the default value
- * @param bool should 'NOT NULL' be added
- * @param string the field after which we should add the new field
- * @return string
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
*/
- protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ protected function _attr_auto_increment(&$attributes, &$field)
{
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name);
-
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
- {
- return $sql;
- }
-
- return $sql.' '.$column_definition
- .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '')
- .($null === NULL ? ' NULL' : ' NOT NULL')
- .($after_field != '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
+ // Not supported (in most databases at least)
}
}
diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php
index 48dc48dd9..2c50c255b 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* ODBC Result Class
@@ -165,7 +166,7 @@ class CI_DB_odbc_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
@@ -198,11 +199,11 @@ if ( ! function_exists('odbc_fetch_array'))
* Emulates the native odbc_fetch_array() function when
* it is not available (odbc_fetch_array() requires unixODBC)
*
- * @param resource
- * @param int
+ * @param resource &$result
+ * @param int $rownumber
* @return array
*/
- function odbc_fetch_array(& $result, $rownumber = 1)
+ function odbc_fetch_array(&$result, $rownumber = 1)
{
$rs = array();
if ( ! odbc_fetch_into($result, $rs, $rownumber))
@@ -231,11 +232,11 @@ if ( ! function_exists('odbc_fetch_object'))
* Emulates the native odbc_fetch_object() function when
* it is not available.
*
- * @param resource
- * @param int
+ * @param resource &$result
+ * @param int $rownumber
* @return object
*/
- function odbc_fetch_object(& $result, $rownumber = 1)
+ function odbc_fetch_object(&$result, $rownumber = 1)
{
$rs = array();
if ( ! odbc_fetch_into($result, $rs, $rownumber))
diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php
index 224d48d2b..908674a9d 100644
--- a/system/database/drivers/odbc/odbc_utility.php
+++ b/system/database/drivers/odbc/odbc_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* ODBC Utility Class
@@ -34,18 +35,16 @@
*/
class CI_DB_odbc_utility extends CI_DB_utility {
- protected $_list_databases = FALSE;
-
/**
- * ODBC Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return mixed
*/
protected function _backup($params = array())
{
// Currently unsupported
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index 32a9e7509..923f0e125 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO Database Adapter Class
@@ -40,22 +41,33 @@
*/
class CI_DB_pdo_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'pdo';
- // The character used to escaping
- protected $_escape_char = '"';
-
- protected $_random_keyword;
-
+ /**
+ * Transaction enabled flag
+ *
+ * @var bool
+ */
public $trans_enabled = FALSE;
- // need to track the PDO options
+ /**
+ * PDO Options
+ *
+ * @var array
+ */
public $options = array();
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Class constructor
*
- * Validates the DSN string and/or detects the subdriver
+ * Validates the DSN string and/or detects the subdriver.
*
* @param array $params
* @return void
@@ -103,9 +115,9 @@ class CI_DB_pdo_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Non-persistent database connection
+ * Database connection
*
- * @param bool
+ * @param bool $persistent
* @return object
*/
public function db_connect($persistent = FALSE)
@@ -153,6 +165,10 @@ class CI_DB_pdo_driver extends CI_DB {
{
return $this->data_cache['version'];
}
+ elseif ( ! $this->conn_id)
+ {
+ $this->initialize();
+ }
// Not all subdrivers support the getAttribute() method
try
@@ -170,7 +186,7 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql SQL query
* @return mixed
*/
protected function _execute($sql)
@@ -183,7 +199,7 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -243,8 +259,8 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -296,7 +312,7 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Insert ID
*
- * @param string
+ * @param string $name
* @return int
*/
public function insert_id($name = NULL)
@@ -311,7 +327,7 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -355,9 +371,9 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @param string the table name
- * @param array the update data
- * @param string the where key
+ * @param string $table Table name
+ * @param array $values Update data
+ * @param string $index WHERE key
* @return string
*/
protected function _update_batch($table, $values, $index)
@@ -401,10 +417,10 @@ class CI_DB_pdo_driver extends CI_DB {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -415,4 +431,4 @@ class CI_DB_pdo_driver extends CI_DB {
}
/* End of file pdo_driver.php */
-/* Location: ./system/database/drivers/pdo/pdo_driver.php */
+/* Location: ./system/database/drivers/pdo/pdo_driver.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/pdo_forge.php b/system/database/drivers/pdo/pdo_forge.php
index 34a6ee44e..130d3667e 100644
--- a/system/database/drivers/pdo/pdo_forge.php
+++ b/system/database/drivers/pdo/pdo_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO Forge Class
@@ -34,133 +35,19 @@
*/
class CI_DB_pdo_forge extends CI_DB_forge {
- protected $_drop_table = 'DROP TABLE %s';
-
/**
- * Create Table
+ * CREATE TABLE IF statement
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @var string
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
- {
- $sql = 'CREATE TABLE ';
-
- if ($if_not_exists === TRUE)
- {
- $sql .= 'IF NOT EXISTS ';
- }
-
- $sql .= $this->db->escape_identifiers($table).' (';
- $current_field_count = 0;
-
- foreach ($fields as $field => $attributes)
- {
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
- {
- $sql .= "\n\t".$attributes;
- }
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
- $numeric = array('SERIAL', 'INTEGER');
-
- $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
-
- if ( ! empty($attributes['CONSTRAINT']))
- {
- // Exception for Postgre numeric which not too happy with constraint within those type
- if ( ! ($this->db->subdriver === 'pgsql' && in_array($attributes['TYPE'], $numeric)))
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
- }
-
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
-
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
-
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
- }
-
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
- }
- }
-
- if (count($primary_keys) > 0)
- {
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
- }
-
- if (is_array($keys) && count($keys) > 0)
- {
- foreach ($keys as $key)
- {
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->db->escape_identifiers($key));
-
- $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
- }
- }
-
- return $sql."\n)";
- }
-
- // --------------------------------------------------------------------
+ protected $_create_table_if = FALSE;
/**
- * Alter table query
- *
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * DROP TABLE IF statement
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param string the table name
- * @param string the column definition
- * @param string the default value
- * @param bool should 'NOT NULL' be added
- * @param string the field after which we should add the new field
- * @return string
+ * @var string
*/
- protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
- {
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name);
-
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
- {
- return $sql;
- }
-
- return $sql .' '.$column_definition
- .($default_value !== '' ? " DEFAULT '".$default_value."'" : '')
- .($null === NULL ? ' NULL' : ' NOT NULL')
- .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
- }
+ protected $_drop_table_if = FALSE;
}
diff --git a/system/database/drivers/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php
index 444406986..32ab1c280 100644
--- a/system/database/drivers/pdo/pdo_result.php
+++ b/system/database/drivers/pdo/pdo_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO Result Class
@@ -162,7 +163,7 @@ class CI_DB_pdo_result extends CI_DB_result {
{
if ($this->db->db_debug)
{
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
return FALSE;
@@ -205,7 +206,7 @@ class CI_DB_pdo_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/pdo/pdo_utility.php b/system/database/drivers/pdo/pdo_utility.php
index 930842118..86f2b120a 100644
--- a/system/database/drivers/pdo/pdo_utility.php
+++ b/system/database/drivers/pdo/pdo_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO Utility Class
@@ -34,18 +35,16 @@
*/
class CI_DB_pdo_utility extends CI_DB_utility {
- protected $_list_databases = FALSE;
-
/**
- * PDO Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return mixed
*/
protected function _backup($params = array())
{
// Currently unsupported
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php
index 438d312a1..6ebd92a9b 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO 4D Database Adapter Class
@@ -40,19 +41,28 @@
*/
class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = '4d';
- // The character used for escaping
+ /**
+ * Identifier escape character
+ *
+ * @var string[]
+ */
protected $_escape_char = array('[', ']');
- protected $_random_keyword = ' RAND()';
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -80,7 +90,7 @@ class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -103,7 +113,7 @@ class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -119,7 +129,7 @@ class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -134,8 +144,8 @@ class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -152,7 +162,7 @@ class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -164,11 +174,11 @@ class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_4d_forge.php b/system/database/drivers/pdo/subdrivers/pdo_4d_forge.php
new file mode 100644
index 000000000..231ad53a4
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_4d_forge.php
@@ -0,0 +1,209 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO 4D Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_4d_forge extends CI_DB_4d_forge {
+
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
+ protected $_create_database = 'CREATE SCHEMA %s';
+
+ /**
+ * DROP DATABASE statement
+ *
+ * @var string
+ */
+ protected $_drop_database = 'DROP SCHEMA %s';
+
+ /**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
+
+ /**
+ * RENAME TABLE statement
+ *
+ * @var string
+ */
+ protected $_rename_table = FALSE;
+
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = 'DROP TABLE IF EXISTS';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'INT16' => 'INT',
+ 'SMALLINT' => 'INT',
+ 'INT' => 'INT64',
+ 'INT32' => 'INT64'
+ );
+
+ /**
+ * DEFAULT value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_default = FALSE;
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
+ {
+ return parent::_alter_table($alter_table, $table, $field);
+ }
+
+ // No method of modifying columns is supported
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ return $this->db->escape_identifiers($field['name'])
+ .' '.$field['type'].$field['length']
+ .$field['null']
+ .$field['unique']
+ .$field['auto_increment'];
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'INTEGER':
+ $attributes['TYPE'] = 'INT';
+ return;
+ case 'BIGINT':
+ $attribites['TYPE'] = 'INT64';
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute UNIQUE
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_unique(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
+ {
+ $field['unique'] = ' UNIQUE';
+
+ // UNIQUE must be used with NOT NULL
+ $field['null'] = ' NOT NULL';
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
+ {
+ if (stripos($field['type'], 'int') !== FALSE)
+ {
+ $field['auto_increment'] = ' AUTO_INCREMENT';
+ }
+ elseif (strcasecmp($field['type'], 'UUID') === 0)
+ {
+ $field['auto_increment'] = ' AUTO_GENERATE';
+ }
+ }
+ }
+
+}
+
+/* End of file pdo_4d_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_4d_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php
index d2a484d9e..4f762b91c 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO CUBRID Database Adapter Class
@@ -40,18 +41,28 @@
*/
class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'cubrid';
+ /**
+ * Identifier escape character
+ *
+ * @var string
+ */
protected $_escape_char = '`';
- protected $_random_keyword = ' RAND()';
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -75,7 +86,7 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -97,7 +108,7 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -112,7 +123,7 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -127,9 +138,9 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @param string the table name
- * @param array the update data
- * @param string the where key
+ * @param string $table Table name
+ * @param array $values Update data
+ * @param string $index WHERE key
* @return string
*/
protected function _update_batch($table, $values, $index)
@@ -168,10 +179,10 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php
new file mode 100644
index 000000000..e8421ec41
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php
@@ -0,0 +1,212 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO CUBRID Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_cubrid_forge extends CI_DB_pdo_forge {
+
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
+ protected $_create_database = FALSE;
+
+ /**
+ * DROP DATABASE statement
+ *
+ * @var string
+ */
+ protected $_drop_database = FALSE;
+
+ /**
+ * CREATE TABLE keys flag
+ *
+ * Whether table keys are created from within the
+ * CREATE TABLE statement.
+ *
+ * @var bool
+ */
+ protected $_create_table_keys = TRUE;
+
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = 'DROP TABLE IF EXISTS';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'SHORT' => 'INTEGER',
+ 'SMALLINT' => 'INTEGER',
+ 'INT' => 'BIGINT',
+ 'INTEGER' => 'BIGINT',
+ 'BIGINT' => 'NUMERIC',
+ 'FLOAT' => 'DOUBLE',
+ 'REAL' => 'DOUBLE'
+ );
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ $sqls = array();
+ for ($i = 0, $c = count($field); $i < $c; $i++)
+ {
+ if ($field[$i]['_literal'] !== FALSE)
+ {
+ $sqls[] = $sql.' CHANGE '.$field[$i]['_literal'];
+ }
+ else
+ {
+ $sqls[] = $sql.' CHANGE '.$this->_process_column($field[$i]);
+ if ( ! empty($field[$i]['new_name']))
+ {
+ $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
+ .' AS '.$this->db->escape_identifiers($field[$i]['name']);
+ }
+ }
+ }
+
+ return $sqls;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ $extra_clause = isset($field['after'])
+ ? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
+
+ if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
+ {
+ $extra_clause = ' FIRST';
+ }
+
+ return $this->db->escape_identifiers($field['name'])
+ .(empty($field['new_name']) ? '' : $this->db->escape_identifiers($field['new_name']))
+ .' '.$field['type'].$field['length']
+ .$field['unsigned']
+ .$field['null']
+ .$field['default']
+ .$field['auto_increment']
+ .$field['unique']
+ .$extra_clause;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process indexes
+ *
+ * @param string $table (ignored)
+ * @return string
+ */
+ protected function _process_indexes($table = NULL)
+ {
+ $sql = '';
+
+ for ($i = 0, $c = count($this->keys); $i < $c; $i++)
+ {
+ if ( ! isset($this->fields[$this->keys[$i]]))
+ {
+ unset($this->keys[$i]);
+ continue;
+ }
+
+ is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
+
+ $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
+ .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
+ }
+
+ $this->keys = array();
+
+ return $sql;
+ }
+
+}
+
+/* End of file pdo_cubrid_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php
index 785b2795c..7121819ec 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO DBLIB Database Adapter Class
@@ -40,18 +41,40 @@
*/
class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'dblib';
+ // --------------------------------------------------------------------
+
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
protected $_random_keyword = ' NEWID()';
+ /**
+ * Quoted identifier flag
+ *
+ * Whether to use SQL-92 standard quoted identifier
+ * (double quotes) or brackets for identifier escaping.
+ *
+ * @var bool
+ */
protected $_quoted_identifier;
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -85,9 +108,9 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Non-persistent database connection
+ * Database connection
*
- * @param bool
+ * @param bool $persistent
* @return object
*/
public function db_connect($persistent = FALSE)
@@ -115,7 +138,7 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -140,7 +163,7 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -157,8 +180,8 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -175,7 +198,7 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -191,11 +214,11 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
@@ -239,6 +262,29 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql);
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Insert batch statement
+ *
+ * Generates a platform-specific insert string from the supplied data.
+ *
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
+ * @return string|bool
+ */
+ protected function _insert_batch($table, $keys, $values)
+ {
+ // Multiple-value inserts are only supported as of SQL Server 2008
+ if (version_compare($this->version(), '10', '>='))
+ {
+ return parent::_insert_batch($table, $keys, $values);
+ }
+
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
+
}
/* End of file pdo_dblib_driver.php */
diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php
new file mode 100644
index 000000000..236e1cce2
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php
@@ -0,0 +1,136 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO DBLIB Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_dblib_forge extends CI_DB_pdo_forge {
+
+ /**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE";
+
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE";
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'TINYINT' => 'SMALLINT',
+ 'SMALLINT' => 'INT',
+ 'INT' => 'BIGINT',
+ 'REAL' => 'FLOAT'
+ );
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN ';
+ $sqls = array();
+ for ($i = 0, $c = count($field); $i < $c; $i++)
+ {
+ $sqls[] = $sql.$this->_process_column($field[$i]);
+ }
+
+ return $sqls;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'INTEGER':
+ $attributes['TYPE'] = 'INT';
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
+ {
+ $field['auto_increment'] = ' IDENTITY(1,1)';
+ }
+ }
+
+}
+
+/* End of file pdo_dblib_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php
index 32d1f219a..83b9648c1 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO Firebird Database Adapter Class
@@ -40,21 +41,30 @@
*/
class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'firebird';
+ // --------------------------------------------------------------------
+
/**
- * The syntax to count rows is slightly different across different
- * database engines, so this string appears in each driver and is
- * used for the count_all() and count_all_results() functions.
+ * ORDER BY random keyword
+ *
+ * @var string
*/
- protected $_random_keyword = ' RANDOM()'; // Currently not supported
+ protected $_random_keyword = ' RANDOM()';
+
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -90,7 +100,7 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -113,7 +123,7 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -128,7 +138,7 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -143,8 +153,8 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -160,10 +170,10 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -178,7 +188,7 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -190,11 +200,11 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php b/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php
new file mode 100644
index 000000000..474188f4e
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php
@@ -0,0 +1,228 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO Firebird Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_firebird_forge extends CI_DB_pdo_forge {
+
+ /**
+ * RENAME TABLE statement
+ *
+ * @var string
+ */
+ protected $_rename_table = FALSE;
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'SMALLINT' => 'INTEGER',
+ 'INTEGER' => 'INT64',
+ 'FLOAT' => 'DOUBLE PRECISION'
+ );
+
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Create database
+ *
+ * @param string $db_name
+ * @return string
+ */
+ public function create_database($db_name)
+ {
+ // Firebird databases are flat files, so a path is required
+
+ // Hostname is needed for remote access
+ empty($this->db->hostname) OR $db_name = $this->hostname.':'.$db_name;
+
+ return parent::create_database('"'.$db_name.'"');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Drop database
+ *
+ * @param string $db_name (ignored)
+ * @return bool
+ */
+ public function drop_database($db_name = '')
+ {
+ if ( ! ibase_drop_db($this->conn_id))
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
+ }
+ elseif ( ! empty($this->db->data_cache['db_names']))
+ {
+ $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
+ if ($key !== FALSE)
+ {
+ unset($this->db->data_cache['db_names'][$key]);
+ }
+ }
+
+ return TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ $sqls = array();
+ for ($i = 0, $c = count($field), $sql .= $alter_type.' '; $i < $c; $i++)
+ {
+ if ($field[$i]['_literal'] !== FALSE)
+ {
+ return FALSE;
+ }
+
+ if (isset($field[$i]['type']))
+ {
+ $sqls[] = $sql.' TYPE '.$field[$i]['type'].$field[$i]['length'];
+ }
+
+ if ( ! empty($field[$i]['default']))
+ {
+ $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
+ .' SET '.$field[$i]['default'];
+ }
+
+ if (isset($field[$i]['null']))
+ {
+ $sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = '
+ .($field[$i]['null'] === TRUE ? 'NULL' : '1')
+ .' WHERE "RDB$FIELD_NAME" = '.$this->db->escape($field[$i]['name'])
+ .' AND "RDB$RELATION_NAME" = '.$this->db->escape($table);
+ }
+
+ if ( ! empty($field[$i]['new_name']))
+ {
+ $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
+ .' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
+ }
+ }
+
+ return $sqls;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ return $this->db->escape_identifiers($field['name'])
+ .' '.$field['type'].$field['length']
+ .$field['null']
+ .$field['unique']
+ .$field['default'];
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'INT':
+ $attributes['TYPE'] = 'INTEGER';
+ return;
+ case 'BIGINT':
+ $attributes['TYPE'] = 'INT64';
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ // Not supported
+ }
+
+}
+
+/* End of file pdo_firebird_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php b/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php
index 22a5f928c..d8dbc50c0 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO IBM DB2 Database Adapter Class
@@ -40,16 +41,21 @@
*/
class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'ibm';
- protected $_random_keyword = ' RAND()';
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -115,7 +121,7 @@ class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -138,7 +144,7 @@ class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -154,7 +160,7 @@ class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -169,8 +175,8 @@ class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -187,7 +193,7 @@ class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -199,21 +205,19 @@ class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
- * @param int the number of rows to limit the query to
- * @param int the offset value
+ * @param string $sql SQL Query
* @return string
*/
- protected function _limit($sql, $limit, $offset)
+ protected function _limit($sql)
{
- $sql .= ' FETCH FIRST '.($limit + $offset).' ROWS ONLY';
+ $sql .= ' FETCH FIRST '.($this->qb_limit + $this->qb_offset).' ROWS ONLY';
- return ($offset)
- ? 'SELECT * FROM ('.$sql.') WHERE rownum > '.$offset
+ return ($this->qb_offset)
+ ? 'SELECT * FROM ('.$sql.') WHERE rownum > '.$this->qb_offset
: $sql;
}
diff --git a/system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php b/system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php
new file mode 100644
index 000000000..f095c717a
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php
@@ -0,0 +1,146 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO IBM DB2 Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_ibm_forge extends CI_DB_pdo_forge {
+
+ /**
+ * RENAME TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_rename_table = 'RENAME TABLE %s TO %s';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'SMALLINT' => 'INTEGER',
+ 'INT' => 'BIGINT',
+ 'INTEGER' => 'BIGINT'
+ );
+
+ /**
+ * DEFAULT value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_default = FALSE;
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if ($alter_type === 'CHANGE')
+ {
+ $alter_type = 'MODIFY';
+ }
+
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute UNIQUE
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_unique(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
+ {
+ $field['unique'] = ' UNIQUE';
+
+ // UNIQUE must be used with NOT NULL
+ $field['null'] = ' NOT NULL';
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ // Not supported
+ }
+
+}
+
+/* End of file pdo_ibm_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php
index 8dd430184..8998670e1 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO Informix Database Adapter Class
@@ -40,16 +41,21 @@
*/
class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'informix';
- protected $_random_keyword = ' RAND()';
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -108,7 +114,7 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -131,7 +137,7 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -148,7 +154,7 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -163,8 +169,8 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -181,10 +187,10 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -199,7 +205,7 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -211,11 +217,11 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql $SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_informix_forge.php b/system/database/drivers/pdo/subdrivers/pdo_informix_forge.php
new file mode 100644
index 000000000..8722dd200
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_informix_forge.php
@@ -0,0 +1,155 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO Informix Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_informix_forge extends CI_DB_pdo_forge {
+
+ /**
+ * RENAME TABLE statement
+ *
+ * @var string
+ */
+ protected $_rename_table = 'RENAME TABLE %s TO %s';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'SMALLINT' => 'INTEGER',
+ 'INT' => 'BIGINT',
+ 'INTEGER' => 'BIGINT',
+ 'REAL' => 'DOUBLE PRECISION',
+ 'SMALLFLOAT' => 'DOUBLE PRECISION'
+ );
+
+ /**
+ * DEFAULT value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_default = ', ';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if ($alter_type === 'CHANGE')
+ {
+ $alter_type = 'MODIFY';
+ }
+
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'BYTE':
+ case 'TEXT':
+ case 'BLOB':
+ case 'CLOB':
+ $attributes['UNIQUE'] = FALSE;
+ if (isset($attributes['DEFAULT']))
+ {
+ unset($attributes['DEFAULT']);
+ }
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute UNIQUE
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_unique(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
+ {
+ $field['unique'] = ' UNIQUE CONSTRAINT '.$this->db->escape_identifiers($field['name']);
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ // Not supported
+ }
+
+}
+
+/* End of file pdo_informix_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_informix_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php
index 0fb5d8f12..2d076f314 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO MySQL Database Adapter Class
@@ -40,19 +41,37 @@
*/
class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'mysql';
+
+ /**
+ * Compression flag
+ *
+ * @var bool
+ */
public $compress = FALSE;
+ // --------------------------------------------------------------------
+
+ /**
+ * Identifier escape character
+ *
+ * @var string
+ */
protected $_escape_char = '`';
- protected $_random_keyword = ' RAND()';
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -76,9 +95,9 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Non-persistent database connection
+ * Database connection
*
- * @param bool
+ * @param bool $persistent
* @return object
* @todo SSL support
*/
@@ -110,7 +129,7 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -132,7 +151,7 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -147,7 +166,7 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -162,9 +181,9 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @param string the table name
- * @param array the update data
- * @param string the where key
+ * @param string $table Table name
+ * @param array $values Update data
+ * @param string $index UPDATE key
* @return string
*/
protected function _update_batch($table, $values, $index)
@@ -203,10 +222,10 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php
new file mode 100644
index 000000000..866b6fb21
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php
@@ -0,0 +1,218 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO MySQL Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_mysql_forge extends CI_DB_pdo_forge {
+
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
+ protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s';
+
+ /**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
+
+ /**
+ * CREATE TABLE keys flag
+ *
+ * Whether table keys are created from within the
+ * CREATE TABLE statement.
+ *
+ * @var bool
+ */
+ protected $_create_table_keys = TRUE;
+
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = 'DROP TABLE IF EXISTS';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'TINYINT',
+ 'SMALLINT',
+ 'MEDIUMINT',
+ 'INT',
+ 'INTEGER',
+ 'BIGINT',
+ 'REAL',
+ 'DOUBLE',
+ 'DOUBLE PRECISION',
+ 'FLOAT',
+ 'DECIMAL',
+ 'NUMERIC'
+ );
+
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * @param object &$db Database object
+ * @return void
+ */
+ public function __construct(&$db)
+ {
+ parent::__construct($db);
+
+ $this->_create_table .= ' DEFAULT CHARSET '.$this->db->char_set.' COLLATE '.$this->db->dbcollat;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if ($alter_type === 'DROP')
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ for ($i = 0, $c = count($field); $i < $c; $i++)
+ {
+ if ($field[$i]['_literal'] !== FALSE)
+ {
+ $field[$i] = ($alter_type === 'ADD')
+ ? "\n\tADD ".$field[$i]['_literal']
+ : "\n\tMODIFY ".$field[$i]['_literal'];
+ }
+ else
+ {
+ if ($alter_type === 'ADD')
+ {
+ $field[$i]['_literal'] = "\n\tADD ";
+ }
+ else
+ {
+ $field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE ";
+ }
+
+ $field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]);
+ }
+ }
+
+ return array($sql.implode(',', $field));
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ $extra_clause = isset($field['after'])
+ ? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
+
+ if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
+ {
+ $extra_clause = ' FIRST';
+ }
+
+ return $this->db->escape_identifiers($field['name'])
+ .(empty($field['new_name']) ? '' : $this->db->escape_identifiers($field['new_name']))
+ .' '.$field['type'].$field['length']
+ .$field['unsigned']
+ .$field['null']
+ .$field['default']
+ .$field['auto_increment']
+ .$field['unique']
+ .$extra_clause;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process indexes
+ *
+ * @param string $table (ignored)
+ * @return string
+ */
+ protected function _process_indexes($table = NULL)
+ {
+ $sql = '';
+
+ for ($i = 0, $c = count($this->keys); $i < $c; $i++)
+ {
+ if ( ! isset($this->fields[$this->keys[$i]]))
+ {
+ unset($this->keys[$i]);
+ continue;
+ }
+
+ is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
+
+ $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
+ .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
+ }
+
+ $this->keys = array();
+
+ return $sql;
+ }
+
+}
+
+/* End of file pdo_mysql_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php
index b03218fad..e1beb3683 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO Oracle Database Adapter Class
@@ -40,24 +41,49 @@
*/
class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'oci';
+ // --------------------------------------------------------------------
+
/**
- * The syntax to count rows is slightly different across different
- * database engines, so this string appears in each driver and is
- * used for the count_all() and count_all_results() functions.
+ * List of reserved identifiers
+ *
+ * Identifiers that must NOT be escaped.
+ *
+ * @var string[]
+ */
+ protected $_reserved_identifiers = array('*', 'rownum');
+
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
*/
- protected $_count_string = 'SELECT COUNT(1) AS ';
protected $_random_keyword = ' ASC'; // Currently not supported
- protected $_reserved_identifiers = array('*', 'rownum');
+ /**
+ * COUNT string
+ *
+ * @used-by CI_DB_driver::count_all()
+ * @used-by CI_DB_query_builder::count_all_results()
+ *
+ * @var string
+ */
+ protected $_count_string = 'SELECT COUNT(1) AS ';
+
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -97,7 +123,7 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -120,7 +146,7 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -135,7 +161,7 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -146,11 +172,11 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Insert_batch statement
+ * Insert batch statement
*
- * @param string the table name
- * @param array the insert keys
- * @param array the insert values
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
* @return string
*/
protected function _insert_batch($table, $keys, $values)
@@ -173,7 +199,7 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -190,11 +216,11 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php b/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php
new file mode 100644
index 000000000..8052d218f
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php
@@ -0,0 +1,133 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO Oracle Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_oci_forge extends CI_DB_pdo_forge {
+
+ /**
+ * CREATE DATABASE statement
+ *
+ * @var string
+ */
+ protected $_create_database = FALSE;
+
+ /**
+ * DROP DATABASE statement
+ *
+ * @var string
+ */
+ protected $_drop_database = FALSE;
+
+ /**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var bool|array
+ */
+ protected $_unsigned = FALSE;
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if ($alter_type === 'DROP')
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+ elseif ($alter_type === 'CHANGE')
+ {
+ $alter_type = 'MODIFY';
+ }
+
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ $sqls = array();
+ for ($i = 0, $c = count($field); $i < $c; $i++)
+ {
+ if ($field[$i]['_literal'] !== FALSE)
+ {
+ $field[$i] = "\n\t".$field[$i]['_literal'];
+ }
+ else
+ {
+ $field[$i]['_literal'] = "\n\t".$this->_process_column($field[$i]);
+ if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name']))
+ {
+ $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
+ .' '.$this->db->escape_identifiers($field[$i]['new_name']);
+ }
+ }
+ }
+
+ $sql .= ' '.$alter_type.' ';
+ $sql .= (count($field) === 1)
+ ? $fields[0]
+ : '('.implode(',', $field).')';
+
+ // RENAME COLUMN must be executed after MODIFY
+ array_unshift($sqls, $sql);
+ return $sql;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ // Not supported - sequences and triggers must be used instead
+ }
+
+}
+
+/* End of file pdo_oci_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_oci_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php
index d64e9fb36..f6e0e215a 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO ODBC Database Adapter Class
@@ -40,29 +41,46 @@
*/
class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'odbc';
- // The character used for escaping - not used in ODBC
- protected $_escape_char = '';
+ /**
+ * Database schema
+ *
+ * @var string
+ */
+ public $schema = 'public';
- // clause and character used for LIKE escape sequences
- protected $_like_escape_str = " {escape '%s'} ";
+ // --------------------------------------------------------------------
- protected $_random_keyword = ' RAND()';
+ /**
+ * Identifier escape character
+ *
+ * Must be empty for ODBC.
+ *
+ * @var string
+ */
+ protected $_escape_char = '';
/**
- * Database schema
+ * ESCAPE statement string
*
* @var string
*/
- public $schema = 'public';
+ protected $_like_escape_str = " {escape '%s'} ";
+
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -129,7 +147,7 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool $prefix_limit = FALSE
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -152,7 +170,7 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -167,8 +185,8 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -185,10 +203,10 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -215,11 +233,11 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php b/system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php
new file mode 100644
index 000000000..ab4d2bf84
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO ODBC Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/database/
+ */
+class CI_DB_pdo_odbc_forge extends CI_DB_pdo_forge {
+
+ /**
+ * UNSIGNED support
+ *
+ * @var bool|array
+ */
+ protected $_unsigned = FALSE;
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ // Not supported (in most databases at least)
+ }
+
+}
+
+/* End of file pdo_odbc_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php
index 93674b576..c3f5b7603 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO PostgreSQL Database Adapter Class
@@ -40,10 +41,13 @@
*/
class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'pgsql';
- protected $_random_keyword = ' RANDOM()';
-
/**
* Database schema
*
@@ -51,12 +55,23 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
*/
public $schema = 'public';
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
+ protected $_random_keyword = ' RANDOM()';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -77,7 +92,7 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
/**
* Insert ID
*
- * @param string
+ * @param string $name
* @return int
*/
public function insert_id($name = NULL)
@@ -99,7 +114,7 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool $prefix_limit = FALSE
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -123,7 +138,7 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -138,7 +153,7 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -153,8 +168,8 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -171,9 +186,9 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @param string the table name
- * @param array the update data
- * @param string the where key
+ * @param string $table Table name
+ * @param array $values Update data
+ * @param string $index WHERE key
* @return string
*/
protected function _update_batch($table, $values, $index)
@@ -212,7 +227,7 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -224,11 +239,11 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php
new file mode 100644
index 000000000..484c1603d
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php
@@ -0,0 +1,194 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO PostgreSQL Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_pgsql_forge extends CI_DB_pdo_forge {
+
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = 'DROP TABLE IF EXISTS';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'INT2' => 'INTEGER',
+ 'SMALLINT' => 'INTEGER',
+ 'INT' => 'BIGINT',
+ 'INT4' => 'BIGINT',
+ 'INTEGER' => 'BIGINT',
+ 'INT8' => 'NUMERIC',
+ 'BIGINT' => 'NUMERIC',
+ 'REAL' => 'DOUBLE PRECISION',
+ 'FLOAT' => 'DOUBLE PRECISION'
+ );
+
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * @param object &$db Database object
+ * @return void
+ */
+ public function __construct(&$db)
+ {
+ parent::__construct($db);
+
+ if (version_compare($this->db->version(), '9.0', '>'))
+ {
+ $this->create_table_if = 'CREATE TABLE IF NOT EXISTS';
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ $sqls = array();
+ for ($i = 0, $c = count($field), $sql .= $alter_type.' '; $i < $c; $i++)
+ {
+ if ($field[$i]['_literal'] !== FALSE)
+ {
+ return FALSE;
+ }
+
+ if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type']))
+ {
+ $sqls[] = $sql.' TYPE '.$field[$i]['type'].$field[$i]['length'];
+ }
+
+ if ( ! empty($field[$i]['default']))
+ {
+ $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
+ .' SET '.$field[$i]['default'];
+ }
+
+ if (isset($field[$i]['null']))
+ {
+ $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
+ .($field[$i]['null'] === TRUE ? ' DROP NOT NULL' : ' SET NOT NULL');
+ }
+
+ if ( ! empty($field[$i]['new_name']))
+ {
+ $sqls[] = $sql.' RENAME '.$this->db->escape_identifiers($field[$i]['name'])
+ .' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
+ }
+ }
+
+ return $sqls;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ // Reset field lenghts for data types that don't support it
+ if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE)
+ {
+ $attributes['CONSTRAINT'] = NULL;
+ }
+
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
+ {
+ $field['type'] = ($field['type'] === 'NUMERIC')
+ ? 'BIGSERIAL'
+ : 'SERIAL';
+ }
+ }
+
+}
+
+/* End of file pdo_pgsql_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php
index bf0363f63..b24b13e76 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO SQLite Database Adapter Class
@@ -40,21 +41,30 @@
*/
class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'sqlite';
+ // --------------------------------------------------------------------
+
/**
- * The syntax to count rows is slightly different across different
- * database engines, so this string appears in each driver and is
- * used for the count_all() and count_all_results() functions.
+ * ORDER BY random keyword
+ *
+ * @var string
*/
- protected $_random_keyword = ' RANDOM()'; // Currently not supported
+ protected $_random_keyword = ' RANDOM()';
+
+ // --------------------------------------------------------------------
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -81,7 +91,7 @@ class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -104,7 +114,7 @@ class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -120,7 +130,7 @@ class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -133,9 +143,9 @@ class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver {
/**
* Replace statement
*
- * @param string the table name
- * @param array the insert keys
- * @param array the insert values
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
* @return string
*/
protected function _replace($table, $keys, $values)
@@ -150,10 +160,10 @@ class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php b/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php
new file mode 100644
index 000000000..da098df31
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php
@@ -0,0 +1,229 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.1.6 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO SQLite Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_sqlite_forge extends CI_DB_pdo_forge {
+
+ /**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
+
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = 'DROP TABLE IF EXISTS';
+
+ /**
+ * UNSIGNED support
+ *
+ * @var bool|array
+ */
+ protected $_unsigned = FALSE;
+
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * @param object &$db Database object
+ * @return void
+ */
+ public function __construct(&$db)
+ {
+ parent::__construct($db);
+
+ if (version_compare($this->db->version(), '3.3', '<'))
+ {
+ $this->_create_table_if = FALSE;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Create database
+ *
+ * @param string $db_name (ignored)
+ * @return bool
+ */
+ public function create_database($db_name = '')
+ {
+ // In SQLite, a database is created when you connect to the database.
+ // We'll return TRUE so that an error isn't generated
+ return TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Drop database
+ *
+ * @param string $db_name (ignored)
+ * @return bool
+ */
+ public function drop_database($db_name = '')
+ {
+ // In SQLite, a database is dropped when we delete a file
+ if (@file_exists($this->db->database))
+ {
+ // We need to close the pseudo-connection first
+ $this->db->close();
+ if ( ! @unlink($this->db->database))
+ {
+ return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE;
+ }
+ elseif ( ! empty($this->db->data_cache['db_names']))
+ {
+ $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
+ if ($key !== FALSE)
+ {
+ unset($this->db->data_cache['db_names'][$key]);
+ }
+ }
+
+ return TRUE;
+ }
+
+ return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if ($alter_type === 'DROP' OR $alter_type === 'CHANGE')
+ {
+ // drop_column():
+ // BEGIN TRANSACTION;
+ // CREATE TEMPORARY TABLE t1_backup(a,b);
+ // INSERT INTO t1_backup SELECT a,b FROM t1;
+ // DROP TABLE t1;
+ // CREATE TABLE t1(a,b);
+ // INSERT INTO t1 SELECT a,b FROM t1_backup;
+ // DROP TABLE t1_backup;
+ // COMMIT;
+
+ return FALSE;
+ }
+
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ return $this->db->escape_identifiers($field['name'])
+ .' '.$field['type']
+ .$field['auto_increment']
+ .$field['null']
+ .$field['unique']
+ .$field['default'];
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'ENUM':
+ case 'SET':
+ $attributes['TYPE'] = 'TEXT';
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
+ {
+ $field['type'] = 'INTEGER PRIMARY KEY';
+ $field['default'] = '';
+ $field['null'] = '';
+ $field['unique'] = '';
+ $field['auto_increment'] = ' AUTOINCREMENT';
+
+ $this->primary_keys = array();
+ }
+ }
+
+}
+
+/* End of file pdo_sqlite_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php
index 33bd7bea5..7bb7f8806 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PDO SQLSRV Database Adapter Class
@@ -40,18 +41,40 @@
*/
class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
+ /**
+ * Sub-driver
+ *
+ * @var string
+ */
public $subdriver = 'sqlsrv';
+ // --------------------------------------------------------------------
+
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
protected $_random_keyword = ' NEWID()';
+ /**
+ * Quoted identifier flag
+ *
+ * Whether to use SQL-92 standard quoted identifier
+ * (double quotes) or brackets for identifier escaping.
+ *
+ * @var bool
+ */
protected $_quoted_identifier;
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Class constructor
*
* Builds the DSN if not already set.
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -109,9 +132,9 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Non-persistent database connection
+ * Database connection
*
- * @param bool
+ * @param bool $persistent
* @return object
*/
public function db_connect($persistent = FALSE)
@@ -144,7 +167,7 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -169,7 +192,7 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -186,8 +209,8 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -204,7 +227,7 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -220,11 +243,11 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
@@ -273,6 +296,29 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql);
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Insert batch statement
+ *
+ * Generates a platform-specific insert string from the supplied data.
+ *
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
+ * @return string|bool
+ */
+ protected function _insert_batch($table, $keys, $values)
+ {
+ // Multiple-value inserts are only supported as of SQL Server 2008
+ if (version_compare($this->version(), '10', '>='))
+ {
+ return parent::_insert_batch($table, $keys, $values);
+ }
+
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
+
}
/* End of file pdo_sqlsrv_driver.php */
diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php
new file mode 100644
index 000000000..e4b669f6e
--- /dev/null
+++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php
@@ -0,0 +1,136 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 2.1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * PDO SQLSRV Forge Class
+ *
+ * @category Database
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_pdo_sqlsrv_forge extends CI_DB_pdo_forge {
+
+ /**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE";
+
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE";
+
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'TINYINT' => 'SMALLINT',
+ 'SMALLINT' => 'INT',
+ 'INT' => 'BIGINT',
+ 'REAL' => 'FLOAT'
+ );
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN ';
+ $sqls = array();
+ for ($i = 0, $c = count($field); $i < $c; $i++)
+ {
+ $sqls[] = $sql.$this->_process_column($field[$i]);
+ }
+
+ return $sqls;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
+ {
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'INTEGER':
+ $attributes['TYPE'] = 'INT';
+ return;
+ default: return;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
+ {
+ $field['auto_increment'] = ' IDENTITY(1,1)';
+ }
+ }
+
+}
+
+/* End of file pdo_sqlsrv_forge.php */
+/* Location: ./system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php */ \ No newline at end of file
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index ca231f6f7..40f21b1e8 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Postgre Database Adapter Class
@@ -40,12 +41,13 @@
*/
class CI_DB_postgre_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'postgre';
- protected $_escape_char = '"';
-
- protected $_random_keyword = ' RANDOM()'; // database specific random keyword
-
/**
* Database schema
*
@@ -53,8 +55,19 @@ class CI_DB_postgre_driver extends CI_DB {
*/
public $schema = 'public';
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
+ protected $_random_keyword = ' RANDOM()'; // database specific random keyword
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
*
* Creates a DSN string to be used for db_connect() and db_pconnect()
*
@@ -170,7 +183,7 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Set client character set
*
- * @param string
+ * @param string $charset
* @return bool
*/
protected function _db_set_charset($charset)
@@ -191,8 +204,12 @@ class CI_DB_postgre_driver extends CI_DB {
{
return $this->data_cache['version'];
}
+ elseif ( ! $this->conn_id)
+ {
+ $this->initialize();
+ }
- if (($pg_version = pg_version($this->conn_id)) === FALSE)
+ if ( ! $this->conn_id OR ($pg_version = pg_version($this->conn_id)) === FALSE)
{
return FALSE;
}
@@ -212,7 +229,7 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return resource
*/
protected function _execute($sql)
@@ -225,7 +242,7 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -285,8 +302,8 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -322,7 +339,7 @@ class CI_DB_postgre_driver extends CI_DB {
* Escapes data based on type
* Sets boolean and null types
*
- * @param string
+ * @param string $str
* @return mixed
*/
public function escape($str)
@@ -400,7 +417,7 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool $prefix_limit = FALSE
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -424,7 +441,7 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -439,7 +456,7 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -469,8 +486,8 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -487,9 +504,9 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific batch update string from the supplied data
*
- * @param string the table name
- * @param array the update data
- * @param string the where key
+ * @param string $table Table name
+ * @param array $values Update data
+ * @param string $index WHERE key
* @return string
*/
protected function _update_batch($table, $values, $index)
@@ -528,7 +545,7 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -540,11 +557,11 @@ class CI_DB_postgre_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php
index 1164d9bb3..425622fac 100644
--- a/system/database/drivers/postgre/postgre_forge.php
+++ b/system/database/drivers/postgre/postgre_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Postgre Forge Class
@@ -34,182 +35,151 @@
*/
class CI_DB_postgre_forge extends CI_DB_forge {
- protected $_drop_table = 'DROP TABLE IF EXISTS %s CASCADE';
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'INT2' => 'INTEGER',
+ 'SMALLINT' => 'INTEGER',
+ 'INT' => 'BIGINT',
+ 'INT4' => 'BIGINT',
+ 'INTEGER' => 'BIGINT',
+ 'INT8' => 'NUMERIC',
+ 'BIGINT' => 'NUMERIC',
+ 'REAL' => 'DOUBLE PRECISION',
+ 'FLOAT' => 'DOUBLE PRECISION'
+ );
/**
- * Process Fields
+ * NULL value representation in CREATE/ALTER TABLE statements
*
- * @param mixed $fields
- * @param array $primary_keys = array()
- * @return string
+ * @var string
*/
- protected function _process_fields($fields, $primary_keys = array())
+ protected $_null = 'NULL';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * @param object &$db Database object
+ * @return void
+ */
+ public function __construct(&$db)
{
- $sql = '';
- $current_field_count = 0;
+ parent::__construct($db);
- foreach ($fields as $field => $attributes)
+ if (version_compare($this->db->version(), '9.0', '>'))
{
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
+ $this->create_table_if = 'CREATE TABLE IF NOT EXISTS';
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
+ {
+ return parent::_alter_table($alter_type, $table, $field);
+ }
+
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ $sqls = array();
+ for ($i = 0, $c = count($field), $sql .= $alter_type.' '; $i < $c; $i++)
+ {
+ if ($field[$i]['_literal'] !== FALSE)
+ {
+ return FALSE;
+ }
+
+ if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type']))
{
- $sql .= "\n\t".$attributes;
+ $sqls[] = $sql.' TYPE '.$field[$i]['type'].$field[$i]['length'];
}
- else
+
+ if ( ! empty($field[$i]['default']))
+ {
+ $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
+ .' SET '.$field[$i]['default'];
+ }
+
+ if (isset($field[$i]['null']))
{
- $sql .= "\n\t".$this->db->escape_identifiers($field);
-
- $attributes = array_change_key_case($attributes, CASE_UPPER);
- $is_unsigned = ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE);
-
- // Convert datatypes to be PostgreSQL-compatible
- switch (strtoupper($attributes['TYPE']))
- {
- case 'TINYINT':
- $attributes['TYPE'] = 'SMALLINT';
- break;
- case 'SMALLINT':
- $attributes['TYPE'] = ($is_unsigned) ? 'INTEGER' : 'SMALLINT';
- break;
- case 'MEDIUMINT':
- $attributes['TYPE'] = 'INTEGER';
- break;
- case 'INT':
- $attributes['TYPE'] = ($is_unsigned) ? 'BIGINT' : 'INTEGER';
- break;
- case 'BIGINT':
- $attributes['TYPE'] = ($is_unsigned) ? 'NUMERIC' : 'BIGINT';
- break;
- case 'DOUBLE':
- $attributes['TYPE'] = 'DOUBLE PRECISION';
- break;
- case 'DATETIME':
- $attributes['TYPE'] = 'TIMESTAMP';
- break;
- case 'LONGTEXT':
- $attributes['TYPE'] = 'TEXT';
- break;
- case 'BLOB':
- $attributes['TYPE'] = 'BYTEA';
- break;
- default:
- break;
- }
-
- // If this is an auto-incrementing primary key, use the serial data type instead
- $sql .= (in_array($field, $primary_keys) && ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- ? ' SERIAL' : ' '.$attributes['TYPE'];
-
- // Modified to prevent constraints with integer data types
- if ( ! empty($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') === FALSE)
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
-
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
-
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
-
- // Added new attribute to create unique fields. Also works with MySQL
- if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
- {
- $sql .= ' UNIQUE';
- }
+ $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
+ .($field[$i]['null'] === TRUE ? ' DROP NOT NULL' : ' SET NOT NULL');
}
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
+ if ( ! empty($field[$i]['new_name']))
{
- $sql .= ',';
+ $sqls[] = $sql.' RENAME '.$this->db->escape_identifiers($field[$i]['name'])
+ .' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
}
}
- return $sql;
- }
+ return $sqls;
+ }
// --------------------------------------------------------------------
/**
- * Create Table
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @param array &$attributes
+ * @return void
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ protected function _attr_type(&$attributes)
{
- $sql = 'CREATE TABLE ';
-
- // PostgreSQL doesn't support IF NOT EXISTS syntax so we check if table exists manually
- if ($if_not_exists === TRUE && $this->db->table_exists($table))
+ // Reset field lenghts for data types that don't support it
+ if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE)
{
- return TRUE;
+ $attributes['CONSTRAINT'] = NULL;
}
- $sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields, $primary_keys);
-
- if (count($primary_keys) > 0)
+ switch (strtoupper($attributes['TYPE']))
{
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ default: return;
}
-
- $sql .= "\n);";
-
- if (is_array($keys) && count($keys) > 0)
- {
- foreach ($keys as $key)
- {
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->db->escape_identifiers($key));
-
- foreach ($key as $field)
- {
- $sql .= "\nCREATE INDEX ".$this->db->escape_identifiers($table.'_'.str_replace(array('"', "'"), '', $field).'_index')
- .' ON '.$this->db->escape_identifiers($table).' ('.$this->db->escape_identifiers($field).');';
- }
- }
- }
-
- return $sql;
}
// --------------------------------------------------------------------
/**
- * Alter table query
+ * Field attribute AUTO_INCREMENT
*
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
- *
- * @param string $alter_type the ALTER type (ADD, DROP, CHANGE)
- * @param string $table the table name
- * @param string $fields the column definition
- * @param string $after_field = ''
- * @return string
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
*/
- protected function _alter_table($alter_type, $table, $fields, $after_field = '')
- {
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' ';
-
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
- {
- return $sql.$this->db->escape_identifiers($fields);
- }
-
- return $sql.$this->_process_fields($fields)
- .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
- }
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
+ {
+ $field['type'] = ($field['type'] === 'NUMERIC')
+ ? 'BIGSERIAL'
+ : 'SERIAL';
+ }
+ }
}
diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php
index 458ae869c..3f73f84c7 100644
--- a/system/database/drivers/postgre/postgre_result.php
+++ b/system/database/drivers/postgre/postgre_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Postgres Result Class
@@ -129,9 +130,9 @@ class CI_DB_postgre_result extends CI_DB_result {
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
- * result set starts at zero
+ * result set starts at zero.
*
- * @param int $n = 0
+ * @param int $n
* @return bool
*/
protected function _data_seek($n = 0)
@@ -160,7 +161,7 @@ class CI_DB_postgre_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php
index c95e6df0c..d3b2b9cdc 100644
--- a/system/database/drivers/postgre/postgre_utility.php
+++ b/system/database/drivers/postgre/postgre_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Postgre Utility Class
@@ -34,19 +35,32 @@
*/
class CI_DB_postgre_utility extends CI_DB_utility {
+ /**
+ * List databases statement
+ *
+ * @var string
+ */
protected $_list_databases = 'SELECT datname FROM pg_database';
+
+ /**
+ * OPTIMIZE TABLE statement
+ *
+ * @var string
+ */
protected $_optimize_table = 'REINDEX TABLE %s';
+ // --------------------------------------------------------------------
+
/**
- * Postgre Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return mixed
*/
protected function _backup($params = array())
{
// Currently unsupported
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index 2fd39346f..85411735c 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLite Database Adapter Class
@@ -40,13 +41,24 @@
*/
class CI_DB_sqlite_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'sqlite';
- // The character used to escape with - not needed for SQLite
- protected $_escape_char = '"';
+ // --------------------------------------------------------------------
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
protected $_random_keyword = ' Random()'; // database specific random keyword
+ // --------------------------------------------------------------------
+
/**
* Non-persistent database connection
*
@@ -112,7 +124,7 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return resource
*/
protected function _execute($sql)
@@ -127,7 +139,7 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -190,8 +202,8 @@ class CI_DB_sqlite_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -250,7 +262,7 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -272,7 +284,7 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return bool
*/
protected function _list_columns($table = '')
@@ -288,7 +300,7 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -320,9 +332,9 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific replace string from the supplied data
*
- * @param string the table name
- * @param array the insert keys
- * @param array the insert values
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
* @return string
*/
protected function _replace($table, $keys, $values)
@@ -337,10 +349,10 @@ class CI_DB_sqlite_driver extends CI_DB {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this function maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php
index e02e327f3..6ad583560 100644
--- a/system/database/drivers/sqlite/sqlite_forge.php
+++ b/system/database/drivers/sqlite/sqlite_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLite Forge Class
@@ -35,9 +36,32 @@
class CI_DB_sqlite_forge extends CI_DB_forge {
/**
+ * CREATE TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_create_table_if = FALSE;
+
+ /**
+ * UNSIGNED support
+ *
+ * @var bool|array
+ */
+ protected $_unsigned = FALSE;
+
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
+
+ // --------------------------------------------------------------------
+
+ /**
* Create database
*
- * @param string the database name
+ * @param string $db_name (ignored)
* @return bool
*/
public function create_database($db_name = '')
@@ -52,7 +76,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
/**
* Drop database
*
- * @param string the database name (ignored)
+ * @param string $db_name (ignored)
* @return bool
*/
public function drop_database($db_name = '')
@@ -76,126 +100,95 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
// --------------------------------------------------------------------
/**
- * Create Table
+ * ALTER TABLE
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @todo implement drop_column(), modify_column()
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ protected function _alter_table($alter_type, $table, $field)
{
- $sql = 'CREATE TABLE ';
-
- // IF NOT EXISTS added to SQLite in 3.3.0
- if ($if_not_exists === TRUE && version_compare($this->db->version(), '3.3.0', '>=') === TRUE)
+ if ($alter_type === 'DROP' OR $alter_type === 'CHANGE')
{
- $sql .= 'IF NOT EXISTS ';
- }
-
- $sql .= $this->db->escape_identifiers($table).' (';
- $current_field_count = 0;
-
- foreach ($fields as $field => $attributes)
- {
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
- {
- $sql .= "\n\t".$attributes;
- }
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
-
- empty($attributes['CONSTRAINT']) OR $sql .= '('.$attributes['CONSTRAINT'].')';
-
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
-
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
+ // drop_column():
+ // BEGIN TRANSACTION;
+ // CREATE TEMPORARY TABLE t1_backup(a,b);
+ // INSERT INTO t1_backup SELECT a,b FROM t1;
+ // DROP TABLE t1;
+ // CREATE TABLE t1(a,b);
+ // INSERT INTO t1 SELECT a,b FROM t1_backup;
+ // DROP TABLE t1_backup;
+ // COMMIT;
+ return FALSE;
+ }
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
+ return parent::_alter_table($alter_type, $table, $field);
+ }
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
- }
+ // --------------------------------------------------------------------
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
- }
- }
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ return $this->db->escape_identifiers($field['name'])
+ .' '.$field['type']
+ .$field['auto_increment']
+ .$field['null']
+ .$field['unique']
+ .$field['default'];
+ }
- if (count($primary_keys) > 0)
- {
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
- }
+ // --------------------------------------------------------------------
- if (is_array($keys) && count($keys) > 0)
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
{
- foreach ($keys as $key)
- {
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->db->escape_identifiers($key));
-
- $sql .= ",\n\tUNIQUE (".implode(', ', $key).')';
- }
+ case 'ENUM':
+ case 'SET':
+ $attributes['TYPE'] = 'TEXT';
+ return;
+ default: return;
}
-
- return $sql."\n)";
}
// --------------------------------------------------------------------
/**
- * Alter table query
+ * Field attribute AUTO_INCREMENT
*
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
- *
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param string the table name
- * @param string the column definition
- * @param string the default value
- * @param bool should 'NOT NULL' be added
- * @param string the field after which we should add the new field
- * @return string
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
*/
- protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ protected function _attr_auto_increment(&$attributes, &$field)
{
- /* SQLite only supports adding new columns and it does
- * NOT support the AFTER statement. Each new column will
- * be added as the last one in the table.
- */
- if ($alter_type !== 'ADD COLUMN')
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
{
- // Not supported
- return FALSE;
- }
+ $field['type'] = 'INTEGER PRIMARY KEY';
+ $field['default'] = '';
+ $field['null'] = '';
+ $field['unique'] = '';
+ $field['auto_increment'] = ' AUTOINCREMENT';
- return 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name)
- .' '.$column_definition
- .($default_value != '' ? " DEFAULT '".$default_value."'" : '')
- // If NOT NULL is specified, the field must have a DEFAULT value other than NULL
- .(($null !== NULL && $default_value !== 'NULL') ? ' NOT NULL' : ' NULL');
+ $this->primary_keys = array();
+ }
}
}
diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php
index 214841412..0e6335f73 100644
--- a/system/database/drivers/sqlite/sqlite_result.php
+++ b/system/database/drivers/sqlite/sqlite_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLite Result Class
@@ -113,9 +114,9 @@ class CI_DB_sqlite_result extends CI_DB_result {
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
- * result set starts at zero
+ * result set starts at zero.
*
- * @param int $n = 0
+ * @param int $n
* @return bool
*/
protected function _data_seek($n = 0)
@@ -144,7 +145,7 @@ class CI_DB_sqlite_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php
index 1bcb42d9f..222d02712 100644
--- a/system/database/drivers/sqlite/sqlite_utility.php
+++ b/system/database/drivers/sqlite/sqlite_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLite Utility Class
@@ -34,18 +35,16 @@
*/
class CI_DB_sqlite_utility extends CI_DB_utility {
- protected $_list_databases = FALSE;
-
/**
- * SQLite Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return mixed
*/
protected function _backup($params = array())
{
// Currently unsupported
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php
index 22c72b9b8..9a2c1eefc 100644
--- a/system/database/drivers/sqlite3/sqlite3_driver.php
+++ b/system/database/drivers/sqlite3/sqlite3_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLite3 Database Adapter Class
@@ -41,13 +42,24 @@
*/
class CI_DB_sqlite3_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'sqlite3';
- // The character used for escaping
- protected $_escape_char = '"';
+ // --------------------------------------------------------------------
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
protected $_random_keyword = ' RANDOM()';
+ // --------------------------------------------------------------------
+
/**
* Non-persistent database connection
*
@@ -119,7 +131,7 @@ class CI_DB_sqlite3_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -179,8 +191,8 @@ class CI_DB_sqlite3_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -239,7 +251,7 @@ class CI_DB_sqlite3_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
@@ -257,7 +269,7 @@ class CI_DB_sqlite3_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -273,7 +285,7 @@ class CI_DB_sqlite3_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -303,9 +315,9 @@ class CI_DB_sqlite3_driver extends CI_DB {
*
* Generates a platform-specific replace string from the supplied data
*
- * @param string the table name
- * @param array the insert keys
- * @param array the insert values
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
* @return string
*/
protected function _replace($table, $keys, $values)
@@ -320,10 +332,10 @@ class CI_DB_sqlite3_driver extends CI_DB {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command, then,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
diff --git a/system/database/drivers/sqlite3/sqlite3_forge.php b/system/database/drivers/sqlite3/sqlite3_forge.php
index f9ae5bcce..e9b91e972 100644
--- a/system/database/drivers/sqlite3/sqlite3_forge.php
+++ b/system/database/drivers/sqlite3/sqlite3_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLite3 Forge Class
@@ -35,9 +36,43 @@
class CI_DB_sqlite3_forge extends CI_DB_forge {
/**
+ * UNSIGNED support
+ *
+ * @var bool|array
+ */
+ protected $_unsigned = FALSE;
+
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * @param object &$db Database object
+ * @return void
+ */
+ public function __construct(&$db)
+ {
+ parent::__construct($db);
+
+ if (version_compare($this->db->version(), '3.3', '<'))
+ {
+ $this->create_table_if = FALSE;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Create database
*
- * @param string the database name
+ * @param string $db_name
* @return bool
*/
public function create_database($db_name = '')
@@ -52,7 +87,7 @@ class CI_DB_sqlite3_forge extends CI_DB_forge {
/**
* Drop database
*
- * @param string the database name (ignored)
+ * @param string $db_name (ignored)
* @return bool
*/
public function drop_database($db_name = '')
@@ -84,125 +119,95 @@ class CI_DB_sqlite3_forge extends CI_DB_forge {
// --------------------------------------------------------------------
/**
- * Create Table
+ * ALTER TABLE
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @todo implement drop_column(), modify_column()
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ protected function _alter_table($alter_type, $table, $field)
{
- $sql = 'CREATE TABLE ';
-
- // IF NOT EXISTS added to SQLite in 3.3.0
- if ($if_not_exists === TRUE && version_compare($this->db->version(), '3.3.0', '>=') === TRUE)
- {
- $sql .= 'IF NOT EXISTS ';
- }
-
- $sql .= $this->db->escape_identifiers($table).' (';
- $current_field_count = 0;
-
- foreach ($fields as $field => $attributes)
+ if ($alter_type === 'DROP' OR $alter_type === 'CHANGE')
{
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
- {
- $sql .= "\n\t".$attributes;
- }
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
-
- empty($attributes['CONSTRAINT']) OR $sql .= '('.$attributes['CONSTRAINT'].')';
-
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
+ // drop_column():
+ // BEGIN TRANSACTION;
+ // CREATE TEMPORARY TABLE t1_backup(a,b);
+ // INSERT INTO t1_backup SELECT a,b FROM t1;
+ // DROP TABLE t1;
+ // CREATE TABLE t1(a,b);
+ // INSERT INTO t1 SELECT a,b FROM t1_backup;
+ // DROP TABLE t1_backup;
+ // COMMIT;
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
+ return FALSE;
+ }
- $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
+ return parent::_alter_table($alter_type, $table, $field);
+ }
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
- }
+ // --------------------------------------------------------------------
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
- }
- }
+ /**
+ * Process column
+ *
+ * @param array $field
+ * @return string
+ */
+ protected function _process_column($field)
+ {
+ return $this->db->escape_identifiers($field['name'])
+ .' '.$field['type']
+ .$field['auto_increment']
+ .$field['null']
+ .$field['unique']
+ .$field['default'];
+ }
- if (count($primary_keys) > 0)
- {
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
- }
+ // --------------------------------------------------------------------
- if (is_array($keys) && count($keys) > 0)
+ /**
+ * Field attribute TYPE
+ *
+ * Performs a data type mapping between different databases.
+ *
+ * @param array &$attributes
+ * @return void
+ */
+ protected function _attr_type(&$attributes)
+ {
+ switch (strtoupper($attributes['TYPE']))
{
- foreach ($keys as $key)
- {
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->db->escape_identifiers($key));
-
- $sql .= ",\n\tUNIQUE (".implode(', ', $key).')';
- }
+ case 'ENUM':
+ case 'SET':
+ $attributes['TYPE'] = 'TEXT';
+ return;
+ default: return;
}
-
- return $sql."\n)";
}
// --------------------------------------------------------------------
/**
- * Alter table query
- *
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * Field attribute AUTO_INCREMENT
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param string the table name
- * @param string the column definition
- * @param string the default value
- * @param bool should 'NOT NULL' be added
- * @param string the field after which we should add the new field
- * @return string
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
*/
- protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ protected function _attr_auto_increment(&$attributes, &$field)
{
- /* SQLite only supports adding new columns and it does
- * NOT support the AFTER statement. Each new column will
- * be added as the last one in the table.
- */
- if ($alter_type !== 'ADD COLUMN')
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
{
- // Not supported
- return FALSE;
- }
+ $field['type'] = 'INTEGER PRIMARY KEY';
+ $field['default'] = '';
+ $field['null'] = '';
+ $field['unique'] = '';
+ $field['auto_increment'] = ' AUTOINCREMENT';
- return 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name)
- .' '.$column_definition
- .($default_value !== '' ? ' DEFAULT '.$default_value : '')
- // If NOT NULL is specified, the field must have a DEFAULT value other than NULL
- .(($null !== NULL && $default_value !== 'NULL') ? ' NOT NULL' : ' NULL');
+ $this->primary_keys = array();
+ }
}
}
diff --git a/system/database/drivers/sqlite3/sqlite3_result.php b/system/database/drivers/sqlite3/sqlite3_result.php
index 35aecda36..153e3480a 100644
--- a/system/database/drivers/sqlite3/sqlite3_result.php
+++ b/system/database/drivers/sqlite3/sqlite3_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLite3 Result Class
@@ -37,9 +38,6 @@
*/
class CI_DB_sqlite3_result extends CI_DB_result {
- // num_fields() might be called multiple times, so we'll use this one to cache it's result
- protected $_num_fields;
-
/**
* Number of fields in the result set
*
@@ -47,9 +45,7 @@ class CI_DB_sqlite3_result extends CI_DB_result {
*/
public function num_fields()
{
- return ( ! is_int($this->_num_fields))
- ? $this->_num_fields = $this->result_id->numColumns()
- : $this->_num_fields;
+ return $this->result_id->numColumns();
}
// --------------------------------------------------------------------
@@ -134,7 +130,7 @@ class CI_DB_sqlite3_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
@@ -165,9 +161,9 @@ class CI_DB_sqlite3_result extends CI_DB_result {
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
- * result set starts at zero
+ * result set starts at zero.
*
- * @param $n = 0 (ignored)
+ * @param int $n (ignored)
* @return array
*/
protected function _data_seek($n = 0)
diff --git a/system/database/drivers/sqlite3/sqlite3_utility.php b/system/database/drivers/sqlite3/sqlite3_utility.php
index f58c3d168..c7736cc6d 100644
--- a/system/database/drivers/sqlite3/sqlite3_utility.php
+++ b/system/database/drivers/sqlite3/sqlite3_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLite3 Utility Class
@@ -34,18 +35,16 @@
*/
class CI_DB_sqlite3_utility extends CI_DB_utility {
- protected $_list_databases = FALSE;
-
/**
- * SQLite Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return mixed
*/
protected function _backup($params = array())
{
// Not supported
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php
index 32f1a59d6..09ccc0200 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_driver.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.0.3
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLSRV Database Adapter Class
@@ -40,20 +41,38 @@
*/
class CI_DB_sqlsrv_driver extends CI_DB {
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'sqlsrv';
- // The character used for escaping
- protected $_escape_char = '"';
+ // --------------------------------------------------------------------
+ /**
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
protected $_random_keyword = ' NEWID()';
- // SQLSRV-specific properties
+ /**
+ * Quoted identifier flag
+ *
+ * Whether to use SQL-92 standard quoted identifier
+ * (double quotes) or brackets for identifier escaping.
+ *
+ * @var bool
+ */
protected $_quoted_identifier = TRUE;
+ // --------------------------------------------------------------------
+
/**
- * Non-persistent database connection
+ * Database connection
*
- * @param bool $pooling = FALSE
+ * @param bool $pooling
* @return resource
*/
public function db_connect($pooling = FALSE)
@@ -106,7 +125,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Select the database
*
- * @param string database name
+ * @param string $database
* @return bool
*/
public function db_select($database = '')
@@ -130,7 +149,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Execute the query
*
- * @param string an SQL query
+ * @param string $sql an SQL query
* @return resource
*/
protected function _execute($sql)
@@ -145,7 +164,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Begin Transaction
*
- * @param bool $test_mode = FALSE
+ * @param bool $test_mode
* @return bool
*/
public function trans_begin($test_mode = FALSE)
@@ -205,8 +224,8 @@ class CI_DB_sqlsrv_driver extends CI_DB {
/**
* Escape String
*
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
+ * @param string $str
+ * @param bool $like Whether or not the string will be used in a LIKE condition
* @return string
*/
public function escape_str($str, $like = FALSE)
@@ -256,8 +275,12 @@ class CI_DB_sqlsrv_driver extends CI_DB {
{
return $this->data_cache['version'];
}
+ elseif ( ! $this->conn_id)
+ {
+ $this->initialize();
+ }
- if (($info = sqlsrv_server_info($this->conn_id)) === FALSE)
+ if ( ! $this->conn_id OR ($info = sqlsrv_server_info($this->conn_id)) === FALSE)
{
return FALSE;
}
@@ -273,7 +296,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
* Generates a platform-specific query string so that the table names can be fetched
*
* @param bool
- * @return string
+ * @return string $prefix_limit
*/
protected function _list_tables($prefix_limit = FALSE)
{
@@ -297,7 +320,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _list_columns($table = '')
@@ -312,7 +335,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific query so that the column data can be retrieved
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _field_data($table)
@@ -365,8 +388,8 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
- * @param string the table name
- * @param array the update data
+ * @param string $table
+ * @param array $values
* @return string
*/
protected function _update($table, $values)
@@ -383,10 +406,10 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific truncate string from the supplied data
*
- * If the database does not support the truncate() command,
+ * If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _truncate($table)
@@ -401,7 +424,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @param string the table name
+ * @param string $table
* @return string
*/
protected function _delete($table)
@@ -417,11 +440,11 @@ class CI_DB_sqlsrv_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @param string the sql query string
+ * @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
@@ -473,6 +496,29 @@ class CI_DB_sqlsrv_driver extends CI_DB {
// --------------------------------------------------------------------
/**
+ * Insert batch statement
+ *
+ * Generates a platform-specific insert string from the supplied data.
+ *
+ * @param string $table Table name
+ * @param array $keys INSERT keys
+ * @param array $values INSERT values
+ * @return string|bool
+ */
+ protected function _insert_batch($table, $keys, $values)
+ {
+ // Multiple-value inserts are only supported as of SQL Server 2008
+ if (version_compare($this->version(), '10', '>='))
+ {
+ return parent::_insert_batch($table, $keys, $values);
+ }
+
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Close DB Connection
*
* @return void
diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php
index ccdb36929..da8f68c56 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_forge.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.0.3
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLSRV Forge Class
@@ -34,124 +35,99 @@
*/
class CI_DB_sqlsrv_forge extends CI_DB_forge {
- protected $_drop_table = 'DROP TABLE %s';
-
/**
- * Create Table
+ * CREATE TABLE IF statement
*
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param bool should 'IF NOT EXISTS' be added to the SQL
- * @return string
+ * @var string
*/
- protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
- {
- $sql = ($if_not_exists === TRUE)
- ? "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'".$table."') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\n"
- : '';
-
- $sql .= 'CREATE TABLE '.$this->db->escape_identifiers($table).' (';
-
- $current_field_count = 0;
- foreach ($fields as $field => $attributes)
- {
- // Numeric field names aren't allowed in databases, so if the key is
- // numeric, we know it was assigned by PHP and the developer manually
- // entered the field information, so we'll simply add it to the list
- if (is_numeric($field))
- {
- $sql .= "\n\t".$attributes;
- }
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
-
- if (stripos($attributes['TYPE'], 'INT') === FALSE && ! empty($attributes['CONSTRAINT']))
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
- }
-
- if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE)
- {
- $sql .= ' UNSIGNED';
- }
+ protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE";
- if (isset($attributes['DEFAULT']))
- {
- $sql .= " DEFAULT '".$attributes['DEFAULT']."'";
- }
-
- $sql .= ( ! empty($attributes['NULL']) && $attribues['NULL'] === TRUE)
- ? ' NULL' : ' NOT NULL';
+ /**
+ * DROP TABLE IF statement
+ *
+ * @var string
+ */
+ protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE";
- if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
- {
- $sql .= ' AUTO_INCREMENT';
- }
- }
+ /**
+ * UNSIGNED support
+ *
+ * @var array
+ */
+ protected $_unsigned = array(
+ 'TINYINT' => 'SMALLINT',
+ 'SMALLINT' => 'INT',
+ 'INT' => 'BIGINT',
+ 'REAL' => 'FLOAT'
+ );
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
- {
- $sql .= ',';
- }
- }
+ // --------------------------------------------------------------------
- if (count($primary_keys) > 0)
+ /**
+ * ALTER TABLE
+ *
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
+ */
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
{
- $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')';
+ return parent::_alter_table($alter_type, $table, $field);
}
- if (is_array($keys) && count($keys) > 0)
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN ';
+ $sqls = array();
+ for ($i = 0, $c = count($field); $i < $c; $i++)
{
- foreach ($keys as $key)
- {
- $key = is_array($key)
- ? $this->db->escape_identifiers($key)
- : array($this->escape_identifiers($key));
-
- $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')';
- }
+ $sqls[] = $sql.$this->_process_column($field[$i]);
}
- return $sql."\n)";
+ return $sqls;
}
// --------------------------------------------------------------------
/**
- * Alter table query
+ * Field attribute TYPE
*
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * Performs a data type mapping between different databases.
*
- * @param string the ALTER type (ADD, DROP, CHANGE)
- * @param string the column name
- * @param string the table name
- * @param string the column definition
- * @param string the default value
- * @param bool should 'NOT NULL' be added
- * @param string the field after which we should add the new field
- * @return string
+ * @param array &$attributes
+ * @return void
*/
- protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ protected function _attr_type(&$attributes)
{
- $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name);
-
- // DROP has everything it needs now.
- if ($alter_type === 'DROP')
+ switch (strtoupper($attributes['TYPE']))
{
- return $sql;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'INTEGER':
+ $attributes['TYPE'] = 'INT';
+ return;
+ default: return;
}
+ }
- return $sql.' '.$column_definition
- .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '')
- .($null === NULL ? ' NULL' : ' NOT NULL')
- .($after_field != '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
+ // --------------------------------------------------------------------
+
+ /**
+ * Field attribute AUTO_INCREMENT
+ *
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
+ */
+ protected function _attr_auto_increment(&$attributes, &$field)
+ {
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
+ {
+ $field['auto_increment'] = ' IDENTITY(1,1)';
+ }
}
}
diff --git a/system/database/drivers/sqlsrv/sqlsrv_result.php b/system/database/drivers/sqlsrv/sqlsrv_result.php
index fb7a68647..6d24cc995 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_result.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLSRV Result Class
@@ -145,7 +146,7 @@ class CI_DB_sqlsrv_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @param string
+ * @param string $class_name
* @return object
*/
protected function _fetch_object($class_name = 'stdClass')
diff --git a/system/database/drivers/sqlsrv/sqlsrv_utility.php b/system/database/drivers/sqlsrv/sqlsrv_utility.php
index d518cc15a..2bc7f9e03 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_utility.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_utility.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 2.0.3
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* SQLSRV Utility Class
@@ -34,19 +35,32 @@
*/
class CI_DB_sqlsrv_utility extends CI_DB_utility {
+ /**
+ * List databases statement
+ *
+ * @var string
+ */
protected $_list_databases = 'EXEC sp_helpdb'; // Can also be: EXEC sp_databases
+
+ /**
+ * OPTIMIZE TABLE statement
+ *
+ * @var string
+ */
protected $_optimize_table = 'ALTER INDEX all ON %s REORGANIZE';
+ // --------------------------------------------------------------------
+
/**
- * SQLSRV Export
+ * Export
*
- * @param array Preferences
+ * @param array $params Preferences
* @return bool
*/
protected function _backup($params = array())
{
// Currently unsupported
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php
index ed2fe3c4a..0e66e4b77 100644
--- a/system/helpers/array_helper.php
+++ b/system/helpers/array_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Array Helpers
diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php
index 3aac14db8..e9b167fa9 100644
--- a/system/helpers/captcha_helper.php
+++ b/system/helpers/captcha_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter CAPTCHA Helper
diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php
index f396c76b0..02841409d 100644
--- a/system/helpers/cookie_helper.php
+++ b/system/helpers/cookie_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Cookie Helpers
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php
index 5d9251526..0fa400d7e 100644
--- a/system/helpers/date_helper.php
+++ b/system/helpers/date_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Date Helpers
@@ -449,20 +450,13 @@ if ( ! function_exists('human_to_unix'))
return FALSE;
}
- $split = explode(' ', $datestr);
+ sscanf($datestr, '%d-%d-%d %s %s', $year, $month, $day, $time, $ampm);
+ sscanf($time, '%d:%d:%d', $hour, $min, $sec);
+ isset($sec) OR $sec = 0;
- list($year, $month, $day) = explode('-', $split[0]);
-
- $ex = explode(':', $split['1']);
-
- $hour = (int) $ex[0];
- $min = (int) $ex[1];
- $sec = ( ! empty($ex[2]) && preg_match('/[0-9]{1,2}/', $ex[2]))
- ? (int) $ex[2] : 0;
-
- if (isset($split[2]))
+ if (isset($ampm))
{
- $ampm = strtolower($split[2]);
+ $ampm = strtolower($ampm);
if ($ampm[0] === 'p' && $hour < 12)
{
diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php
index 7d6b6770e..49dcfc8a9 100644
--- a/system/helpers/directory_helper.php
+++ b/system/helpers/directory_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Directory Helpers
@@ -46,9 +47,10 @@ if ( ! function_exists('directory_map'))
* representation of it. Sub-folders contained with the
* directory will be mapped as well.
*
- * @param string path to source
- * @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc)
- * @param bool whether to show hidden files
+ * @param string $source_dir Path to source
+ * @param int $directory_depth Depth of directories to traverse
+ * (0 = fully recursive, 1 = current dir, etc)
+ * @param bool $hidden Whether to show hidden files
* @return array
*/
function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE)
@@ -67,9 +69,11 @@ if ( ! function_exists('directory_map'))
continue;
}
+ @is_dir($source_dir.$file) AND $file .= DIRECTORY_SEPARATOR;
+
if (($directory_depth < 1 OR $new_depth > 0) && @is_dir($source_dir.$file))
{
- $filedata[$file] = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $new_depth, $hidden);
+ $filedata[$file] = directory_map($source_dir.$file, $new_depth, $hidden);
}
else
{
diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php
index 2c26a36d5..8fe66e222 100644
--- a/system/helpers/download_helper.php
+++ b/system/helpers/download_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Download Helpers
diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php
index 2a63b36c9..dfb166a5a 100644
--- a/system/helpers/email_helper.php
+++ b/system/helpers/email_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Email Helpers
@@ -42,7 +43,8 @@ if ( ! function_exists('valid_email'))
/**
* Validate email address
*
- * @param string
+ * @deprecated 3.0.0 Use PHP's filter_var() instead
+ * @param string $email
* @return bool
*/
function valid_email($email)
@@ -58,12 +60,13 @@ if ( ! function_exists('send_email'))
/**
* Send an email
*
- * @param string
- * @param string
- * @param string
+ * @deprecated 3.0.0 Use PHP's mail() instead
+ * @param string $recipient
+ * @param string $subject
+ * @param string $message
* @return bool
*/
- function send_email($recipient, $subject = 'Test email', $message = 'Hello World')
+ function send_email($recipient, $subject, $message)
{
return mail($recipient, $subject, $message);
}
diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php
index 8f23a3d54..aebb6e47a 100644
--- a/system/helpers/file_helper.php
+++ b/system/helpers/file_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter File Helpers
@@ -65,12 +66,12 @@ if ( ! function_exists('write_file'))
* Writes data to the file specified in the path.
* Creates a new file if non-existent.
*
- * @param string path to file
- * @param string file data
- * @param int
+ * @param string $path File path
+ * @param string $data Data to write
+ * @param string $mode fopen() mode (default: 'wb')
* @return bool
*/
- function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE)
+ function write_file($path, $data, $mode = 'wb')
{
if ( ! $fp = @fopen($path, $mode))
{
@@ -98,13 +99,13 @@ if ( ! function_exists('delete_files'))
* If the second parameter is set to TRUE, any directories contained
* within the supplied base directory will be nuked as well.
*
- * @param string path to file
- * @param bool whether to delete any directories found in the path
- * @param int
- * @param bool whether to skip deleting .htaccess and index page files
+ * @param string $path File path
+ * @param bool $del_dir Whether to delete any directories found in the path
+ * @param bool $htdocs Whether to skip deleting .htaccess and index page files
+ * @param int $_level Current directory depth level (default: 0; internal use only)
* @return bool
*/
- function delete_files($path, $del_dir = FALSE, $level = 0, $htdocs = FALSE)
+ function delete_files($path, $del_dir = FALSE, $htdocs = FALSE, $_level = 0)
{
// Trim the trailing slash
$path = rtrim($path, '/\\');
@@ -120,7 +121,7 @@ if ( ! function_exists('delete_files'))
{
if (is_dir($path.DIRECTORY_SEPARATOR.$filename) && $filename[0] !== '.')
{
- delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1, $htdocs);
+ delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $htdocs, $_level + 1);
}
elseif ($htdocs !== TRUE OR ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename))
{
@@ -130,7 +131,7 @@ if ( ! function_exists('delete_files'))
}
@closedir($current_dir);
- if ($del_dir === TRUE && $level > 0)
+ if ($del_dir === TRUE && $_level > 0)
{
return @rmdir($path);
}
@@ -318,12 +319,12 @@ if ( ! function_exists('get_mime_by_extension'))
* Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience
* It should NOT be trusted, and should certainly NOT be used for security
*
- * @param string path to file
- * @return mixed
+ * @param string $filename File name
+ * @return string
*/
- function get_mime_by_extension($file)
+ function get_mime_by_extension($filename)
{
- $extension = strtolower(substr(strrchr($file, '.'), 1));
+ $extension = strtolower(substr(strrchr($filename, '.'), 1));
static $mimes;
@@ -358,7 +359,7 @@ if ( ! function_exists('symbolic_permissions'))
* Takes a numeric value representing a file's permissions and returns
* standard symbolic notation representing that value
*
- * @param int
+ * @param int $perms Permissions
* @return string
*/
function symbolic_permissions($perms)
@@ -425,7 +426,7 @@ if ( ! function_exists('octal_permissions'))
* Takes a numeric value representing a file's permissions and returns
* a three character string representing the file's octal permissions
*
- * @param int
+ * @param int $perms Permissions
* @return string
*/
function octal_permissions($perms)
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index 622622c0e..e7bea92cc 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -22,7 +22,9 @@
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
+ * @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Form Helpers
@@ -124,9 +126,9 @@ if ( ! function_exists('form_hidden'))
* Generates hidden fields. You can pass a simple key/value string or
* an associative array with multiple values.
*
- * @param mixed
- * @param string
- * @param bool
+ * @param mixed $name Field name
+ * @param string $value Field value
+ * @param bool $recursing
* @return string
*/
function form_hidden($name, $value = '', $recursing = FALSE)
@@ -149,7 +151,7 @@ if ( ! function_exists('form_hidden'))
if ( ! is_array($value))
{
- $form .= '<input type="hidden" name="'.$name.'" value="'.html_escape($value)."\" />\n";
+ $form .= '<input type="hidden" name="'.$name.'" value="'.form_prep($value)."\" />\n";
}
else
{
@@ -243,9 +245,9 @@ if ( ! function_exists('form_textarea'))
/**
* Textarea field
*
- * @param mixed
- * @param string
- * @param string
+ * @param mixed $data
+ * @param string $value
+ * @param string $extra
* @return string
*/
function form_textarea($data = '', $value = '', $extra = '')
@@ -263,7 +265,7 @@ if ( ! function_exists('form_textarea'))
}
$name = is_array($data) ? $data['name'] : $data;
- return '<textarea '._parse_form_attributes($data, $defaults).$extra.'>'.html_escape($val)."</textarea>\n";
+ return '<textarea '._parse_form_attributes($data, $defaults).$extra.'>'.form_prep($val, TRUE)."</textarea>\n";
}
}
@@ -298,10 +300,10 @@ if ( ! function_exists('form_dropdown'))
/**
* Drop-down Menu
*
- * @param mixed $name = ''
- * @param mixed $options = array()
- * @param mixed $selected = array()
- * @param mixed $extra = array()
+ * @param mixed $name
+ * @param mixed $options
+ * @param mixed $selected
+ * @param mixed $extra
* @return string
*/
function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
@@ -349,7 +351,7 @@ if ( ! function_exists('form_dropdown'))
foreach ($val as $optgroup_key => $optgroup_val)
{
$sel = in_array($optgroup_key, $selected) ? ' selected="selected"' : '';
- $form .= '<option value="'.html_escape($optgroup_key).'"'.$sel.'>'
+ $form .= '<option value="'.form_prep($optgroup_key).'"'.$sel.'>'
.(string) $optgroup_val."</option>\n";
}
@@ -357,7 +359,7 @@ if ( ! function_exists('form_dropdown'))
}
else
{
- $form .= '<option value="'.html_escape($key).'"'
+ $form .= '<option value="'.form_prep($key).'"'
.(in_array($key, $selected) ? ' selected="selected"' : '').'>'
.(string) $val."</option>\n";
}
@@ -600,17 +602,28 @@ if ( ! function_exists('form_prep'))
*
* Formats text so that it can be safely placed in a form field in the event it has HTML tags.
*
- * @todo Remove in version 3.1+.
- * @deprecated 3.0.0 This function has been broken for a long time
- * and is now just an alias for html_escape(). It's
- * second argument is ignored.
- * @param string $str = ''
- * @param string $field_name = ''
- * @return string
+ * @param string|string[] $str Value to escape
+ * @param bool $is_textarea Whether we're escaping for a textarea element
+ * @return string|string[] Escaped values
*/
- function form_prep($str = '', $field_name = '')
+ function form_prep($str = '', $is_textarea = FALSE)
{
- return html_escape($str);
+ if (is_array($str))
+ {
+ foreach (array_keys($str) as $key)
+ {
+ $str[$key] = form_prep($str[$key], $is_textarea);
+ }
+
+ return $str;
+ }
+
+ if ($is_textarea === TRUE)
+ {
+ return str_replace(array('<', '>'), array('&lt;', '&gt;'), stripslashes($str));
+ }
+
+ return str_replace(array("'", '"'), array('&#39;', '&quot;'), stripslashes($str));
}
}
@@ -625,23 +638,21 @@ if ( ! function_exists('set_value'))
* re-populate an input field or textarea. If Form Validation
* is active it retrieves the info from the validation class
*
- * @param string
- * @param string
- * @return mixed
+ * @param string $field Field name
+ * @param string $default Default value
+ * @param bool $is_textarea Whether the field is a textarea element
+ * @return string
*/
- function set_value($field = '', $default = '')
+ function set_value($field = '', $default = '', $is_textarea = FALSE)
{
if (FALSE === ($OBJ =& _get_validation_object()))
{
- if ( ! isset($_POST[$field]))
- {
- return html_escape($default);
- }
-
- return html_escape($_POST[$field]);
+ return isset($_POST[$field])
+ ? form_prep($_POST[$field], $is_textarea)
+ : form_prep($default, $is_textarea);
}
- return html_escape($OBJ->set_value($field, $default));
+ return form_prep($OBJ->set_value($field, $default), $is_textarea);
}
}
@@ -862,8 +873,8 @@ if ( ! function_exists('_parse_form_attributes'))
*
* Helper function used by some of the form helpers
*
- * @param array
- * @param array
+ * @param array $attributes List of attributes
+ * @param array $default Default values
* @return string
*/
function _parse_form_attributes($attributes, $default)
@@ -891,7 +902,7 @@ if ( ! function_exists('_parse_form_attributes'))
{
if ($key === 'value')
{
- $val = html_escape($val);
+ $val = form_prep($val);
}
elseif ($key === 'name' && ! strlen($default['name']))
{
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index 2372e8174..fa49f7d75 100644
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter HTML Helpers
@@ -156,12 +157,12 @@ if ( ! function_exists('br'))
/**
* Generates HTML BR tags based on number supplied
*
- * @param int
+ * @param int $count Number of times to repeat the tag
* @return string
*/
- function br($num = 1)
+ function br($count = 1)
{
- return str_repeat('<br />', $num);
+ return str_repeat('<br />', $count);
}
}
diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php
index 647d840e4..59cb296b2 100644
--- a/system/helpers/inflector_helper.php
+++ b/system/helpers/inflector_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Inflector Helpers
@@ -44,7 +45,7 @@ if ( ! function_exists('singular'))
*
* Takes a plural word and makes it singular
*
- * @param string
+ * @param string $str Input string
* @return string
*/
function singular($str)
@@ -108,11 +109,10 @@ if ( ! function_exists('plural'))
*
* Takes a singular word and makes it plural
*
- * @param string
- * @param bool
+ * @param string $str Input string
* @return string
*/
- function plural($str, $force = FALSE)
+ function plural($str)
{
$result = strval($str);
@@ -165,7 +165,7 @@ if ( ! function_exists('camelize'))
*
* Takes multiple words separated by spaces or underscores and camelizes them
*
- * @param string
+ * @param string $str Input string
* @return string
*/
function camelize($str)
@@ -183,7 +183,7 @@ if ( ! function_exists('underscore'))
*
* Takes multiple words separated by spaces and underscores them
*
- * @param string
+ * @param string $str Input string
* @return string
*/
function underscore($str)
@@ -201,8 +201,8 @@ if ( ! function_exists('humanize'))
*
* Takes multiple words separated by the separator and changes them to spaces
*
- * @param string $str
- * @param string $separator
+ * @param string $str Input string
+ * @param string $separator Input separator
* @return string
*/
function humanize($str, $separator = '_')
@@ -218,12 +218,12 @@ if ( ! function_exists('is_countable'))
/**
* Checks if the given word has a plural version.
*
- * @param string the word to check
- * @return bool if the word is countable
+ * @param string $word Word to check
+ * @return bool
*/
function is_countable($word)
{
- return ! in_array(strtolower(strval($word)),
+ return ! in_array(strtolower($word),
array(
'equipment', 'information', 'rice', 'money',
'species', 'series', 'fish', 'meta'
diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php
index bd567ed79..658be6de7 100644
--- a/system/helpers/language_helper.php
+++ b/system/helpers/language_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Language Helpers
diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php
index e49f2f7a0..b93096543 100644
--- a/system/helpers/number_helper.php
+++ b/system/helpers/number_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Number Helpers
diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php
index 166fef065..5a798b118 100644
--- a/system/helpers/path_helper.php
+++ b/system/helpers/path_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Path Helpers
diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php
index 8bbd06684..898a49c80 100644
--- a/system/helpers/security_helper.php
+++ b/system/helpers/security_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Security Helpers
diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php
index b6b2afcf4..4b491758e 100644
--- a/system/helpers/smiley_helper.php
+++ b/system/helpers/smiley_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Smiley Helpers
@@ -130,10 +131,9 @@ if ( ! function_exists('get_clickable_smileys'))
*
* @param string the URL to the folder containing the smiley images
* @param array
- * @param array
* @return array
*/
- function get_clickable_smileys($image_url, $alias = '', $smileys = NULL)
+ function get_clickable_smileys($image_url, $alias = '')
{
// For backward compatibility with js_insert_smiley
if (is_array($alias))
@@ -142,7 +142,7 @@ if ( ! function_exists('get_clickable_smileys'))
}
elseif (FALSE === ($smileys = _get_smiley_array()))
{
- return $smileys;
+ return FALSE;
}
// Add a trailing slash to the file path if needed
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php
index c5c493452..9fc24559a 100644
--- a/system/helpers/string_helper.php
+++ b/system/helpers/string_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter String Helpers
@@ -50,6 +51,9 @@ if ( ! function_exists('trim_slashes'))
*
* this/that/theother
*
+ * @todo Remove in version 3.1+.
+ * @deprecated 3.0.0 This is just an alias for PHP's native trim()
+ *
* @param string
* @return string
*/
@@ -214,10 +218,10 @@ if ( ! function_exists('random_string'))
break;
}
return substr(str_shuffle(str_repeat($pool, ceil($len / strlen($pool)))), 0, $len);
- case 'unique':
+ case 'unique': // todo: remove in 3.1+
case 'md5':
return md5(uniqid(mt_rand()));
- case 'encrypt':
+ case 'encrypt': // todo: remove in 3.1+
case 'sha1':
return sha1(uniqid(mt_rand(), TRUE));
}
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index 89602fc28..cce659231 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Text Helpers
diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php
index 96bedd026..48f1f1147 100644
--- a/system/helpers/typography_helper.php
+++ b/system/helpers/typography_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Typography Helpers
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
index dc77246dc..0aa358a0b 100644
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter URL Helpers
@@ -473,9 +474,11 @@ if ( ! function_exists('url_title'))
* human-friendly URL string with a "separator" string
* as the word separator.
*
- * @param string the string
- * @param string the separator
- * @param bool
+ * @todo Remove old 'dash' and 'underscore' usage in 3.1+.
+ * @param string $str Input string
+ * @param string $separator Word separator
+ * (usually '-' or '_')
+ * @param bool $lowercase Wether to transform the output string to lowercase
* @return string
*/
function url_title($str, $separator = '-', $lowercase = FALSE)
@@ -524,10 +527,11 @@ if ( ! function_exists('redirect'))
* For very fine grained control over headers, you could use the Output
* Library's set_header() function.
*
- * @param string the URL
- * @param string the method: location or refresh
- * @param int
- * @return string
+ * @param string $uri URL
+ * @param string $method Redirect method
+ * 'auto', 'location' or 'refresh'
+ * @param int $code HTTP Response status code
+ * @return void
*/
function redirect($uri = '', $method = 'auto', $code = NULL)
{
diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php
index 1431777d2..c3dfdcddb 100644
--- a/system/helpers/xml_helper.php
+++ b/system/helpers/xml_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter XML Helpers
diff --git a/system/language/english/calendar_lang.php b/system/language/english/calendar_lang.php
index a70a564e8..288eb91d8 100644
--- a/system/language/english/calendar_lang.php
+++ b/system/language/english/calendar_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['cal_su'] = 'Su';
$lang['cal_mo'] = 'Mo';
diff --git a/system/language/english/date_lang.php b/system/language/english/date_lang.php
index 6683e4c69..db1e9e0ff 100644
--- a/system/language/english/date_lang.php
+++ b/system/language/english/date_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['date_year'] = 'Year';
$lang['date_years'] = 'Years';
diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php
index 479cbb167..50ce6bbd6 100644
--- a/system/language/english/db_lang.php
+++ b/system/language/english/db_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['db_invalid_connection_str'] = 'Unable to determine the database settings based on the connection string you submitted.';
$lang['db_unable_to_connect'] = 'Unable to connect to your database server using the provided settings.';
@@ -40,8 +41,8 @@ $lang['db_field_param_missing'] = 'To fetch fields requires the name of the tabl
$lang['db_unsupported_function'] = 'This feature is not available for the database you are using.';
$lang['db_transaction_failure'] = 'Transaction failure: Rollback performed.';
$lang['db_unable_to_drop'] = 'Unable to drop the specified database.';
-$lang['db_unsuported_feature'] = 'Unsupported feature of the database platform you are using.';
-$lang['db_unsuported_compression'] = 'The file compression format you chose is not supported by your server.';
+$lang['db_unsupported_feature'] = 'Unsupported feature of the database platform you are using.';
+$lang['db_unsupported_compression'] = 'The file compression format you chose is not supported by your server.';
$lang['db_filepath_error'] = 'Unable to write data to the file path you have submitted.';
$lang['db_invalid_cache_path'] = 'The cache path you submitted is not valid or writable.';
$lang['db_table_name_required'] = 'A table name is required for that operation.';
diff --git a/system/language/english/email_lang.php b/system/language/english/email_lang.php
index 0de9aa27e..646a49647 100644
--- a/system/language/english/email_lang.php
+++ b/system/language/english/email_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['email_must_be_array'] = 'The email validation method must be passed an array.';
$lang['email_invalid_address'] = 'Invalid email address: %s';
diff --git a/system/language/english/form_validation_lang.php b/system/language/english/form_validation_lang.php
index 6ff0cc2f4..52ca21f92 100644
--- a/system/language/english/form_validation_lang.php
+++ b/system/language/english/form_validation_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['required'] = 'The %s field is required.';
$lang['isset'] = 'The %s field must have a value.';
diff --git a/system/language/english/ftp_lang.php b/system/language/english/ftp_lang.php
index 24923c8d8..090a88c28 100644
--- a/system/language/english/ftp_lang.php
+++ b/system/language/english/ftp_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['ftp_no_connection'] = 'Unable to locate a valid connection ID. Please make sure you are connected before peforming any file routines.';
$lang['ftp_unable_to_connect'] = 'Unable to connect to your FTP server using the supplied hostname.';
diff --git a/system/language/english/imglib_lang.php b/system/language/english/imglib_lang.php
index d755437f2..296c4af68 100644
--- a/system/language/english/imglib_lang.php
+++ b/system/language/english/imglib_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['imglib_source_image_required'] = 'You must specify a source image in your preferences.';
$lang['imglib_gd_required'] = 'The GD image library is required for this feature.';
diff --git a/system/language/english/migration_lang.php b/system/language/english/migration_lang.php
index a262d3018..689a72952 100644
--- a/system/language/english/migration_lang.php
+++ b/system/language/english/migration_lang.php
@@ -24,6 +24,7 @@
* @since Version 3.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['migration_none_found'] = 'No migrations were found.';
$lang['migration_not_found'] = 'No migration could be found with the version number: %d.';
@@ -34,6 +35,5 @@ $lang['migration_missing_up_method'] = 'The migration class "%s" is missing an "
$lang['migration_missing_down_method'] = 'The migration class "%s" is missing a "down" method.';
$lang['migration_invalid_filename'] = 'Migration "%s" has an invalid filename.';
-
/* End of file migration_lang.php */
/* Location: ./system/language/english/migration_lang.php */ \ No newline at end of file
diff --git a/system/language/english/number_lang.php b/system/language/english/number_lang.php
index 429c64738..019013a49 100644
--- a/system/language/english/number_lang.php
+++ b/system/language/english/number_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['terabyte_abbr'] = 'TB';
$lang['gigabyte_abbr'] = 'GB';
diff --git a/system/language/english/profiler_lang.php b/system/language/english/profiler_lang.php
index 112527faa..6ffcd9349 100644
--- a/system/language/english/profiler_lang.php
+++ b/system/language/english/profiler_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['profiler_database'] = 'DATABASE';
$lang['profiler_controller_info'] = 'CLASS/METHOD';
diff --git a/system/language/english/unit_test_lang.php b/system/language/english/unit_test_lang.php
index 146ec25b4..ed452615f 100644
--- a/system/language/english/unit_test_lang.php
+++ b/system/language/english/unit_test_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['ut_test_name'] = 'Test Name';
$lang['ut_test_datatype'] = 'Test Datatype';
diff --git a/system/language/english/upload_lang.php b/system/language/english/upload_lang.php
index d70e7f20f..88f9ac372 100644
--- a/system/language/english/upload_lang.php
+++ b/system/language/english/upload_lang.php
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
$lang['upload_userfile_not_set'] = 'Unable to find a post variable called userfile.';
$lang['upload_file_exceeds_limit'] = 'The uploaded file exceeds the maximum allowed size in your PHP configuration file.';
diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php
index 7ec2380a5..e76fdc557 100644
--- a/system/libraries/Cache/Cache.php
+++ b/system/libraries/Cache/Cache.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -18,12 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Caching Class
diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php
index c85034f95..46e633463 100644
--- a/system/libraries/Cache/drivers/Cache_apc.php
+++ b/system/libraries/Cache/drivers/Cache_apc.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -18,12 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter APC Caching Class
diff --git a/system/libraries/Cache/drivers/Cache_dummy.php b/system/libraries/Cache/drivers/Cache_dummy.php
index 3f2b4b956..a3bdc3c80 100644
--- a/system/libraries/Cache/drivers/Cache_dummy.php
+++ b/system/libraries/Cache/drivers/Cache_dummy.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -18,12 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Dummy Caching Class
diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php
index 37d77c268..5d370380e 100644
--- a/system/libraries/Cache/drivers/Cache_file.php
+++ b/system/libraries/Cache/drivers/Cache_file.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -18,12 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter File Caching Class
diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php
index bf90f6197..fae002347 100644
--- a/system/libraries/Cache/drivers/Cache_memcached.php
+++ b/system/libraries/Cache/drivers/Cache_memcached.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -18,12 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Memcached Caching Class
diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php
index e4a26b5f0..60033344b 100644
--- a/system/libraries/Cache/drivers/Cache_redis.php
+++ b/system/libraries/Cache/drivers/Cache_redis.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -18,12 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 3.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Redis Caching Class
diff --git a/system/libraries/Cache/drivers/Cache_wincache.php b/system/libraries/Cache/drivers/Cache_wincache.php
index 89e9f77c8..383b3afdd 100644
--- a/system/libraries/Cache/drivers/Cache_wincache.php
+++ b/system/libraries/Cache/drivers/Cache_wincache.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -18,12 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 3.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Wincache Caching Class
diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php
index 95f537e42..caa496a5e 100644
--- a/system/libraries/Calendar.php
+++ b/system/libraries/Calendar.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Calendar Class
diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php
index d4b17fa36..035a6a42b 100644
--- a/system/libraries/Cart.php
+++ b/system/libraries/Cart.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Shopping Cart Class
@@ -193,7 +194,7 @@ class CI_Cart {
$items['qty'] = (float) $items['qty'];
// If the quantity is zero or blank there's nothing for us to do
- if ( ! is_numeric($items['qty']) OR $items['qty'] == 0)
+ if ($items['qty'] == 0)
{
return FALSE;
}
@@ -224,15 +225,6 @@ class CI_Cart {
// Prep the price. Remove leading zeros and anything that isn't a number or decimal point.
$items['price'] = (float) $items['price'];
- // Is the price a valid number?
- if ( ! is_numeric($items['price']))
- {
- log_message('error', 'An invalid price was submitted for product ID: '.$items['id']);
- return FALSE;
- }
-
- // --------------------------------------------------------------------
-
// We now need to create a unique identifier for the item being inserted into the cart.
// Every time something is added to the cart it is stored in the master cart array.
// Each row in the cart array, however, must have a unique index that identifies not only
@@ -350,12 +342,6 @@ class CI_Cart {
// Prep the quantity
$items['qty'] = (float) $items['qty'];
- // Is the quantity a number?
- if ( ! is_numeric($items['qty']))
- {
- return FALSE;
- }
-
// Is the quantity zero? If so we will remove the item from the cart.
// If the quantity is greater than zero we are updating
if ($items['qty'] == 0)
diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php
index 5d642b982..621d22631 100644
--- a/system/libraries/Driver.php
+++ b/system/libraries/Driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Driver Library Class
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index 7280466a5..d23be1af1 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Email Class
@@ -38,55 +39,340 @@
*/
class CI_Email {
+ /**
+ * Used as the User-Agent and X-Mailer headers' value.
+ *
+ * @var string
+ */
public $useragent = 'CodeIgniter';
+
+ /**
+ * Path to the Sendmail binary.
+ *
+ * @var string
+ */
public $mailpath = '/usr/sbin/sendmail'; // Sendmail path
+
+ /**
+ * Which method to use for sending e-mails.
+ *
+ * @var string 'mail', 'sendmail' or 'smtp'
+ */
public $protocol = 'mail'; // mail/sendmail/smtp
- public $smtp_host = ''; // SMTP Server. Example: mail.earthlink.net
- public $smtp_user = ''; // SMTP Username
- public $smtp_pass = ''; // SMTP Password
- public $smtp_port = 25; // SMTP Port
- public $smtp_timeout = 5; // SMTP Timeout in seconds
- public $smtp_crypto = ''; // SMTP Encryption. Can be null, tls or ssl.
- public $wordwrap = TRUE; // TRUE/FALSE - Turns word-wrap on/off
- public $wrapchars = 76; // Number of characters to wrap at.
- public $mailtype = 'text'; // text/html - Defines email formatting
- public $charset = 'utf-8'; // Default char set: iso-8859-1 or us-ascii
+
+ /**
+ * STMP Server host
+ *
+ * @var string
+ */
+ public $smtp_host = '';
+
+ /**
+ * SMTP Username
+ *
+ * @var string
+ */
+ public $smtp_user = '';
+
+ /**
+ * SMTP Password
+ *
+ * @var string
+ */
+ public $smtp_pass = '';
+
+ /**
+ * SMTP Server port
+ *
+ * @var int
+ */
+ public $smtp_port = 25;
+
+ /**
+ * SMTP connection timeout in seconds
+ *
+ * @var int
+ */
+ public $smtp_timeout = 5;
+
+ /**
+ * SMTP Encryption
+ *
+ * @var string NULL, 'tls' or 'ssl'
+ */
+ public $smtp_crypto = NULL;
+
+ /**
+ * Whether to apply word-wrapping to the message body.
+ *
+ * @var bool
+ */
+ public $wordwrap = TRUE;
+
+ /**
+ * Number of characters to wrap at.
+ *
+ * @see CI_Email::$wordwrap
+ * @var int
+ */
+ public $wrapchars = 76;
+
+ /**
+ * Message format.
+ *
+ * @var string 'text' or 'html'
+ */
+ public $mailtype = 'text';
+
+ /**
+ * Character set (default: utf-8)
+ *
+ * @var string
+ */
+ public $charset = 'utf-8';
+
+ /**
+ * Multipart message
+ *
+ * @var string 'mixed' (in the body) or 'related' (separate)
+ */
public $multipart = 'mixed'; // "mixed" (in the body) or "related" (separate)
- public $alt_message = ''; // Alternative message for HTML emails
- public $validate = FALSE; // TRUE/FALSE - Enables email validation
+
+ /**
+ * Alternative message (for HTML messages only)
+ *
+ * @var string
+ */
+ public $alt_message = '';
+
+ /**
+ * Whether to validate e-mail addresses.
+ *
+ * @var bool
+ */
+ public $validate = FALSE;
+
+ /**
+ * X-Priority header value.
+ *
+ * @var int 1-5
+ */
public $priority = 3; // Default priority (1 - 5)
+
+ /**
+ * Newline character sequence.
+ * Use "\r\n" to comply with RFC 822.
+ *
+ * @link http://www.ietf.org/rfc/rfc822.txt
+ * @var string "\r\n" or "\n"
+ */
public $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822)
- public $crlf = "\n"; // The RFC 2045 compliant CRLF for quoted-printable is "\r\n". Apparently some servers,
- // even on the receiving end think they need to muck with CRLFs, so using "\n", while
- // distasteful, is the only thing that seems to work for all environments.
- public $dsn = FALSE; // Delivery Status Notification
- public $send_multipart = TRUE; // TRUE/FALSE - Yahoo does not like multipart alternative, so this is an override. Set to FALSE for Yahoo.
- public $bcc_batch_mode = FALSE; // TRUE/FALSE - Turns on/off Bcc batch feature
- public $bcc_batch_size = 200; // If bcc_batch_mode = TRUE, sets max number of Bccs in each batch
+ /**
+ * CRLF character sequence
+ *
+ * RFC 2045 specifies that for 'quoted-printable' encoding,
+ * "\r\n" must be used. However, it appears that some servers
+ * (even on the receiving end) don't handle it properly and
+ * switching to "\n", while improper, is the only solution
+ * that seems to work for all environments.
+ *
+ * @link http://www.ietf.org/rfc/rfc822.txt
+ * @var string
+ */
+ public $crlf = "\n";
+
+ /**
+ * Whether to use Delivery Status Notification.
+ *
+ * @var bool
+ */
+ public $dsn = FALSE;
+
+ /**
+ * Whether to send multipart alternatives.
+ * Yahoo! doesn't seem to like these.
+ *
+ * @var bool
+ */
+ public $send_multipart = TRUE;
+
+ /**
+ * Whether to send messages to BCC recipients in batches.
+ *
+ * @var bool
+ */
+ public $bcc_batch_mode = FALSE;
+
+ /**
+ * BCC Batch max number size.
+ *
+ * @see CI_Email::$bcc_batch_mode
+ * @var int
+ */
+ public $bcc_batch_size = 200;
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Whether PHP is running in safe mode. Initialized by the class constructor.
+ *
+ * @var bool
+ */
protected $_safe_mode = FALSE;
+
+ /**
+ * Subject header
+ *
+ * @var string
+ */
protected $_subject = '';
+
+ /**
+ * Message body
+ *
+ * @var string
+ */
protected $_body = '';
+
+ /**
+ * Final message body to be sent.
+ *
+ * @var string
+ */
protected $_finalbody = '';
+
+ /**
+ * multipart/alternative boundary
+ *
+ * @var string
+ */
protected $_alt_boundary = '';
+
+ /**
+ * Attachment boundary
+ *
+ * @var string
+ */
protected $_atc_boundary = '';
+
+ /**
+ * Final headers to send
+ *
+ * @var string
+ */
protected $_header_str = '';
+
+ /**
+ * SMTP Connection socket placeholder
+ *
+ * @var resource
+ */
protected $_smtp_connect = '';
+
+ /**
+ * Mail encoding
+ *
+ * @var string '8bit' or '7bit'
+ */
protected $_encoding = '8bit';
- protected $_IP = FALSE;
+
+ /**
+ * Whether to perform SMTP authentication
+ *
+ * @var bool
+ */
protected $_smtp_auth = FALSE;
+
+ /**
+ * Whether to send a Reply-To header
+ *
+ * @var bool
+ */
protected $_replyto_flag = FALSE;
+
+ /**
+ * Debug messages
+ *
+ * @see CI_Email::print_debugger()
+ * @var string
+ */
protected $_debug_msg = array();
+
+ /**
+ * Recipients
+ *
+ * @var string[]
+ */
protected $_recipients = array();
+
+ /**
+ * CC Recipients
+ *
+ * @var string[]
+ */
protected $_cc_array = array();
+
+ /**
+ * BCC Recipients
+ *
+ * @var string[]
+ */
protected $_bcc_array = array();
+
+ /**
+ * Message headers
+ *
+ * @var string[]
+ */
protected $_headers = array();
+
+ /**
+ * Attachment data
+ *
+ * @var array
+ */
protected $_attachments = array();
+
+ /**
+ * Valid $protocol values
+ *
+ * @see CI_Email::$protocol
+ * @var string[]
+ */
protected $_protocols = array('mail', 'sendmail', 'smtp');
- protected $_base_charsets = array('us-ascii', 'iso-2022-'); // 7-bit charsets (excluding language suffix)
+
+ /**
+ * Base charsets
+ *
+ * Character sets valid for 7-bit encoding,
+ * excluding language suffix.
+ *
+ * @var string[]
+ */
+ protected $_base_charsets = array('us-ascii', 'iso-2022-');
+
+ /**
+ * Bit depths
+ *
+ * Valid mail encodings
+ *
+ * @see CI_Email::$_encoding
+ * @var string[]
+ */
protected $_bit_depths = array('7bit', '8bit');
+
+ /**
+ * $priority translations
+ *
+ * Actual values to send with the X-Priority header
+ *
+ * @var string[]
+ */
protected $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)');
+ // --------------------------------------------------------------------
+
/**
* Constructor - Sets Email Preferences
*
@@ -771,7 +1057,7 @@ class CI_Email {
}
// Reduce multiple spaces
- $str = preg_replace('| +|', ' ', $str);
+ $body = preg_replace('| +|', ' ', $body);
return ($this->wordwrap)
? $this->word_wrap($body, 76)
@@ -1446,11 +1732,14 @@ class CI_Email {
*/
protected function _send_with_sendmail()
{
- $fp = @popen($this->mailpath.' -oi -f '.$this->clean_email($this->_headers['From']).' -t'.' -r '.$this->clean_email($this->_headers['Return-Path']), 'w');
-
- if ($fp === FALSE OR $fp === NULL)
+ // is popen() enabled?
+ if ( ! function_usable('popen')
+ OR FALSE === ($fp = @popen(
+ $this->mailpath.' -oi -f '.$this->clean_email($this->_headers['From'])
+ .' -t -r '.$this->clean_email($this->_headers['Return-Path'])
+ , 'w'))
+ ) // server probably has popen disabled, so nothing we can do to get a verbose error.
{
- // server probably has popen disabled, so nothing we can do to get a verbose error.
return FALSE;
}
diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php
index 73ab8ca7d..cdb0a6452 100644
--- a/system/libraries/Encrypt.php
+++ b/system/libraries/Encrypt.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Encryption Class
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index c1bf51935..e50eee4f2 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Form Validation Class
@@ -439,11 +440,10 @@ class CI_Form_validation {
// Load the language file containing error messages
$this->CI->lang->load('form_validation');
- // Cycle through the rules for each field, match the
- // corresponding $_POST item and test for errors
+ // Cycle through the rules for each field and match the corresponding $validation_data item
foreach ($this->_field_data as $field => $row)
{
- // Fetch the data from the corresponding $_POST or validation array and cache it in the _field_data array.
+ // Fetch the data from the validation_data array item and cache it in the _field_data array.
// Depending on whether the field name is an array or a string will determine where we get it from.
if ($row['is_array'] === TRUE)
{
@@ -453,7 +453,13 @@ class CI_Form_validation {
{
$this->_field_data[$field]['postdata'] = $validation_array[$field];
}
+ }
+ // Execute validation rules
+ // Note: A second foreach (for now) is required in order to avoid false-positives
+ // for rules like 'matches', which correlate to other validation fields.
+ foreach ($this->_field_data as $field => $row)
+ {
// Don't try to validate if we have no rules set
if (empty($row['rules']))
{
@@ -1323,6 +1329,11 @@ class CI_Form_validation {
*/
public function prep_for_form($data = '')
{
+ if ($this->_safe_form_data === FALSE OR empty($data))
+ {
+ return $data;
+ }
+
if (is_array($data))
{
foreach ($data as $key => $val)
@@ -1333,11 +1344,6 @@ class CI_Form_validation {
return $data;
}
- if ($this->_safe_form_data === FALSE OR $data === '')
- {
- return $data;
- }
-
return str_replace(array("'", '"', '<', '>'), array('&#39;', '&quot;', '&lt;', '&gt;'), stripslashes($data));
}
diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php
index ae85fdf37..60c03b5ad 100644
--- a/system/libraries/Ftp.php
+++ b/system/libraries/Ftp.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* FTP Class
@@ -36,18 +37,63 @@
*/
class CI_FTP {
+ /**
+ * FTP Server hostname
+ *
+ * @var string
+ */
public $hostname = '';
+
+ /**
+ * FTP Username
+ *
+ * @var string
+ */
public $username = '';
+
+ /**
+ * FTP Password
+ *
+ * @var string
+ */
public $password = '';
+
+ /**
+ * FTP Server port
+ *
+ * @var int
+ */
public $port = 21;
+
+ /**
+ * Passive mode flag
+ *
+ * @var bool
+ */
public $passive = TRUE;
+
+ /**
+ * Debug flag
+ *
+ * Specifies whether to display error messages.
+ *
+ * @var bool
+ */
public $debug = FALSE;
+
+ /**
+ * Connection
+ *
+ * @var resource
+ */
public $conn_id = FALSE;
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
- * @param array $config = array()
+ * @param array $config
* @return void
*/
public function __construct($config = array())
@@ -65,7 +111,7 @@ class CI_FTP {
/**
* Initialize preferences
*
- * @param array
+ * @param array $config
* @return void
*/
public function initialize($config = array())
@@ -87,7 +133,7 @@ class CI_FTP {
/**
* FTP Connect
*
- * @param array the connection values
+ * @param array $config Connection values
* @return bool
*/
public function connect($config = array())
@@ -167,8 +213,8 @@ class CI_FTP {
* so we do it by trying to change to a particular directory.
* Internally, this parameter is only used by the "mirror" function below.
*
- * @param string
- * @param bool
+ * @param string $path
+ * @param bool $supress_debug
* @return bool
*/
public function changedir($path = '', $supress_debug = FALSE)
@@ -197,8 +243,8 @@ class CI_FTP {
/**
* Create a directory
*
- * @param string
- * @param int
+ * @param string $path
+ * @param int $permissions
* @return bool
*/
public function mkdir($path = '', $permissions = NULL)
@@ -233,10 +279,10 @@ class CI_FTP {
/**
* Upload a file to the server
*
- * @param string
- * @param string
- * @param string
- * @param int
+ * @param string $locpath
+ * @param string $rempath
+ * @param string $mode
+ * @param int $permissions
* @return bool
*/
public function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL)
@@ -287,9 +333,9 @@ class CI_FTP {
/**
* Download a file from a remote server to the local server
*
- * @param string
- * @param string
- * @param string
+ * @param string $rempath
+ * @param string $locpath
+ * @param string $mode
* @return bool
*/
public function download($rempath, $locpath, $mode = 'auto')
@@ -328,9 +374,9 @@ class CI_FTP {
/**
* Rename (or move) a file
*
- * @param string
- * @param string
- * @param bool
+ * @param string $old_file
+ * @param string $new_file
+ * @param bool $move
* @return bool
*/
public function rename($old_file, $new_file, $move = FALSE)
@@ -359,8 +405,8 @@ class CI_FTP {
/**
* Move a file
*
- * @param string
- * @param string
+ * @param string $old_file
+ * @param string $new_file
* @return bool
*/
public function move($old_file, $new_file)
@@ -373,7 +419,7 @@ class CI_FTP {
/**
* Rename (or move) a file
*
- * @param string
+ * @param string $filepath
* @return bool
*/
public function delete_file($filepath)
@@ -403,7 +449,7 @@ class CI_FTP {
* Delete a folder and recursively delete everything (including sub-folders)
* containted within it.
*
- * @param string
+ * @param string $filepath
* @return bool
*/
public function delete_dir($filepath)
@@ -450,8 +496,8 @@ class CI_FTP {
/**
* Set file permissions
*
- * @param string the file path
- * @param int the permissions
+ * @param string $path File path
+ * @param int $perm Permissions
* @return bool
*/
public function chmod($path, $perm)
@@ -480,7 +526,7 @@ class CI_FTP {
/**
* FTP List files in the specified directory
*
- * @param string $path = '.'
+ * @param string $path
* @return array
*/
public function list_files($path = '.')
@@ -503,8 +549,8 @@ class CI_FTP {
* Whatever the directory structure of the original file path will be
* recreated on the server.
*
- * @param string path to source with trailing slash
- * @param string path to destination - include the base folder with trailing slash
+ * @param string $locpath Path to source with trailing slash
+ * @param string $rempath Path to destination - include the base folder with trailing slash
* @return bool
*/
public function mirror($locpath, $rempath)
@@ -550,7 +596,7 @@ class CI_FTP {
/**
* Extract the file extension
*
- * @param string
+ * @param string $filename
* @return string
*/
protected function _getext($filename)
@@ -569,7 +615,7 @@ class CI_FTP {
/**
* Set the upload type
*
- * @param string
+ * @param string $ext Filename extension
* @return string
*/
protected function _settype($ext)
@@ -616,7 +662,7 @@ class CI_FTP {
/**
* Display error message
*
- * @param string
+ * @param string $line
* @return void
*/
protected function _error($line)
diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php
index ef4187847..9379e3ec8 100644
--- a/system/libraries/Image_lib.php
+++ b/system/libraries/Image_lib.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Image Manipulation class
@@ -866,7 +867,11 @@ class CI_Image_lib {
}
$retval = 1;
- @exec($cmd, $output, $retval);
+ // exec() might be disabled
+ if (function_usable('exec'))
+ {
+ @exec($cmd, $output, $retval);
+ }
// Did it work?
if ($retval > 0)
@@ -946,7 +951,11 @@ class CI_Image_lib {
$cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp';
$retval = 1;
- @exec($cmd, $output, $retval);
+ // exec() might be disabled
+ if (function_usable('exec'))
+ {
+ @exec($cmd, $output, $retval);
+ }
// Did it work?
if ($retval > 0)
@@ -958,7 +967,7 @@ class CI_Image_lib {
// With NetPBM we have to create a temporary image.
// If you try manipulating the original it fails so
// we have to rename the temp file.
- copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path);
+ copy($this->dest_folder.'netpbm.tmp', $this->full_dst_path);
unlink($this->dest_folder.'netpbm.tmp');
@chmod($this->full_dst_path, FILE_WRITE_MODE);
diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php
index 60309cd83..9a15cddaa 100644
--- a/system/libraries/Javascript.php
+++ b/system/libraries/Javascript.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Javascript Class
@@ -36,12 +37,19 @@
*/
class CI_Javascript {
+ /**
+ * JavaScript location
+ *
+ * @var string
+ */
protected $_javascript_location = 'js';
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
- * @param array $params = array()
+ * @param array $params
* @return void
*/
public function __construct($params = array())
@@ -586,8 +594,8 @@ class CI_Javascript {
*
* gather together all script needing to be output
*
- * @param string $view_var = 'script_foot'
- * @param bool $script_tags = TRUE
+ * @param string $view_var
+ * @param bool $script_tags
* @return string
*/
public function compile($view_var = 'script_foot', $script_tags = TRUE)
@@ -616,8 +624,8 @@ class CI_Javascript {
*
* Outputs a <script> tag with the source as an external js file
*
- * @param string $external_file = ''
- * @param bool $relative = FALSE
+ * @param string $external_file
+ * @param bool $relative
* @return string
*/
public function external($external_file = '', $relative = FALSE)
diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php
index f67725c18..275aeb048 100644
--- a/system/libraries/Migration.php
+++ b/system/libraries/Migration.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 3.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Migration Class
diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php
index 36b57b332..ae8dba072 100644
--- a/system/libraries/Pagination.php
+++ b/system/libraries/Pagination.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Pagination Class
@@ -36,46 +37,269 @@
*/
class CI_Pagination {
- protected $base_url = ''; // The page we are linking to
- protected $prefix = ''; // A custom prefix added to the path.
- protected $suffix = ''; // A custom suffix added to the path.
- protected $total_rows = 0; // Total number of items (database results)
- protected $per_page = 10; // Max number of items you want shown per page
- protected $num_links = 2; // Number of "digit" links to show before/after the currently viewed page
- protected $cur_page = 0; // The current page being viewed
- protected $use_page_numbers = FALSE; // Use page number for segment instead of offset
- protected $first_link = '&lsaquo; First';
- protected $next_link = '&gt;';
- protected $prev_link = '&lt;';
- protected $last_link = 'Last &rsaquo;';
- protected $uri_segment = 3;
- protected $full_tag_open = '';
- protected $full_tag_close = '';
- protected $first_tag_open = '';
- protected $first_tag_close = '';
- protected $last_tag_open = '';
- protected $last_tag_close = '';
- protected $first_url = ''; // Alternative URL for the First Page.
- protected $cur_tag_open = '<strong>';
- protected $cur_tag_close = '</strong>';
- protected $next_tag_open = '';
- protected $next_tag_close = '';
- protected $prev_tag_open = '';
- protected $prev_tag_close = '';
- protected $num_tag_open = '';
- protected $num_tag_close = '';
+ /**
+ * Base URL
+ *
+ * The page that we're linking to
+ *
+ * @var string
+ */
+ protected $base_url = '';
+
+ /**
+ * Prefix
+ *
+ * @var string
+ */
+ protected $prefix = '';
+
+ /**
+ * Suffix
+ *
+ * @var string
+ */
+ protected $suffix = '';
+
+ /**
+ * Total number of items
+ *
+ * @var int
+ */
+ protected $total_rows = 0;
+
+ /**
+ * Items per page
+ *
+ * @var int
+ */
+ protected $per_page = 10;
+
+ /**
+ * Number of links to show
+ *
+ * Relates to "digit" type links shown before/after
+ * the currently viewed page.
+ *
+ * @var int
+ */
+ protected $num_links = 2;
+
+ /**
+ * Current page
+ *
+ * @var int
+ */
+ protected $cur_page = 0;
+
+ /**
+ * Use page numbers flag
+ *
+ * Whether to use actual page numbers instead of an offset
+ *
+ * @var bool
+ */
+ protected $use_page_numbers = FALSE;
+
+ /**
+ * First link
+ *
+ * @var string
+ */
+ protected $first_link = '&lsaquo; First';
+
+ /**
+ * Next link
+ *
+ * @var string
+ */
+ protected $next_link = '&gt;';
+
+ /**
+ * Previous link
+ *
+ * @var string
+ */
+ protected $prev_link = '&lt;';
+
+ /**
+ * Last link
+ *
+ * @var string
+ */
+ protected $last_link = 'Last &rsaquo;';
+
+ /**
+ * URI Segment
+ *
+ * @var int
+ */
+ protected $uri_segment = 3;
+
+ /**
+ * Full tag open
+ *
+ * @var string
+ */
+ protected $full_tag_open = '';
+
+ /**
+ * Full tag close
+ *
+ * @var string
+ */
+ protected $full_tag_close = '';
+
+ /**
+ * First tag open
+ *
+ * @var string
+ */
+ protected $first_tag_open = '';
+
+ /**
+ * First tag close
+ *
+ * @var string
+ */
+ protected $first_tag_close = '';
+
+ /**
+ * Last tag open
+ *
+ * @var string
+ */
+ protected $last_tag_open = '';
+
+ /**
+ * Last tag close
+ *
+ * @var string
+ */
+ protected $last_tag_close = '';
+
+ /**
+ * First URL
+ *
+ * An alternative URL for the first page
+ *
+ * @var string
+ */
+ protected $first_url = '';
+
+ /**
+ * Current tag open
+ *
+ * @var string
+ */
+ protected $cur_tag_open = '<strong>';
+
+ /**
+ * Current tag close
+ *
+ * @var string
+ */
+ protected $cur_tag_close = '</strong>';
+
+ /**
+ * Next tag open
+ *
+ * @var string
+ */
+ protected $next_tag_open = '';
+
+ /**
+ * Next tag close
+ *
+ * @var string
+ */
+ protected $next_tag_close = '';
+
+ /**
+ * Previous tag open
+ *
+ * @var string
+ */
+ protected $prev_tag_open = '';
+
+ /**
+ * Previous tag close
+ *
+ * @var string
+ */
+ protected $prev_tag_close = '';
+
+ /**
+ * Number tag open
+ *
+ * @var string
+ */
+ protected $num_tag_open = '';
+
+ /**
+ * Number tag close
+ *
+ * @var string
+ */
+ protected $num_tag_close = '';
+
+ /**
+ * Page query string flag
+ *
+ * @var bool
+ */
protected $page_query_string = FALSE;
+
+ /**
+ * Query string segment
+ *
+ * @var string
+ */
protected $query_string_segment = 'per_page';
- protected $display_pages = TRUE;
- protected $_attributes = '';
- protected $_link_types = array();
+
+ /**
+ * Display pages flag
+ *
+ * @var bool
+ */
+ protected $display_pages = TRUE;
+
+ /**
+ * Attributes
+ *
+ * @var string
+ */
+ protected $_attributes = '';
+
+ /**
+ * Link types
+ *
+ * "rel" attribute
+ *
+ * @see CI_Pagination::_attr_rel()
+ * @var array
+ */
+ protected $_link_types = array();
+
+ /**
+ * Reuse query string flag
+ *
+ * @var bool
+ */
protected $reuse_query_string = FALSE;
- protected $data_page_attr = 'data-ci-pagination-page';
+
+ /**
+ * Data page attribute
+ *
+ * @var string
+ */
+ protected $data_page_attr = 'data-ci-pagination-page';
+
+ // --------------------------------------------------------------------
/**
* Constructor
*
- * @param array initialization parameters
+ * @param array $params Initialization parameters
* @return void
*/
public function __construct($params = array())
@@ -89,7 +313,7 @@ class CI_Pagination {
/**
* Initialize Preferences
*
- * @param array initialization parameters
+ * @param array $params Initialization parameters
* @return void
*/
public function initialize($params = array())
@@ -352,7 +576,7 @@ class CI_Pagination {
/**
* Parse attributes
*
- * @param array
+ * @param array $attributes
* @return void
*/
protected function _parse_attributes($attributes)
@@ -376,7 +600,7 @@ class CI_Pagination {
* Add "rel" attribute
*
* @link http://www.w3.org/TR/html5/links.html#linkTypes
- * @param string
+ * @param string $type
* @return string
*/
protected function _attr_rel($type)
diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php
index b64c78254..d29eede02 100644
--- a/system/libraries/Parser.php
+++ b/system/libraries/Parser.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Parser Class
diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php
index 1e961f6df..1c97e3481 100644
--- a/system/libraries/Profiler.php
+++ b/system/libraries/Profiler.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Profiler Class
@@ -74,12 +75,14 @@ class CI_Profiler {
*/
protected $CI;
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Class constructor
*
* Initialize Profiler
*
- * @param array $config
+ * @param array $config Parameters
*/
public function __construct($config = array())
{
@@ -111,7 +114,7 @@ class CI_Profiler {
*
* Sets the private _compile_* properties to enable/disable Profiler sections
*
- * @param mixed
+ * @param mixed $config
* @return void
*/
public function set_sections($config)
@@ -190,11 +193,24 @@ class CI_Profiler {
$dbs = array();
// Let's determine which databases are currently connected to
- foreach (get_object_vars($this->CI) as $CI_object)
+ foreach (get_object_vars($this->CI) as $name => $cobject)
{
- if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB'))
+ if (is_object($cobject))
{
- $dbs[] = $CI_object;
+ if ($cobject instanceof CI_DB)
+ {
+ $dbs[get_class($this->CI).':$'.$name] = $cobject;
+ }
+ elseif ($cobject instanceof CI_Model)
+ {
+ foreach (get_object_vars($cobject) as $mname => $mobject)
+ {
+ if ($mobject instanceof CI_DB)
+ {
+ $dbs[get_class($cobject).':$'.$mname] = $mobject;
+ }
+ }
+ }
}
}
@@ -219,7 +235,7 @@ class CI_Profiler {
$output = "\n\n";
$count = 0;
- foreach ($dbs as $db)
+ foreach ($dbs as $name => $db)
{
$hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : '';
@@ -233,7 +249,7 @@ class CI_Profiler {
$output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">'
."\n"
.'<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_database')
- .':&nbsp; '.$db->database.'&nbsp;&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries')
+ .':&nbsp; '.$db->database.' ('.$name.')&nbsp;&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries')
.': '.count($db->queries).'&nbsp;&nbsp;'.$show_hide_js."</legend>\n\n\n"
.'<table style="width:100%;'.$hide_queries.'" id="ci_profiler_queries_db_'.$count."\">\n";
diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php
index fec9b5b31..96e65f154 100755
--- a/system/libraries/Session/Session.php
+++ b/system/libraries/Session/Session.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -18,12 +18,13 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 2.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Session Class
@@ -51,10 +52,29 @@
*/
class CI_Session extends CI_Driver_Library {
+ /**
+ * Initialization parameters
+ *
+ * @var array
+ */
public $params = array();
+
+ /**
+ * Current driver in use
+ *
+ * @var string
+ */
protected $current = NULL;
+
+ /**
+ * User data
+ *
+ * @var array
+ */
protected $userdata = array();
+ // ------------------------------------------------------------------------
+
const FLASHDATA_KEY = 'flash';
const FLASHDATA_NEW = ':new:';
const FLASHDATA_OLD = ':old:';
@@ -62,6 +82,8 @@ class CI_Session extends CI_Driver_Library {
const EXPIRATION_KEY = '__expirations';
const TEMP_EXP_DEF = 300;
+ // ------------------------------------------------------------------------
+
/**
* CI_Session constructor
*
@@ -506,7 +528,7 @@ class CI_Session extends CI_Driver_Library {
foreach ($this->all_userdata() as $name => $value)
{
$parts = explode(self::FLASHDATA_NEW, $name);
- if (is_array($parts) && count($parts) === 2)
+ if (count($parts) === 2)
{
$new_name = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$parts[1];
$this->set_userdata($new_name, $value);
@@ -595,8 +617,16 @@ class CI_Session extends CI_Driver_Library {
*/
abstract class CI_Session_driver extends CI_Driver {
+ /**
+ * CI Singleton
+ *
+ * @see get_instance()
+ * @var object
+ */
protected $CI;
+ // ------------------------------------------------------------------------
+
/**
* Constructor
*
diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php
index 2f1bf3531..3c4848265 100755
--- a/system/libraries/Session/drivers/Session_cookie.php
+++ b/system/libraries/Session/drivers/Session_cookie.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -9,7 +9,7 @@
* Licensed under the Open Software License version 3.0
*
* This source file is subject to the Open Software License (OSL 3.0) that is
- * bundled with this package in the files license.txt / license.rst. It is
+ * bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
* http://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to obtain it
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Cookie-based session management driver
@@ -540,11 +541,25 @@ class CI_Session_cookie extends CI_Session_driver {
// Check for database
if ($this->sess_use_database === TRUE)
{
+ $this->CI->db->where('session_id', $old_sessid);
+
+ if ($this->sess_match_ip === TRUE)
+ {
+ $this->CI->db->where('ip_address', $this->CI->input->ip_address());
+ }
+
+ if ($this->sess_match_useragent === TRUE)
+ {
+ $this->CI->db->where('user_agent', trim(substr($this->CI->input->user_agent(), 0, 120)));
+ }
+
// Update the session ID and last_activity field in the DB
- $this->CI->db->update($this->sess_table_name, array(
- 'last_activity' => $this->now,
- 'session_id' => $this->userdata['session_id']
- ), array('session_id' => $old_sessid));
+ $this->CI->db->update($this->sess_table_name,
+ array(
+ 'last_activity' => $this->now,
+ 'session_id' => $this->userdata['session_id']
+ )
+ );
}
// Write the cookie
@@ -590,7 +605,19 @@ class CI_Session_cookie extends CI_Session_driver {
// Run the update query
// Any time we change the session id, it gets updated immediately,
// so our where clause below is always safe
- $this->CI->db->update($this->sess_table_name, $set, array('session_id' => $this->userdata['session_id']));
+ $this->CI->db->where('session_id', $this->userdata['session_id']);
+
+ if ($this->sess_match_ip === TRUE)
+ {
+ $this->CI->db->where('ip_address', $this->CI->input->ip_address());
+ }
+
+ if ($this->sess_match_useragent === TRUE)
+ {
+ $this->CI->db->where('user_agent', trim(substr($this->CI->input->user_agent(), 0, 120)));
+ }
+
+ $this->CI->db->update($this->sess_table_name, $set);
// Clear dirty flag to prevent double updates
$this->data_dirty = FALSE;
diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php
index a837b89f6..3e700ad5d 100755
--- a/system/libraries/Session/drivers/Session_native.php
+++ b/system/libraries/Session/drivers/Session_native.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -9,7 +9,7 @@
* Licensed under the Open Software License version 3.0
*
* This source file is subject to the Open Software License (OSL 3.0) that is
- * bundled with this package in the files license.txt / license.rst. It is
+ * bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
* http://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to obtain it
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Native PHP session management driver
diff --git a/system/libraries/Table.php b/system/libraries/Table.php
index 0f8404d85..886fb6581 100644
--- a/system/libraries/Table.php
+++ b/system/libraries/Table.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.3.1
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* HTML Table Generating Class
diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php
index 7bd7cba04..c923a6220 100644
--- a/system/libraries/Trackback.php
+++ b/system/libraries/Trackback.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Trackback Class
@@ -38,12 +39,45 @@
*/
class CI_Trackback {
- public $time_format = 'local';
+ /**
+ * Character set
+ *
+ * @var string
+ */
public $charset = 'UTF-8';
- public $data = array('url' => '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => '');
+
+ /**
+ * Trackback data
+ *
+ * @var array
+ */
+ public $data = array('url' => '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => '');
+
+ /**
+ * Convert ASCII flag
+ *
+ * Whether to convert high-ASCII and MS Word
+ * characters to HTML entities.
+ *
+ * @var bool
+ */
public $convert_ascii = TRUE;
- public $response = '';
- public $error_msg = array();
+
+ /**
+ * Response
+ *
+ * @var string
+ */
+ public $response = '';
+
+ /**
+ * Error messages list
+ *
+ * @var string[]
+ */
+ public $error_msg = array();
+
+ // --------------------------------------------------------------------
/**
* Constructor
diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php
index a50934f2c..d83bf519b 100644
--- a/system/libraries/Typography.php
+++ b/system/libraries/Typography.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Typography Class
diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php
index 7b99dee0d..842b4aebd 100644
--- a/system/libraries/Unit_test.php
+++ b/system/libraries/Unit_test.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.3.1
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Unit Testing Class
@@ -38,13 +39,52 @@
*/
class CI_Unit_test {
+ /**
+ * Active flag
+ *
+ * @var bool
+ */
public $active = TRUE;
+
+ /**
+ * Test results
+ *
+ * @var array
+ */
public $results = array();
+
+ /**
+ * Strict comparison flag
+ *
+ * Whether to use === or == when comparing
+ *
+ * @var bool
+ */
public $strict = FALSE;
+
+ /**
+ * Template
+ *
+ * @var string
+ */
protected $_template = NULL;
+
+ /**
+ * Template rows
+ *
+ * @var string
+ */
protected $_template_rows = NULL;
+
+ /**
+ * List of visible test items
+ *
+ * @var array
+ */
protected $_test_items_visible = array();
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
@@ -92,9 +132,9 @@ class CI_Unit_test {
* Runs the supplied tests
*
* @param mixed $test
- * @param mixed $expected = TRUE
- * @param string $test_name = 'undefined'
- * @param string $notes = ''
+ * @param mixed $expected
+ * @param string $test_name
+ * @param string $notes
* @return string
*/
public function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '')
@@ -112,13 +152,13 @@ class CI_Unit_test {
}
else
{
- $result = ($this->strict === TRUE) ? ($test === $expected) : ($test === $expected);
+ $result = ($this->strict === TRUE) ? ($test === $expected) : ($test == $expected);
$extype = gettype($expected);
}
$back = $this->_backtrace();
- $report[] = array (
+ $report = array (
'test_name' => $test_name,
'test_datatype' => gettype($test),
'res_datatype' => $extype,
@@ -130,7 +170,7 @@ class CI_Unit_test {
$this->results[] = $report;
- return $this->report($this->result($report));
+ return $this->report($this->result(array($report)));
}
// --------------------------------------------------------------------
@@ -140,7 +180,7 @@ class CI_Unit_test {
*
* Displays a table with the test data
*
- * @param array $result = array()
+ * @param array $result
* @return string
*/
public function report($result = array())
@@ -220,7 +260,7 @@ class CI_Unit_test {
*
* Returns the raw result data
*
- * @param array $results = array()
+ * @param array $results
* @return array
*/
public function result($results = array())
@@ -244,30 +284,11 @@ class CI_Unit_test {
continue;
}
- if (is_array($val))
- {
- foreach ($val as $k => $v)
- {
- if ( ! in_array($k, $this->_test_items_visible))
- {
- continue;
- }
-
- if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v))))
- {
- $v = $line;
- }
- $temp[$CI->lang->line('ut_'.$k)] = $v;
- }
- }
- else
+ if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val))))
{
- if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val))))
- {
- $val = $line;
- }
- $temp[$CI->lang->line('ut_'.$key)] = $val;
+ $val = $line;
}
+ $temp[$CI->lang->line('ut_'.$key)] = $val;
}
$retval[] = $temp;
@@ -375,4 +396,4 @@ function is_false($test)
}
/* End of file Unit_test.php */
-/* Location: ./system/libraries/Unit_test.php */ \ No newline at end of file
+/* Location: ./system/libraries/Unit_test.php */
diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php
index 76bbc244e..b3e9f7515 100644
--- a/system/libraries/Upload.php
+++ b/system/libraries/Upload.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* File Uploading Class
@@ -36,40 +37,210 @@
*/
class CI_Upload {
+ /**
+ * Maximum file size
+ *
+ * @var int
+ */
public $max_size = 0;
+
+ /**
+ * Maximum image width
+ *
+ * @var int
+ */
public $max_width = 0;
+
+ /**
+ * Maximum image height
+ *
+ * @var int
+ */
public $max_height = 0;
+
+ /**
+ * Maximum filename length
+ *
+ * @var int
+ */
public $max_filename = 0;
+
+ /**
+ * Maximum duplicate filename increment ID
+ *
+ * @var int
+ */
public $max_filename_increment = 100;
+
+ /**
+ * Allowed file types
+ *
+ * @var string
+ */
public $allowed_types = '';
+
+ /**
+ * Temporary filename
+ *
+ * @var string
+ */
public $file_temp = '';
+
+ /**
+ * Filename
+ *
+ * @var string
+ */
public $file_name = '';
+
+ /**
+ * Original filename
+ *
+ * @var string
+ */
public $orig_name = '';
+
+ /**
+ * File type
+ *
+ * @var string
+ */
public $file_type = '';
- public $file_size = '';
+
+ /**
+ * File size
+ *
+ * @var int
+ */
+ public $file_size = NULL;
+
+ /**
+ * Filename extension
+ *
+ * @var string
+ */
public $file_ext = '';
+
+ /**
+ * Upload path
+ *
+ * @var string
+ */
public $upload_path = '';
+
+ /**
+ * Overwrite flag
+ *
+ * @var bool
+ */
public $overwrite = FALSE;
+
+ /**
+ * Obfuscate filename flag
+ *
+ * @var bool
+ */
public $encrypt_name = FALSE;
+
+ /**
+ * Is image flag
+ *
+ * @var bool
+ */
public $is_image = FALSE;
- public $image_width = '';
- public $image_height = '';
+
+ /**
+ * Image width
+ *
+ * @var int
+ */
+ public $image_width = NULL;
+
+ /**
+ * Image height
+ *
+ * @var int
+ */
+ public $image_height = NULL;
+
+ /**
+ * Image type
+ *
+ * @var string
+ */
public $image_type = '';
+
+ /**
+ * Image size string
+ *
+ * @var string
+ */
public $image_size_str = '';
+
+ /**
+ * Error messages list
+ *
+ * @var array
+ */
public $error_msg = array();
+
+ /**
+ * MIME types list
+ *
+ * @var array
+ */
public $mimes = array();
+
+ /**
+ * Remove spaces flag
+ *
+ * @var bool
+ */
public $remove_spaces = TRUE;
+
+ /**
+ * MIME detection flag
+ *
+ * @var bool
+ */
public $detect_mime = TRUE;
+
+ /**
+ * XSS filter flag
+ *
+ * @var bool
+ */
public $xss_clean = FALSE;
+
+ /**
+ * Temporary filename prefix
+ *
+ * @var string
+ */
public $temp_prefix = 'temp_file_';
+
+ /**
+ * Filename sent by the client
+ *
+ * @var bool
+ */
public $client_name = '';
+ // --------------------------------------------------------------------
+
+ /**
+ * Filename override
+ *
+ * @var string
+ */
protected $_file_name_override = '';
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
- * @param array
+ * @param array $props
* @return void
*/
public function __construct($props = array())
@@ -89,7 +260,7 @@ class CI_Upload {
/**
* Initialize preferences
*
- * @param array
+ * @param array $config
* @return void
*/
public function initialize($config = array())
@@ -105,14 +276,14 @@ class CI_Upload {
'file_name' => '',
'orig_name' => '',
'file_type' => '',
- 'file_size' => '',
+ 'file_size' => NULL,
'file_ext' => '',
'upload_path' => '',
'overwrite' => FALSE,
'encrypt_name' => FALSE,
'is_image' => FALSE,
- 'image_width' => '',
- 'image_height' => '',
+ 'image_width' => NULL,
+ 'image_height' => NULL,
'image_type' => '',
'image_size_str' => '',
'error_msg' => array(),
@@ -154,7 +325,7 @@ class CI_Upload {
/**
* Perform the file upload
*
- * @param string $field = 'userfile'
+ * @param string $field
* @return bool
*/
public function do_upload($field = 'userfile')
@@ -356,7 +527,7 @@ class CI_Upload {
* Returns an associative array containing all of the information
* related to the upload, allowing the developer easy access in one array.
*
- * @param string
+ * @param string $index
* @return mixed
*/
public function data($index = NULL)
@@ -391,7 +562,7 @@ class CI_Upload {
/**
* Set Upload Path
*
- * @param string
+ * @param string $path
* @return void
*/
public function set_upload_path($path)
@@ -409,8 +580,8 @@ class CI_Upload {
* existence of a file with the same name. If found, it will append a
* number to the end of the filename to avoid overwriting a pre-existing file.
*
- * @param string
- * @param string
+ * @param string $path
+ * @param string $filename
* @return string
*/
public function set_filename($path, $filename)
@@ -454,7 +625,7 @@ class CI_Upload {
/**
* Set Maximum File Size
*
- * @param int
+ * @param int $n
* @return void
*/
public function set_max_filesize($n)
@@ -467,7 +638,7 @@ class CI_Upload {
/**
* Set Maximum File Name Length
*
- * @param int
+ * @param int $n
* @return void
*/
public function set_max_filename($n)
@@ -480,7 +651,7 @@ class CI_Upload {
/**
* Set Maximum Image Width
*
- * @param int
+ * @param int $n
* @return void
*/
public function set_max_width($n)
@@ -493,7 +664,7 @@ class CI_Upload {
/**
* Set Maximum Image Height
*
- * @param int
+ * @param int $n
* @return void
*/
public function set_max_height($n)
@@ -506,7 +677,7 @@ class CI_Upload {
/**
* Set Allowed File Types
*
- * @param string
+ * @param string $types
* @return void
*/
public function set_allowed_types($types)
@@ -526,7 +697,7 @@ class CI_Upload {
*
* Uses GD to determine the width/height/type of image
*
- * @param string
+ * @param string $path
* @return void
*/
public function set_image_properties($path = '')
@@ -558,7 +729,7 @@ class CI_Upload {
* Enables the XSS flag so that the file that was uploaded
* will be run through the XSS filter.
*
- * @param bool
+ * @param bool $flag
* @return void
*/
public function set_xss_clean($flag = FALSE)
@@ -600,7 +771,7 @@ class CI_Upload {
/**
* Verify that the filetype is allowed
*
- * @param bool
+ * @param bool $ignore_mime
* @return bool
*/
public function is_allowed_filetype($ignore_mime = FALSE)
@@ -737,7 +908,7 @@ class CI_Upload {
/**
* Extract the file extension
*
- * @param string
+ * @param string $filename
* @return string
*/
public function get_extension($filename)
@@ -751,7 +922,7 @@ class CI_Upload {
/**
* Clean the file name for security
*
- * @param string
+ * @param string $filename
* @return string
*/
public function clean_file_name($filename)
@@ -885,7 +1056,7 @@ class CI_Upload {
/**
* Set an error message
*
- * @param string
+ * @param string $msg
* @return void
*/
public function set_error($msg)
@@ -915,8 +1086,8 @@ class CI_Upload {
/**
* Display the error message
*
- * @param string
- * @param string
+ * @param string $open
+ * @param string $close
* @return string
*/
public function display_errors($open = '<p>', $close = '</p>')
@@ -932,7 +1103,7 @@ class CI_Upload {
* This is a list of mime types. We use it to validate
* the "allowed types" set by the developer
*
- * @param string
+ * @param string $mime
* @return string
*/
public function mimes_types($mime)
@@ -945,10 +1116,12 @@ class CI_Upload {
/**
* Prep Filename
*
- * Prevents possible script execution from Apache's handling of files multiple extensions
- * http://httpd.apache.org/docs/1.3/mod/mod_mime.html#multipleext
+ * Prevents possible script execution from Apache's handling
+ * of files' multiple extensions.
+ *
+ * @link http://httpd.apache.org/docs/1.3/mod/mod_mime.html#multipleext
*
- * @param string
+ * @param string $filename
* @return string
*/
protected function _prep_filename($filename)
@@ -985,7 +1158,7 @@ class CI_Upload {
* Detects the (actual) MIME type of the uploaded file, if possible.
* The input array is expected to be $_FILES[$field]
*
- * @param array
+ * @param array $file
* @return void
*/
protected function _file_mime_type($file)
@@ -1035,7 +1208,7 @@ class CI_Upload {
? 'file --brief --mime '.escapeshellarg($file['tmp_name']).' 2>&1'
: 'file --brief --mime '.$file['tmp_name'].' 2>&1';
- if (function_exists('exec'))
+ if (function_usable('exec'))
{
/* This might look confusing, as $mime is being populated with all of the output when set in the second parameter.
* However, we only neeed the last line, which is the actual return value of exec(), and as such - it overwrites
@@ -1050,7 +1223,7 @@ class CI_Upload {
}
}
- if ( (bool) @ini_get('safe_mode') === FALSE && function_exists('shell_exec'))
+ if ( (bool) @ini_get('safe_mode') === FALSE && function_usable('shell_exec'))
{
$mime = @shell_exec($cmd);
if (strlen($mime) > 0)
@@ -1064,7 +1237,7 @@ class CI_Upload {
}
}
- if (function_exists('popen'))
+ if (function_usable('popen'))
{
$proc = @popen($cmd, 'r');
if (is_resource($proc))
diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php
index 3387d4aa6..e920578d9 100644
--- a/system/libraries/User_agent.php
+++ b/system/libraries/User_agent.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* User Agent Class
diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php
index 3ed050a2e..3ef823e29 100755
--- a/system/libraries/Xmlrpc.php
+++ b/system/libraries/Xmlrpc.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,14 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+if ( ! function_exists('xml_parser_create'))
+{
+ show_error('Your PHP installation does not support XML');
+}
+
+// ------------------------------------------------------------------------
/**
* XML-RPC request handler class
@@ -34,56 +42,212 @@
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
*/
-
-if ( ! function_exists('xml_parser_create'))
-{
- show_error('Your PHP installation does not support XML');
-}
-
-// ------------------------------------------------------------------------
-
class CI_Xmlrpc {
- public $debug = FALSE; // Debugging on or off
+ /**
+ * Debug flag
+ *
+ * @var bool
+ */
+ public $debug = FALSE;
+
+ /**
+ * I4 data type
+ *
+ * @var string
+ */
public $xmlrpcI4 = 'i4';
+
+ /**
+ * Integer data type
+ *
+ * @var string
+ */
public $xmlrpcInt = 'int';
+
+ /**
+ * Boolean data type
+ *
+ * @var string
+ */
public $xmlrpcBoolean = 'boolean';
+
+ /**
+ * Double data type
+ *
+ * @var string
+ */
public $xmlrpcDouble = 'double';
+
+ /**
+ * String data type
+ *
+ * @var string
+ */
public $xmlrpcString = 'string';
+
+ /**
+ * DateTime format
+ *
+ * @var string
+ */
public $xmlrpcDateTime = 'dateTime.iso8601';
+
+ /**
+ * Base64 data type
+ *
+ * @var string
+ */
public $xmlrpcBase64 = 'base64';
+
+ /**
+ * Array data type
+ *
+ * @var string
+ */
public $xmlrpcArray = 'array';
+
+ /**
+ * Struct data type
+ *
+ * @var string
+ */
public $xmlrpcStruct = 'struct';
+ /**
+ * Data types list
+ *
+ * @var array
+ */
public $xmlrpcTypes = array();
+
+ /**
+ * Valid parents list
+ *
+ * @var array
+ */
public $valid_parents = array();
- public $xmlrpcerr = array(); // Response numbers
- public $xmlrpcstr = array(); // Response strings
+ /**
+ * Response error numbers list
+ *
+ * @var array
+ */
+ public $xmlrpcerr = array();
+
+ /**
+ * Response error messages list
+ *
+ * @var string[]
+ */
+ public $xmlrpcstr = array();
+
+ /**
+ * Encoding charset
+ *
+ * @var string
+ */
public $xmlrpc_defencoding = 'UTF-8';
+
+ /**
+ * XML-RPC client name
+ *
+ * @var string
+ */
public $xmlrpcName = 'XML-RPC for CodeIgniter';
+
+ /**
+ * XML-RPC version
+ *
+ * @var string
+ */
public $xmlrpcVersion = '1.1';
- public $xmlrpcerruser = 800; // Start of user errors
- public $xmlrpcerrxml = 100; // Start of XML Parse errors
- public $xmlrpc_backslash = ''; // formulate backslashes for escaping regexp
+ /**
+ * Start of user errors
+ *
+ * @var int
+ */
+ public $xmlrpcerruser = 800;
+
+ /**
+ * Start of XML parse errors
+ *
+ * @var int
+ */
+ public $xmlrpcerrxml = 100;
+
+ /**
+ * Backslash replacement value
+ *
+ * @var string
+ */
+ public $xmlrpc_backslash = '';
+
+ /**
+ * XML-RPC Client object
+ *
+ * @var object
+ */
public $client;
+
+ /**
+ * XML-RPC Method name
+ *
+ * @var string
+ */
public $method;
+
+ /**
+ * XML-RPC Data
+ *
+ * @var array
+ */
public $data;
+
+ /**
+ * XML-RPC Message
+ *
+ * @var string
+ */
public $message = '';
- public $error = ''; // Error string for request
+
+ /**
+ * Request error message
+ *
+ * @var string
+ */
+ public $error = '';
+
+ /**
+ * XML-RPC result object
+ *
+ * @var object
+ */
public $result;
+
+ /**
+ * XML-RPC Reponse
+ *
+ * @var array
+ */
public $response = array(); // Response from remote server
+ /**
+ * XSS Filter flag
+ *
+ * @var bool
+ */
public $xss_clean = TRUE;
+ // --------------------------------------------------------------------
/**
* Constructor
*
* Initializes property default values
*
- * @param array
+ * @param array $config
* @return void
*/
public function __construct($config = array())
@@ -148,7 +312,7 @@ class CI_Xmlrpc {
/**
* Initialize
*
- * @param array
+ * @param array $config
* @return void
*/
public function initialize($config = array())
@@ -171,9 +335,9 @@ class CI_Xmlrpc {
* Parse server URL
*
* @param string $url
- * @param int $port = 80
- * @param string $proxy = FALSE
- * @param int $proxy_port = 8080
+ * @param int $port
+ * @param string $proxy
+ * @param int $proxy_port
* @return void
*/
public function server($url, $port = 80, $proxy = FALSE, $proxy_port = 8080)
@@ -200,7 +364,7 @@ class CI_Xmlrpc {
/**
* Set Timeout
*
- * @param int seconds
+ * @param int $seconds
* @return void
*/
public function timeout($seconds = 5)
@@ -216,7 +380,7 @@ class CI_Xmlrpc {
/**
* Set Methods
*
- * @param string method name
+ * @param string $function Method name
* @return void
*/
public function method($function)
@@ -229,7 +393,7 @@ class CI_Xmlrpc {
/**
* Take Array of Data and Create Objects
*
- * @param array
+ * @param array $incoming
* @return void
*/
public function request($incoming)
@@ -253,7 +417,7 @@ class CI_Xmlrpc {
/**
* Set Debug
*
- * @param bool
+ * @param bool $flag
* @return void
*/
public function set_debug($flag = TRUE)
@@ -266,7 +430,7 @@ class CI_Xmlrpc {
/**
* Values Parsing
*
- * @param mixed
+ * @param mixed $value
* @return object
*/
public function values_parsing($value)
@@ -349,8 +513,8 @@ class CI_Xmlrpc {
/**
* Sends an Error Message for Server Request
*
- * @param int
- * @param string
+ * @param int $number
+ * @param string $message
* @return object
*/
public function send_error_message($number, $message)
@@ -363,7 +527,7 @@ class CI_Xmlrpc {
/**
* Send Response for Server Request
*
- * @param array
+ * @param array $response
* @return object
*/
public function send_response($response)
@@ -384,24 +548,79 @@ class CI_Xmlrpc {
*/
class XML_RPC_Client extends CI_Xmlrpc
{
+ /**
+ * Path
+ *
+ * @var string
+ */
public $path = '';
+
+ /**
+ * Server hostname
+ *
+ * @var string
+ */
public $server = '';
+
+ /**
+ * Server port
+ *
+ * @var int
+ */
public $port = 80;
+
+ /**
+ * Proxy hostname
+ *
+ * @var string
+ */
public $proxy = FALSE;
+
+ /**
+ * Proxy port
+ *
+ * @var int
+ */
public $proxy_port = 8080;
+
+ /**
+ * Error number
+ *
+ * @var string
+ */
public $errno = '';
+
+ /**
+ * Error message
+ *
+ * @var string
+ */
public $errstring = '';
+
+ /**
+ * Timeout in seconds
+ *
+ * @var int
+ */
public $timeout = 5;
+
+ /**
+ * No Multicall flag
+ *
+ * @var bool
+ */
public $no_multicall = FALSE;
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
* @param string $path
* @param object $server
- * @param int $port = 80
- * @param string $proxy = FALSE
- * @param int $proxy_port = 8080
+ * @param int $port
+ * @param string $proxy
+ * @param int $proxy_port
* @return void
*/
public function __construct($path, $server, $port = 80, $proxy = FALSE, $proxy_port = 8080)
@@ -420,7 +639,7 @@ class XML_RPC_Client extends CI_Xmlrpc
/**
* Send message
*
- * @param mixed
+ * @param mixed $msg
* @return object
*/
public function send($msg)
@@ -439,7 +658,7 @@ class XML_RPC_Client extends CI_Xmlrpc
/**
* Send payload
*
- * @param object
+ * @param object $msg
* @return object
*/
public function sendPayload($msg)
@@ -499,18 +718,50 @@ class XML_RPC_Client extends CI_Xmlrpc
*/
class XML_RPC_Response
{
+
+ /**
+ * Value
+ *
+ * @var mixed
+ */
public $val = 0;
+
+ /**
+ * Error number
+ *
+ * @var int
+ */
public $errno = 0;
+
+ /**
+ * Error message
+ *
+ * @var string
+ */
public $errstr = '';
+
+ /**
+ * Headers list
+ *
+ * @var array
+ */
public $headers = array();
+
+ /**
+ * XSS Filter flag
+ *
+ * @var bool
+ */
public $xss_clean = TRUE;
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
- * @param mixed
- * @param int
- * @param string
+ * @param mixed $val
+ * @param int $code
+ * @param string $fstr
* @return void
*/
public function __construct($val, $code = 0, $fstr = '')
@@ -716,16 +967,42 @@ class XML_RPC_Response
*/
class XML_RPC_Message extends CI_Xmlrpc
{
+
+ /**
+ * Payload
+ *
+ * @var string
+ */
public $payload;
+
+ /**
+ * Method name
+ *
+ * @var string
+ */
public $method_name;
+
+ /**
+ * Parameter list
+ *
+ * @var array
+ */
public $params = array();
+
+ /**
+ * XH?
+ *
+ * @var array
+ */
public $xh = array();
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
- * @param string method name
- * @param array
+ * @param string $method
+ * @param array $pars
* @return void
*/
public function __construct($method, $pars = FALSE)
@@ -1303,14 +1580,27 @@ class XML_RPC_Message extends CI_Xmlrpc
*/
class XML_RPC_Values extends CI_Xmlrpc
{
+ /**
+ * Value data
+ *
+ * @var array
+ */
public $me = array();
+
+ /**
+ * Value type
+ *
+ * @var int
+ */
public $mytype = 0;
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
- * @param mixed
- * @param string
+ * @param mixed $val
+ * @param string $type
* @return void
*/
public function __construct($val = -1, $type = '')
diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php
index 5d01d374d..3c3337bf2 100644
--- a/system/libraries/Xmlrpcs.php
+++ b/system/libraries/Xmlrpcs.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
if ( ! function_exists('xml_parser_create'))
{
diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php
index 5c4c257f8..9ecd0de9f 100644
--- a/system/libraries/Zip.php
+++ b/system/libraries/Zip.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Zip Compression Class
diff --git a/system/libraries/javascript/Jquery.php b/system/libraries/javascript/Jquery.php
index ed02fadb7..2bf47957f 100644
--- a/system/libraries/javascript/Jquery.php
+++ b/system/libraries/javascript/Jquery.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Jquery Class
@@ -36,14 +37,57 @@
*/
class CI_Jquery extends CI_Javascript {
+ /**
+ * JavaScript directory location
+ *
+ * @var string
+ */
protected $_javascript_folder = 'js';
+
+ /**
+ * JQuery code for load
+ *
+ * @var array
+ */
public $jquery_code_for_load = array();
+
+ /**
+ * JQuery code for compile
+ *
+ * @var array
+ */
public $jquery_code_for_compile = array();
+
+ /**
+ * JQuery corner active flag
+ *
+ * @var bool
+ */
public $jquery_corner_active = FALSE;
+
+ /**
+ * JQuery table sorter active flag
+ *
+ * @var bool
+ */
public $jquery_table_sorter_active = FALSE;
+
+ /**
+ * JQuery table sorder pager active
+ *
+ * @var bool
+ */
public $jquery_table_sorter_pager_active = FALSE;
+
+ /**
+ * JQuery AJAX image
+ *
+ * @var string
+ */
public $jquery_ajax_img = '';
+ // --------------------------------------------------------------------
+
/**
* Constructor
*
@@ -382,8 +426,8 @@ class CI_Jquery extends CI_Javascript {
*
* Outputs a jQuery addClass event
*
- * @param string $element = 'this'
- * @param string $class = ''
+ * @param string $element
+ * @param string $class
* @return string
*/
protected function _addClass($element = 'this', $class = '')
@@ -399,10 +443,10 @@ class CI_Jquery extends CI_Javascript {
*
* Outputs a jQuery animate event
*
- * @param string $element = 'this'
- * @param array $params = array()
- * @param string $speed = '' 'slow', 'normal', 'fast', or time in milliseconds
- * @param string $extra = ''
+ * @param string $element
+ * @param array $params
+ * @param string $speed 'slow', 'normal', 'fast', or time in milliseconds
+ * @param string $extra
* @return string
*/
protected function _animate($element = 'this', $params = array(), $speed = '', $extra = '')
@@ -514,8 +558,8 @@ class CI_Jquery extends CI_Javascript {
*
* Outputs a jQuery remove class event
*
- * @param string $element = 'this'
- * @param string $class = ''
+ * @param string $element
+ * @param string $class
* @return string
*/
protected function _removeClass($element = 'this', $class = '')
@@ -622,8 +666,8 @@ class CI_Jquery extends CI_Javascript {
*
* Outputs a jQuery toggle class event
*
- * @param string $element = 'this'
- * @param string $class = ''
+ * @param string $element
+ * @param string $class
* @return string
*/
protected function _toggleClass($element = 'this', $class = '')
@@ -707,9 +751,9 @@ class CI_Jquery extends CI_Javascript {
/**
* Zebra tables
*
- * @param string $class = ''
- * @param string $odd = 'odd'
- * @param string $hover = ''
+ * @param string $class
+ * @param string $odd
+ * @param string $hover
* @return string
*/
protected function _zebraTables($class = '', $odd = 'odd', $hover = '')
@@ -734,10 +778,9 @@ class CI_Jquery extends CI_Javascript {
/**
* Corner Plugin
*
- * http://www.malsup.com/jquery/corner/
- *
- * @param string $element = ''
- * @param string $corner_style = ''
+ * @link http://www.malsup.com/jquery/corner/
+ * @param string $element
+ * @param string $corner_style
* @return string
*/
public function corner($element = '', $corner_style = '')
@@ -761,7 +804,7 @@ class CI_Jquery extends CI_Javascript {
* Load a thickbox modal window
*
* @param string $src
- * @param bool $relative = FALSE
+ * @param bool $relative
* @return void
*/
public function modal($src, $relative = FALSE)
@@ -777,7 +820,7 @@ class CI_Jquery extends CI_Javascript {
* Load an Effect library
*
* @param string $src
- * @param bool $relative = FALSE
+ * @param bool $relative
* @return void
*/
public function effect($src, $relative = FALSE)
@@ -793,7 +836,7 @@ class CI_Jquery extends CI_Javascript {
* Load a plugin library
*
* @param string $src
- * @param bool $relative = FALSE
+ * @param bool $relative
* @return void
*/
public function plugin($src, $relative = FALSE)
@@ -809,7 +852,7 @@ class CI_Jquery extends CI_Javascript {
* Load a user interface library
*
* @param string $src
- * @param bool $relative = FALSE
+ * @param bool $relative
* @return void
*/
public function ui($src, $relative = FALSE)
@@ -825,7 +868,7 @@ class CI_Jquery extends CI_Javascript {
* Creates a jQuery sortable
*
* @param string $element
- * @param array $options = array()
+ * @param array $options
* @return string
*/
public function sortable($element, $options = array())
@@ -896,8 +939,8 @@ class CI_Jquery extends CI_Javascript {
* As events are specified, they are stored in an array
* This funciton compiles them all for output on a page
*
- * @param string $view_var = 'script_foot'
- * @param bool $script_tags = TRUE
+ * @param string $view_var
+ * @param bool $script_tags
* @return void
*/
protected function _compile($view_var = 'script_foot', $script_tags = TRUE)
@@ -963,8 +1006,8 @@ class CI_Jquery extends CI_Javascript {
*
* Outputs the script tag that loads the jquery.js file into an HTML document
*
- * @param string $library_src = ''
- * @param bool $relative = FALSE
+ * @param string $library_src
+ * @param bool $relative
* @return string
*/
public function script($library_src = '', $relative = FALSE)