From dc6fba5492a215b40c254ed6f704c580427cdfea Mon Sep 17 00:00:00 2001 From: GDmac Date: Wed, 31 Oct 2012 16:53:15 +0100 Subject: Fix #1946 dbforge add_key add_key not setting multiple-column keys when given array Signed-off-by: GDmac --- system/database/DB_forge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 119d78d38..2be2790dd 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -132,7 +132,7 @@ abstract class CI_DB_forge { */ public function add_key($key = '', $primary = FALSE) { - if (is_array($key)) + if ($primary && is_array($key)) { foreach ($key as $one) { -- cgit v1.2.3-24-g4f1b From 87f4dc27230debc0af281c9780f2ba939fe07608 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 01:11:22 +0200 Subject: Fix an update_string() bug --- system/database/DB_driver.php | 30 +++--------------------------- system/database/DB_query_builder.php | 2 +- 2 files changed, 4 insertions(+), 28 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index e8286aaa1..795ed6711 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1080,43 +1080,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); } diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index a3585586e..cc43d834c 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -1575,7 +1575,7 @@ 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); - +var_dump($sql); $this->_reset_write(); return $this->query($sql); } -- cgit v1.2.3-24-g4f1b From b107e5728ad867e860d2d4469c1ec523bd3ffac1 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 11:50:21 +0200 Subject: Remove var_dump() missed in a previous commit --- system/database/DB_query_builder.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index cc43d834c..8a3d3b198 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -1575,7 +1575,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); -var_dump($sql); $this->_reset_write(); return $this->query($sql); } -- cgit v1.2.3-24-g4f1b From c5536aac5752054f7f76e448d58b86407d8f574e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 17:33:58 +0200 Subject: Manually apply PR #1594 (fixing phpdoc page-level generation/warnings) Also partially fixes issue #1295, fixes inconsistencies in some page-level docblocks and adds include checks in language files. --- system/database/DB.php | 3 ++- system/database/DB_cache.php | 3 ++- system/database/DB_driver.php | 3 ++- system/database/DB_forge.php | 3 ++- system/database/DB_query_builder.php | 3 ++- system/database/DB_result.php | 3 ++- system/database/DB_utility.php | 3 ++- system/database/drivers/cubrid/cubrid_driver.php | 3 ++- system/database/drivers/cubrid/cubrid_forge.php | 3 ++- system/database/drivers/cubrid/cubrid_result.php | 3 ++- system/database/drivers/cubrid/cubrid_utility.php | 3 ++- system/database/drivers/ibase/ibase_driver.php | 3 ++- system/database/drivers/ibase/ibase_forge.php | 3 ++- system/database/drivers/ibase/ibase_result.php | 3 ++- system/database/drivers/ibase/ibase_utility.php | 3 ++- system/database/drivers/mssql/mssql_driver.php | 3 ++- system/database/drivers/mssql/mssql_forge.php | 3 ++- system/database/drivers/mssql/mssql_result.php | 3 ++- system/database/drivers/mssql/mssql_utility.php | 3 ++- system/database/drivers/mysql/mysql_driver.php | 3 ++- system/database/drivers/mysql/mysql_forge.php | 3 ++- system/database/drivers/mysql/mysql_result.php | 3 ++- system/database/drivers/mysql/mysql_utility.php | 3 ++- system/database/drivers/mysqli/mysqli_driver.php | 3 ++- system/database/drivers/mysqli/mysqli_forge.php | 3 ++- system/database/drivers/mysqli/mysqli_result.php | 3 ++- system/database/drivers/mysqli/mysqli_utility.php | 3 ++- system/database/drivers/oci8/oci8_driver.php | 3 ++- system/database/drivers/oci8/oci8_forge.php | 3 ++- system/database/drivers/oci8/oci8_result.php | 3 ++- system/database/drivers/oci8/oci8_utility.php | 3 ++- system/database/drivers/odbc/odbc_driver.php | 3 ++- system/database/drivers/odbc/odbc_forge.php | 3 ++- system/database/drivers/odbc/odbc_result.php | 3 ++- system/database/drivers/odbc/odbc_utility.php | 3 ++- system/database/drivers/pdo/pdo_driver.php | 3 ++- system/database/drivers/pdo/pdo_forge.php | 3 ++- system/database/drivers/pdo/pdo_result.php | 3 ++- system/database/drivers/pdo/pdo_utility.php | 3 ++- system/database/drivers/pdo/subdrivers/pdo_4d_driver.php | 3 ++- system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php | 3 ++- system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php | 3 ++- system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php | 3 ++- system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php | 3 ++- system/database/drivers/pdo/subdrivers/pdo_informix_driver.php | 3 ++- system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php | 3 ++- system/database/drivers/pdo/subdrivers/pdo_oci_driver.php | 3 ++- system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php | 3 ++- system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php | 3 ++- system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php | 3 ++- system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php | 3 ++- system/database/drivers/postgre/postgre_driver.php | 3 ++- system/database/drivers/postgre/postgre_forge.php | 3 ++- system/database/drivers/postgre/postgre_result.php | 3 ++- system/database/drivers/postgre/postgre_utility.php | 3 ++- system/database/drivers/sqlite/sqlite_driver.php | 3 ++- system/database/drivers/sqlite/sqlite_forge.php | 3 ++- system/database/drivers/sqlite/sqlite_result.php | 3 ++- system/database/drivers/sqlite/sqlite_utility.php | 3 ++- system/database/drivers/sqlite3/sqlite3_driver.php | 3 ++- system/database/drivers/sqlite3/sqlite3_forge.php | 3 ++- system/database/drivers/sqlite3/sqlite3_result.php | 3 ++- system/database/drivers/sqlite3/sqlite3_utility.php | 3 ++- system/database/drivers/sqlsrv/sqlsrv_driver.php | 3 ++- system/database/drivers/sqlsrv/sqlsrv_forge.php | 3 ++- system/database/drivers/sqlsrv/sqlsrv_result.php | 3 ++- system/database/drivers/sqlsrv/sqlsrv_utility.php | 3 ++- 67 files changed, 134 insertions(+), 67 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index d751325ce..676cb9ccd 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -1,4 +1,4 @@ - Date: Fri, 2 Nov 2012 01:42:31 +0200 Subject: DocBlocks for base DB classes Partially fixes issue #1295. --- system/database/DB.php | 17 +- system/database/DB_cache.php | 26 +- system/database/DB_driver.php | 263 +++++++++++++++++++- system/database/DB_forge.php | 51 +++- system/database/DB_query_builder.php | 460 ++++++++++++++++++++++++----------- system/database/DB_result.php | 200 +++++++++++++-- system/database/DB_utility.php | 44 ++-- 7 files changed, 864 insertions(+), 197 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 676cb9ccd..79e5c7ad2 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -32,8 +32,10 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @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) { @@ -149,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 37d2dd0b5..b8f8995fa 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -35,8 +35,24 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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 @@ -59,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 = '') @@ -95,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 @@ -154,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 = '') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 515e9cbb1..497f8b9c9 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -41,60 +41,300 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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('*'); + + /** + * 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. + * 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) @@ -1175,8 +1415,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 50b55d60e..d2d99ccea 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -35,17 +35,66 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ abstract class CI_DB_forge { + /** + * 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'; + + /** + * DROP TABLE statement + * + * @var string + */ protected $_drop_table = 'DROP TABLE IF EXISTS %s'; + + /** + * RENAME TABLE statement + * + * @var string + */ protected $_rename_table = 'ALTER TABLE %s RENAME TO %s'; + // -------------------------------------------------------------------- + /** * Constructor * diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 75cad95de..41b30aec3 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -40,42 +40,213 @@ defined('BASEPATH') OR exit('No direct script access allowed'); 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 * @@ -183,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') @@ -234,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) @@ -255,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) @@ -271,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) @@ -318,7 +488,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Join + * JOIN * * Generates the JOIN portion of the query * @@ -406,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 @@ -424,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 @@ -444,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) @@ -505,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) @@ -523,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) @@ -541,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) @@ -559,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) @@ -577,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) @@ -629,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) @@ -648,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) @@ -667,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) @@ -686,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) @@ -705,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) @@ -771,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 ') @@ -860,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) @@ -881,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) @@ -919,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) @@ -936,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) @@ -953,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) @@ -1009,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) @@ -1028,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) @@ -1040,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) @@ -1184,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) @@ -1219,9 +1401,9 @@ 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 + * @return int Number of rows inserted or FALSE on failure */ public function insert_batch($table = '', $set = NULL) { @@ -1540,14 +1722,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) @@ -1980,7 +2162,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 +2235,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 +2473,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 +2579,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 704fd7cc2..9d19075ba 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -39,19 +39,68 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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) @@ -90,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') @@ -114,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) { @@ -250,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') @@ -340,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) @@ -364,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) @@ -388,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') @@ -402,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') @@ -416,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') @@ -440,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') @@ -463,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') @@ -483,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 @@ -491,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 12680be5f..3bd77c84b 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -35,13 +35,31 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ abstract class CI_DB_utility extends CI_DB_forge { + /** + * Database object + * + * @var object + */ public $db; - // Platform specific SQL strings - // Just setting those defaults to FALSE as they are mostly MySQL-specific + // -------------------------------------------------------------------- + + /** + * OPTIMIZE TABLE statement + * + * @var string|bool + */ protected $_optimize_table = FALSE; + + /** + * REPAIR TABLE statement + * + * @var string|bool + */ protected $_repair_table = FALSE; + // -------------------------------------------------------------------- + /** * Constructor * @@ -95,7 +113,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) @@ -108,7 +126,7 @@ 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) @@ -169,7 +187,7 @@ 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) @@ -194,10 +212,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 = '"') @@ -234,8 +252,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()) @@ -281,7 +299,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()) @@ -294,8 +312,6 @@ abstract class CI_DB_utility extends CI_DB_forge { $params = array('tables' => $params); } - // ------------------------------------------------------ - // Set up our default preferences $prefs = array( 'tables' => array(), -- cgit v1.2.3-24-g4f1b From c98e93aab3997bfea4fbb9d07f7b2550a84f8f7a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Nov 2012 02:04:59 +0200 Subject: [ci skip] DocBlocks for DB drivers' utility classes Partially fixes issue #1295. --- system/database/DB_utility.php | 13 +++++++++--- system/database/drivers/cubrid/cubrid_forge.php | 15 +++++++++++++- system/database/drivers/ibase/ibase_forge.php | 9 ++++++++- system/database/drivers/ibase/ibase_utility.php | 4 +--- system/database/drivers/mssql/mssql_forge.php | 7 +++++++ system/database/drivers/mssql/mssql_utility.php | 15 ++++++++++++-- system/database/drivers/mysql/mysql_forge.php | 9 ++++++++- system/database/drivers/mysql/mysql_utility.php | 23 ++++++++++++++++++++-- system/database/drivers/mysqli/mysqli_forge.php | 9 ++++++++- system/database/drivers/mysqli/mysqli_utility.php | 23 ++++++++++++++++++++-- system/database/drivers/oci8/oci8_forge.php | 19 ++++++++++++++++++ system/database/drivers/oci8/oci8_utility.php | 9 +++++++-- system/database/drivers/odbc/odbc_forge.php | 7 +++++++ system/database/drivers/odbc/odbc_utility.php | 6 ++---- system/database/drivers/pdo/pdo_forge.php | 7 +++++++ system/database/drivers/pdo/pdo_utility.php | 6 ++---- system/database/drivers/postgre/postgre_forge.php | 11 +++++++++-- .../database/drivers/postgre/postgre_utility.php | 17 ++++++++++++++-- system/database/drivers/sqlite/sqlite_utility.php | 6 ++---- .../database/drivers/sqlite3/sqlite3_utility.php | 6 ++---- system/database/drivers/sqlsrv/sqlsrv_forge.php | 7 +++++++ system/database/drivers/sqlsrv/sqlsrv_utility.php | 17 ++++++++++++++-- 22 files changed, 205 insertions(+), 40 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 3bd77c84b..31102c0c6 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -44,24 +44,31 @@ abstract class CI_DB_utility extends CI_DB_forge { // -------------------------------------------------------------------- + /** + * List databases statement + * + * @var string + */ + $_list_databases = FALSE; + /** * OPTIMIZE TABLE statement * - * @var string|bool + * @var string */ protected $_optimize_table = FALSE; /** * REPAIR TABLE statement * - * @var string|bool + * @var string */ protected $_repair_table = FALSE; // -------------------------------------------------------------------- /** - * Constructor + * Class constructor * * @return void */ diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php index a7b4efd9a..33d502137 100644 --- a/system/database/drivers/cubrid/cubrid_forge.php +++ b/system/database/drivers/cubrid/cubrid_forge.php @@ -35,13 +35,26 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class CI_DB_cubrid_forge extends CI_DB_forge { + /** + * CREATE DATABASE statement + * + * @var string + */ protected $_create_database = FALSE; + + // -------------------------------------------------------------------- + + /** + * DROP DATABASE statement + * + * @var string + */ protected $_drop_database = FALSE; /** * Process Fields * - * @param mixed the fields + * @param mixed $fields * @return string */ protected function _process_fields($fields) diff --git a/system/database/drivers/ibase/ibase_forge.php b/system/database/drivers/ibase/ibase_forge.php index 7f3693dbd..7c4d00a23 100644 --- a/system/database/drivers/ibase/ibase_forge.php +++ b/system/database/drivers/ibase/ibase_forge.php @@ -35,12 +35,19 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class CI_DB_ibase_forge extends CI_DB_forge { + /** + * DROP TABLE statement + * + * @var string + */ protected $_drop_table = 'DROP TABLE %s'; + // -------------------------------------------------------------------- + /** * Create database * - * @param string the database name + * @param string $db_name * @return string */ public function create_database($db_name) diff --git a/system/database/drivers/ibase/ibase_utility.php b/system/database/drivers/ibase/ibase_utility.php index 06de677b6..5eb209ae1 100644 --- a/system/database/drivers/ibase/ibase_utility.php +++ b/system/database/drivers/ibase/ibase_utility.php @@ -35,10 +35,8 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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_forge.php b/system/database/drivers/mssql/mssql_forge.php index e0b26d81e..1eef648b0 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -35,8 +35,15 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class CI_DB_mssql_forge extends CI_DB_forge { + /** + * DROP TABLE statement + * + * @var string + */ protected $_drop_table = 'DROP TABLE %s'; + // -------------------------------------------------------------------- + /** * Create Table * diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 90cc23b05..a011d5974 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -35,13 +35,24 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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()) diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 05db86253..7ce4e8b00 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -35,12 +35,19 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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 * - * @param mixed the fields + * @param mixed $fields * @return string */ protected function _process_fields($fields) diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index bc20d2556..8aa051755 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -35,14 +35,33 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index b3c9e8e23..0732dfea5 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -35,12 +35,19 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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 * - * @param mixed the fields + * @param mixed $fields * @return string */ protected function _process_fields($fields) diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 41a9186ce..345691e84 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -35,14 +35,33 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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_forge.php b/system/database/drivers/oci8/oci8_forge.php index fed8141b1..ad578f830 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -35,10 +35,29 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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; + + /** + * DROP TABLE statement + * + * @var string + */ protected $_drop_table = 'DROP TABLE %s'; + // -------------------------------------------------------------------- + /** * Create Table * diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 0c6cfc698..e5aae8132 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -35,12 +35,17 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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()) diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index fb85c2a74..699ce996c 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -35,8 +35,15 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class CI_DB_odbc_forge extends CI_DB_forge { + /** + * DROP TABLE statement + * + * @var string + */ protected $_drop_table = 'DROP TABLE %s'; + // -------------------------------------------------------------------- + /** * Create Table * diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 715bfc949..bfa94f469 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -35,12 +35,10 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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()) diff --git a/system/database/drivers/pdo/pdo_forge.php b/system/database/drivers/pdo/pdo_forge.php index 8c22eb33f..e77970cf2 100644 --- a/system/database/drivers/pdo/pdo_forge.php +++ b/system/database/drivers/pdo/pdo_forge.php @@ -35,8 +35,15 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class CI_DB_pdo_forge extends CI_DB_forge { + /** + * DROP TABLE statement + * + * @var string + */ protected $_drop_table = 'DROP TABLE %s'; + // -------------------------------------------------------------------- + /** * Create Table * diff --git a/system/database/drivers/pdo/pdo_utility.php b/system/database/drivers/pdo/pdo_utility.php index ed4d685a1..03b309249 100644 --- a/system/database/drivers/pdo/pdo_utility.php +++ b/system/database/drivers/pdo/pdo_utility.php @@ -35,12 +35,10 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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()) diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index aac82c1e5..b08fa5177 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -35,13 +35,20 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class CI_DB_postgre_forge extends CI_DB_forge { + /** + * DROP TABLE statement + * + * @var string + */ protected $_drop_table = 'DROP TABLE IF EXISTS %s CASCADE'; + // -------------------------------------------------------------------- + /** * Process Fields * * @param mixed $fields - * @param array $primary_keys = array() + * @param array $primary_keys * @return string */ protected function _process_fields($fields, $primary_keys = array()) @@ -195,7 +202,7 @@ class CI_DB_postgre_forge extends CI_DB_forge { * @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 = '' + * @param string $after_field * @return string */ protected function _alter_table($alter_type, $table, $fields, $after_field = '') diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 96cd90e92..bae1c6704 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -35,13 +35,26 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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()) diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 15ebc0392..2fd5c85f6 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -35,12 +35,10 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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()) diff --git a/system/database/drivers/sqlite3/sqlite3_utility.php b/system/database/drivers/sqlite3/sqlite3_utility.php index 043c349af..6f276ebcc 100644 --- a/system/database/drivers/sqlite3/sqlite3_utility.php +++ b/system/database/drivers/sqlite3/sqlite3_utility.php @@ -35,12 +35,10 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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()) diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php index 1e5ef4bfd..8155565c0 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_forge.php +++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php @@ -35,8 +35,15 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class CI_DB_sqlsrv_forge extends CI_DB_forge { + /** + * DROP TABLE statement + * + * @var string + */ protected $_drop_table = 'DROP TABLE %s'; + // -------------------------------------------------------------------- + /** * Create Table * diff --git a/system/database/drivers/sqlsrv/sqlsrv_utility.php b/system/database/drivers/sqlsrv/sqlsrv_utility.php index 5f7d0bdbb..315090049 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_utility.php +++ b/system/database/drivers/sqlsrv/sqlsrv_utility.php @@ -35,13 +35,26 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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()) -- cgit v1.2.3-24-g4f1b From 8463b919e17d9bd7fa35821d547c4acc229520f7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Nov 2012 02:16:28 +0200 Subject: [ci skip] DocBlocks for DB drivers' result classes Partially fixes issue #1295. --- system/database/drivers/cubrid/cubrid_result.php | 6 ++-- system/database/drivers/ibase/ibase_result.php | 2 +- system/database/drivers/mssql/mssql_result.php | 6 ++-- system/database/drivers/mysql/mysql_result.php | 10 +++---- system/database/drivers/mysqli/mysqli_result.php | 6 ++-- system/database/drivers/oci8/oci8_result.php | 34 +++++++++++++++++++--- system/database/drivers/odbc/odbc_result.php | 14 ++++----- system/database/drivers/pdo/pdo_result.php | 2 +- system/database/drivers/postgre/postgre_result.php | 6 ++-- system/database/drivers/sqlite/sqlite_result.php | 6 ++-- system/database/drivers/sqlite3/sqlite3_result.php | 13 +++------ system/database/drivers/sqlsrv/sqlsrv_result.php | 2 +- 12 files changed, 64 insertions(+), 43 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/cubrid/cubrid_result.php b/system/database/drivers/cubrid/cubrid_result.php index 4b51b355a..30aed38d9 100644 --- a/system/database/drivers/cubrid/cubrid_result.php +++ b/system/database/drivers/cubrid/cubrid_result.php @@ -131,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) @@ -162,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/ibase/ibase_result.php b/system/database/drivers/ibase/ibase_result.php index 6ee0a7d59..bbad9d895 100644 --- a/system/database/drivers/ibase/ibase_result.php +++ b/system/database/drivers/ibase/ibase_result.php @@ -129,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/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index 11849f005..c74c70abf 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -132,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) @@ -163,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/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 67ee06e1e..4bfa0ae35 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -39,9 +39,9 @@ defined('BASEPATH') OR exit('No direct script access allowed'); 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) @@ -145,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) @@ -178,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/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 87c056a11..15e15cd5f 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -131,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) @@ -162,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/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 90c8523a3..7d5bf5172 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -38,15 +38,40 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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) @@ -168,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') @@ -212,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/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 279513a57..2c50c255b 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -166,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') @@ -199,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)) @@ -232,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/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php index 1b29d29b7..1de5a47ec 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -206,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/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 78a8a9c68..3f73f84c7 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -130,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) @@ -161,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/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index e5bfa55ad..0e6335f73 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -114,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) @@ -145,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/sqlite3/sqlite3_result.php b/system/database/drivers/sqlite3/sqlite3_result.php index 437adf28e..153e3480a 100644 --- a/system/database/drivers/sqlite3/sqlite3_result.php +++ b/system/database/drivers/sqlite3/sqlite3_result.php @@ -38,9 +38,6 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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 * @@ -48,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(); } // -------------------------------------------------------------------- @@ -135,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') @@ -166,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/sqlsrv/sqlsrv_result.php b/system/database/drivers/sqlsrv/sqlsrv_result.php index fc66d9d8a..6d24cc995 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_result.php +++ b/system/database/drivers/sqlsrv/sqlsrv_result.php @@ -146,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') -- cgit v1.2.3-24-g4f1b From a24e52e1c0136db0c1949e73255b4e9bf114b437 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Nov 2012 03:54:12 +0200 Subject: [ci skip] DocBlocks for DB drivers' driver classes Partially fixes issue #1295. --- system/database/DB_driver.php | 14 +++ system/database/DB_utility.php | 2 +- system/database/drivers/cubrid/cubrid_driver.php | 49 ++++++---- system/database/drivers/ibase/ibase_driver.php | 59 ++++++----- system/database/drivers/mssql/mssql_driver.php | 58 +++++++---- system/database/drivers/mysql/mysql_driver.php | 63 ++++++++---- system/database/drivers/mysqli/mysqli_driver.php | 61 ++++++++---- system/database/drivers/oci8/oci8_driver.php | 108 ++++++++++++++------- system/database/drivers/odbc/odbc_driver.php | 56 +++++++---- system/database/drivers/pdo/pdo_driver.php | 55 ++++++----- .../drivers/pdo/subdrivers/pdo_4d_driver.php | 33 ++++--- .../drivers/pdo/subdrivers/pdo_cubrid_driver.php | 32 +++--- .../drivers/pdo/subdrivers/pdo_dblib_driver.php | 44 ++++++--- .../drivers/pdo/subdrivers/pdo_firebird_driver.php | 41 +++++--- .../drivers/pdo/subdrivers/pdo_ibm_driver.php | 37 +++---- .../drivers/pdo/subdrivers/pdo_informix_driver.php | 31 +++--- .../drivers/pdo/subdrivers/pdo_mysql_driver.php | 44 ++++++--- .../drivers/pdo/subdrivers/pdo_oci_driver.php | 57 ++++++++--- .../drivers/pdo/subdrivers/pdo_odbc_driver.php | 51 ++++++---- .../drivers/pdo/subdrivers/pdo_pgsql_driver.php | 46 ++++++--- .../drivers/pdo/subdrivers/pdo_sqlite_driver.php | 37 ++++--- .../drivers/pdo/subdrivers/pdo_sqlsrv_driver.php | 44 ++++++--- system/database/drivers/postgre/postgre_driver.php | 56 ++++++----- system/database/drivers/sqlite/sqlite_driver.php | 39 +++++--- system/database/drivers/sqlite3/sqlite3_driver.php | 37 ++++--- system/database/drivers/sqlsrv/sqlsrv_driver.php | 58 +++++++---- 26 files changed, 801 insertions(+), 411 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 497f8b9c9..39db16150 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -305,6 +305,13 @@ abstract class CI_DB_driver { */ protected $_reserved_identifiers = array('*'); + /** + * Identifier escape character + * + * @var string + */ + protected $_escape_char = '"'; + /** * ESCAPE statement string * @@ -319,6 +326,13 @@ abstract class CI_DB_driver { */ protected $_like_escape_chr = '!'; + /** + * ORDER BY random keyword + * + * @var string + */ + protected $_random_keyword = ' RAND()'; + /** * COUNT string * diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 31102c0c6..f7bef6a2c 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -49,7 +49,7 @@ abstract class CI_DB_utility extends CI_DB_forge { * * @var string */ - $_list_databases = FALSE; + protected $_list_databases = FALSE; /** * OPTIMIZE TABLE statement diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index e8201822d..48b904286 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -41,18 +41,33 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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 @@ -114,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) @@ -174,7 +189,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) @@ -187,7 +202,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) @@ -266,8 +281,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) @@ -333,7 +348,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) @@ -355,7 +370,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 = '') @@ -370,7 +385,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) @@ -400,9 +415,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/ibase/ibase_driver.php b/system/database/drivers/ibase/ibase_driver.php index 3b5d8f4c6..fc1c28f31 100644 --- a/system/database/drivers/ibase/ibase_driver.php +++ b/system/database/drivers/ibase/ibase_driver.php @@ -41,15 +41,30 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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 @@ -104,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) @@ -117,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) @@ -133,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; } @@ -153,7 +168,7 @@ class CI_DB_ibase_driver extends CI_DB { return TRUE; } - return @ibase_commit($this->trans); + return @ibase_commit($this->_ibase_trans); } // -------------------------------------------------------------------- @@ -171,7 +186,7 @@ class CI_DB_ibase_driver extends CI_DB { return TRUE; } - return @ibase_rollback($this->trans); + return @ibase_rollback($this->_ibase_trans); } // -------------------------------------------------------------------- @@ -179,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) @@ -240,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) @@ -263,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 = '') @@ -278,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) @@ -311,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) @@ -328,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) @@ -346,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) @@ -358,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/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index bd83c5459..c74f9683b 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -41,18 +41,36 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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. * @@ -74,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) @@ -114,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 = '') @@ -140,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) @@ -153,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) @@ -213,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) @@ -296,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) @@ -321,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 = '') @@ -336,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) @@ -368,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) @@ -386,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) @@ -404,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) @@ -420,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) diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index f0fc4ab3e..2457e558c 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -41,25 +41,46 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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; + // -------------------------------------------------------------------- + + /** + * Identifier escape character + * + * @var string + */ + protected $_escape_char = '`'; + + // -------------------------------------------------------------------- + /** - * Constructor + * Class constructor * - * @param array + * @param array $params * @return void */ public function __construct($params) @@ -77,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) @@ -129,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 = '') @@ -153,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) @@ -180,7 +201,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) @@ -195,7 +216,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) @@ -215,7 +236,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) @@ -281,8 +302,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) @@ -341,7 +362,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) @@ -363,7 +384,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 = '') @@ -376,7 +397,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 = '') @@ -427,9 +448,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/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 2e61a235d..7d2507b40 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -41,25 +41,46 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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; + // -------------------------------------------------------------------- + + /** + * Identifier escape character + * + * @var string + */ + protected $_escape_char = '`'; + + // -------------------------------------------------------------------- + /** - * Non-persistent database connection + * Database connection * - * @param bool + * @param bool $persistent * @return object * @todo SSL support */ @@ -111,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 = '') @@ -135,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) @@ -162,7 +183,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) @@ -177,7 +198,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) @@ -197,7 +218,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) @@ -263,8 +284,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) @@ -323,7 +344,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) @@ -345,7 +366,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 = '') @@ -358,7 +379,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 = '') @@ -417,9 +438,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/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index b1fd86a8e..38d2395b6 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -50,34 +50,76 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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 @@ -208,7 +250,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) @@ -227,7 +269,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) @@ -307,7 +349,7 @@ class CI_DB_oci8_driver extends CI_DB { /** * Bind parameters * - * @param array + * @param array $params * @return void */ protected function _bind_params($params) @@ -336,7 +378,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) @@ -409,8 +451,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) @@ -470,7 +512,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) @@ -493,7 +535,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 = '') @@ -508,7 +550,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) @@ -554,9 +596,9 @@ class CI_DB_oci8_driver extends CI_DB { * * 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) @@ -579,10 +621,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) @@ -597,7 +639,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) @@ -614,11 +656,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/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 2e890c46b..88df615e6 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -41,24 +41,42 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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 @@ -105,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) @@ -118,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) @@ -182,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) @@ -242,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) @@ -265,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 = '') @@ -280,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) @@ -310,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) @@ -328,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) @@ -346,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/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 5fc3f67c5..57a3c5c98 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -41,22 +41,33 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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 @@ -104,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) @@ -171,7 +182,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) @@ -184,7 +195,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) @@ -244,8 +255,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) @@ -297,7 +308,7 @@ class CI_DB_pdo_driver extends CI_DB { /** * Insert ID * - * @param string + * @param string $name * @return int */ public function insert_id($name = NULL) @@ -312,7 +323,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) @@ -356,9 +367,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) @@ -402,10 +413,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) @@ -416,4 +427,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/subdrivers/pdo_4d_driver.php b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php index 70813c479..6ebd92a9b 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php @@ -41,19 +41,28 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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) @@ -81,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) @@ -104,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 = '') @@ -120,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) @@ -135,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) @@ -153,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) @@ -165,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_cubrid_driver.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php index f8e40218e..4f762b91c 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php @@ -41,18 +41,28 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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) @@ -76,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) @@ -98,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 = '') @@ -113,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) @@ -128,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) @@ -169,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_dblib_driver.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php index 0e1482e55..6ac32fc16 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php @@ -41,18 +41,40 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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) @@ -86,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) @@ -116,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) @@ -141,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 = '') @@ -158,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) @@ -176,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) @@ -192,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) diff --git a/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php index 5185f738c..83b9648c1 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php @@ -41,21 +41,30 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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) @@ -91,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) @@ -114,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 = '') @@ -129,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) @@ -144,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) @@ -161,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) @@ -179,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) @@ -191,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_ibm_driver.php b/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php index e0a4b2855..d8dbc50c0 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php @@ -41,16 +41,21 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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) @@ -116,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) @@ -139,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 = '') @@ -155,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) @@ -170,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) @@ -188,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) @@ -200,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_informix_driver.php b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php index 45f30ba23..8998670e1 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php @@ -41,16 +41,21 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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) @@ -109,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) @@ -132,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 = '') @@ -149,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) @@ -164,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) @@ -182,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) @@ -200,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) @@ -212,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_mysql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php index fa8ebfb23..2d076f314 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php @@ -41,19 +41,37 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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) @@ -77,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 */ @@ -111,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) @@ -133,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 = '') @@ -148,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) @@ -163,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) @@ -204,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_oci_driver.php b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php index 1b4cefb22..2e28476ba 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php @@ -41,24 +41,49 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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) @@ -98,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) @@ -121,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 = '') @@ -136,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) @@ -149,9 +174,9 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver { /** * 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) @@ -174,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) @@ -191,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_odbc_driver.php b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php index 1b238a4ed..f6e0e215a 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php @@ -41,29 +41,46 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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) @@ -130,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) @@ -153,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 = '') @@ -168,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) @@ -186,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) @@ -216,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_pgsql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php index 2e9430c62..c3f5b7603 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php @@ -41,10 +41,13 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver { + /** + * Sub-driver + * + * @var string + */ public $subdriver = 'pgsql'; - protected $_random_keyword = ' RANDOM()'; - /** * Database schema * @@ -52,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) @@ -78,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) @@ -100,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) @@ -124,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 = '') @@ -139,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) @@ -154,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) @@ -172,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) @@ -213,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) @@ -225,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_sqlite_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php index 4432b2381..b24b13e76 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php @@ -41,21 +41,30 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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) @@ -82,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) @@ -105,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 = '') @@ -121,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) @@ -134,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) @@ -151,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_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php index 94c2b9832..b8c60c6b2 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php @@ -41,18 +41,40 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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) @@ -110,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) @@ -145,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) @@ -170,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 = '') @@ -187,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) @@ -205,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) @@ -221,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) diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 96ea5f4f9..028dc1996 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -41,12 +41,13 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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 * @@ -54,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() * @@ -171,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) @@ -213,7 +225,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) @@ -226,7 +238,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) @@ -286,8 +298,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) @@ -323,7 +335,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) @@ -401,7 +413,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) @@ -425,7 +437,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 = '') @@ -440,7 +452,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) @@ -470,8 +482,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) @@ -488,9 +500,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) @@ -529,7 +541,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) @@ -541,11 +553,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/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 5e6746d46..85411735c 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -41,13 +41,24 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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 * @@ -113,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) @@ -128,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) @@ -191,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) @@ -251,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) @@ -273,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 = '') @@ -289,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) @@ -321,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) @@ -338,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/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index 92aecef4b..9a2c1eefc 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -42,13 +42,24 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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 * @@ -120,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) @@ -180,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) @@ -240,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) @@ -258,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 = '') @@ -274,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) @@ -304,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) @@ -321,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/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index e49b4b17d..de3d87312 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -41,20 +41,38 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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) @@ -107,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 = '') @@ -131,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) @@ -146,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) @@ -206,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) @@ -274,7 +292,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) { @@ -298,7 +316,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 = '') @@ -313,7 +331,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) @@ -366,8 +384,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) @@ -384,10 +402,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) @@ -402,7 +420,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) @@ -418,11 +436,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) -- cgit v1.2.3-24-g4f1b From 2b73037e450859e85fb468ad7499a26882a67292 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 5 Nov 2012 17:01:11 +0200 Subject: Fix DB drivers version() implementations that don't execute a query Fails if called prior to the DB connection initialization. --- system/database/drivers/cubrid/cubrid_driver.php | 15 ++++++++++++--- system/database/drivers/mysql/mysql_driver.php | 18 +++++++++++++++--- system/database/drivers/mysqli/mysqli_driver.php | 13 ++++++++++--- system/database/drivers/oci8/oci8_driver.php | 18 +++++++++++++++--- system/database/drivers/pdo/pdo_driver.php | 4 ++++ system/database/drivers/postgre/postgre_driver.php | 6 +++++- system/database/drivers/sqlsrv/sqlsrv_driver.php | 6 +++++- 7 files changed, 66 insertions(+), 14 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index 48b904286..c89a924d3 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -179,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; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 2457e558c..b1edc2925 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -191,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; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 7d2507b40..ae17703ac 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -173,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; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 38d2395b6..b2663e2c5 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -240,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; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 57a3c5c98..923f0e125 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -165,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 diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 028dc1996..40f21b1e8 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -204,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; } diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index de3d87312..d3999bf75 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -275,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; } -- cgit v1.2.3-24-g4f1b From a287a34c215903d3452023d74149eb5880125715 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 5 Nov 2012 23:19:59 +0200 Subject: Refactored DB Forge - PDO subdrivers are isolated from each other now. - Added compatibility for pretty much all of the features, for every DB platform. - Unified the way that stuff works in general. - Fixes issue #1005. --- system/database/DB_forge.php | 631 +++++++++++++++++++-- system/database/drivers/cubrid/cubrid_forge.php | 214 +++---- system/database/drivers/ibase/ibase_forge.php | 204 ++++--- system/database/drivers/mssql/mssql_forge.php | 160 +++--- system/database/drivers/mysql/mysql_forge.php | 207 +++---- system/database/drivers/mysqli/mysqli_forge.php | 207 +++---- system/database/drivers/oci8/oci8_forge.php | 131 ++--- system/database/drivers/odbc/odbc_forge.php | 126 +--- system/database/drivers/pdo/pdo_forge.php | 131 +---- .../drivers/pdo/subdrivers/pdo_4d_forge.php | 209 +++++++ .../drivers/pdo/subdrivers/pdo_cubrid_forge.php | 173 ++++++ .../drivers/pdo/subdrivers/pdo_dblib_forge.php | 136 +++++ .../drivers/pdo/subdrivers/pdo_firebird_forge.php | 228 ++++++++ .../drivers/pdo/subdrivers/pdo_ibm_forge.php | 146 +++++ .../drivers/pdo/subdrivers/pdo_informix_forge.php | 155 +++++ .../drivers/pdo/subdrivers/pdo_mysql_forge.php | 198 +++++++ .../drivers/pdo/subdrivers/pdo_oci_forge.php | 133 +++++ .../drivers/pdo/subdrivers/pdo_odbc_forge.php | 62 ++ .../drivers/pdo/subdrivers/pdo_pgsql_forge.php | 193 +++++++ .../drivers/pdo/subdrivers/pdo_sqlite_forge.php | 228 ++++++++ .../drivers/pdo/subdrivers/pdo_sqlsrv_forge.php | 136 +++++ system/database/drivers/postgre/postgre_forge.php | 245 ++++---- system/database/drivers/sqlite/sqlite_forge.php | 192 +++---- system/database/drivers/sqlite3/sqlite3_forge.php | 201 +++---- system/database/drivers/sqlsrv/sqlsrv_forge.php | 160 +++--- 25 files changed, 3437 insertions(+), 1369 deletions(-) create mode 100644 system/database/drivers/pdo/subdrivers/pdo_4d_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_informix_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_oci_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php create mode 100644 system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index f46237e25..d8ecefe77 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -35,6 +35,13 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ abstract class CI_DB_forge { + /** + * Database object + * + * @var object + */ + public $db; + /** * Fields data * @@ -80,23 +87,68 @@ abstract class CI_DB_forge { protected $_drop_database = 'DROP DATABASE %s'; /** - * DROP TABLE statement + * 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 = 'DROP TABLE IF EXISTS %s'; + protected $_drop_table_if = 'DROP TABLE IF EXISTS'; /** * RENAME TABLE statement * * @var string */ - protected $_rename_table = 'ALTER TABLE %s RENAME TO %s'; + 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 '; // -------------------------------------------------------------------- /** - * Constructor + * Class constructor * * @return void */ @@ -113,7 +165,7 @@ abstract class CI_DB_forge { /** * Create database * - * @param string the database name + * @param string $db_name * @return bool */ public function create_database($db_name) @@ -140,7 +192,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) @@ -176,25 +228,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 ($primary && is_array($key)) + if (empty($key)) + { + show_error('Key information is required for that operation.'); + } + + if (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) @@ -214,12 +266,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.'); } @@ -261,8 +313,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) @@ -271,51 +323,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_unsuported_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; } + 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) @@ -324,7 +454,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); } // -------------------------------------------------------------------- @@ -332,8 +495,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) @@ -370,32 +533,37 @@ abstract class CI_DB_forge { /** * Column Add * - * @param string the table name - * @param string the column name - * @param string the column definition + * @param string $table Table name + * @param array $field Column definition * @return bool */ - public function add_column($table = '', $field = array(), $after_field = '') + public function add_column($table = '', $field = array()) { 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 + // Work-around for literal column definitions + if ( ! is_array($field)) + { + $field = array($field); + } + foreach (array_keys($field) as $k) { $this->add_field(array($k => $field[$k])); + } - if (count($this->fields) === 0) - { - show_error('Field information is required.'); - } - - $sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field); - $this->_reset(); + $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_unsuported_feature') : FALSE; + } + for ($i = 0, $c = count($sqls); $i < $c; $i++) + { if ($this->db->query($sql) === FALSE) { return FALSE; @@ -410,8 +578,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 = '') @@ -426,7 +594,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_unsuported_feature') : FALSE; + } + + return $this->db->query($sql); } // -------------------------------------------------------------------- @@ -434,8 +608,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()) @@ -445,32 +619,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_unsuported_feature') : FALSE; + } + + for ($i = 0, $c = count($sqls); $i < $c; $i++) + { + if ($this->db->query($sql) === 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/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php index 33d502137..e3f8bc334 100644 --- a/system/database/drivers/cubrid/cubrid_forge.php +++ b/system/database/drivers/cubrid/cubrid_forge.php @@ -42,8 +42,6 @@ class CI_DB_cubrid_forge extends CI_DB_forge { */ protected $_create_database = FALSE; - // -------------------------------------------------------------------- - /** * DROP DATABASE statement * @@ -52,177 +50,121 @@ class CI_DB_cubrid_forge extends CI_DB_forge { protected $_drop_database = FALSE; /** - * Process Fields + * CREATE TABLE IF statement * - * @param mixed $fields - * @return string + * @var string + */ + protected $_create_table_if = FALSE; + + /** + * UNSIGNED support + * + * @var array */ - protected function _process_fields($fields) + 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) { - $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) - { - $sql .= ' AUTO_INCREMENT'; - } - - if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) + $sqls[] = $sql.' CHANGE '.$this->_process_column($field[$i]); + if ( ! empty($field[$i]['new_name'])) { - $sql .= ' UNIQUE'; + $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' AS '.$this->db->escape_identifiers($field[$i]['name']); } } - - // 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 + * Field attribute TYPE * - * @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 + * Performs a data type mapping between different databases. + * + * @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 '; - - /* As of version 8.4.1 CUBRID does not support this SQL syntax. - if ($if_not_exists === TRUE) + switch (strtoupper($attributes['TYPE'])) { - $sql .= 'IF NOT EXISTS '; + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + default: return; } - */ - - $sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields); - - // 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) - { - 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).')'; - } - } - - 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/ibase/ibase_forge.php b/system/database/drivers/ibase/ibase_forge.php index 7c4d00a23..a0c4e6563 100644 --- a/system/database/drivers/ibase/ibase_forge.php +++ b/system/database/drivers/ibase/ibase_forge.php @@ -36,11 +36,43 @@ defined('BASEPATH') OR exit('No direct script access allowed'); class CI_DB_ibase_forge extends CI_DB_forge { /** - * DROP TABLE statement + * CREATE TABLE IF statement * * @var string */ - protected $_drop_table = 'DROP TABLE %s'; + 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'; // -------------------------------------------------------------------- @@ -65,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 = '') @@ -90,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/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index 1eef648b0..5eebedbf7 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -36,130 +36,98 @@ defined('BASEPATH') OR exit('No direct script access allowed'); class CI_DB_mssql_forge extends CI_DB_forge { /** - * DROP TABLE statement + * CREATE TABLE IF statement * * @var string */ - protected $_drop_table = 'DROP TABLE %s'; - - // -------------------------------------------------------------------- + protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE"; /** - * 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 = ($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']; + protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE"; - if (stripos($attributes['TYPE'], 'INT') === FALSE && ! empty($attributes['CONSTRAINT'])) - { - $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'; - } - } + /** + * 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/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 7ce4e8b00..ea3207760 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -42,165 +42,140 @@ class CI_DB_mysql_forge extends CI_DB_forge { */ protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s'; - // -------------------------------------------------------------------- - /** - * Process Fields + * UNSIGNED support * - * @param mixed $fields - * @return string + * @var array */ - 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 $_unsigned = array( + 'TINYINT', + 'SMALLINT', + 'MEDIUMINT', + 'INT', + 'INTEGER', + 'BIGINT', + 'REAL', + 'DOUBLE', + 'DOUBLE PRECISION', + 'FLOAT', + 'DECIMAL', + 'NUMERIC' + ); - 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'; + /** + * 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 + * + * @return void + */ + public function __construct() + { + parent::__construct(); - 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['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE "; } - $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')'; + $field[$i] = $field['_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) + { + 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']; + } + + // -------------------------------------------------------------------- + + /** + * 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_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 0732dfea5..914d6a268 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -42,165 +42,140 @@ class CI_DB_mysqli_forge extends CI_DB_forge { */ protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s'; - // -------------------------------------------------------------------- - /** - * Process Fields + * UNSIGNED support * - * @param mixed $fields - * @return string + * @var array */ - 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 $_unsigned = array( + 'TINYINT', + 'SMALLINT', + 'MEDIUMINT', + 'INT', + 'INTEGER', + 'BIGINT', + 'REAL', + 'DOUBLE', + 'DOUBLE PRECISION', + 'FLOAT', + 'DECIMAL', + 'NUMERIC' + ); - 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'; + /** + * 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 + * + * @return void + */ + public function __construct() + { + parent::__construct(); - 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['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE "; } - $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')'; + $field[$i] = $field['_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) + { + 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']; + } + + // -------------------------------------------------------------------- + + /** + * 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/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index ad578f830..bd9d2df3c 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -50,126 +50,81 @@ class CI_DB_oci8_forge extends CI_DB_forge { protected $_drop_database = FALSE; /** - * DROP TABLE statement + * DROP TABLE IF statement * * @var string */ - protected $_drop_table = 'DROP TABLE %s'; + protected $_drop_table_if = FALSE; + + /** + * UNSIGNED support + * + * @var bool|array + */ + protected $_unsigned = FALSE; // -------------------------------------------------------------------- /** - * 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) + protected function _alter_table($alter_type, $table, $field) { - $sql = 'CREATE TABLE '; - - if ($if_not_exists === TRUE) + 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) - { - $sql .= ' UNSIGNED'; - } - - if (isset($attributes['DEFAULT'])) + $field[$i]['_literal'] = "\n\t".$this->_process_column($field[$i]); + if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name'])) { - $sql .= " DEFAULT '".$attributes['DEFAULT']."'"; + $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' '.$this->db->escape_identifiers($field[$i]['new_name']); } - - $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/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 699ce996c..fb16ca5cf 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -36,130 +36,38 @@ defined('BASEPATH') OR exit('No direct script access allowed'); class CI_DB_odbc_forge extends CI_DB_forge { /** - * DROP TABLE statement + * CREATE TABLE IF statement * * @var string */ - protected $_drop_table = 'DROP TABLE %s'; - - // -------------------------------------------------------------------- + protected $_create_table_if = FALSE; /** - * 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 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'; + protected $_drop_table_if = FALSE; - 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->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)"; - } + /** + * 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/pdo/pdo_forge.php b/system/database/drivers/pdo/pdo_forge.php index e77970cf2..130d3667e 100644 --- a/system/database/drivers/pdo/pdo_forge.php +++ b/system/database/drivers/pdo/pdo_forge.php @@ -36,139 +36,18 @@ defined('BASEPATH') OR exit('No direct script access allowed'); class CI_DB_pdo_forge extends CI_DB_forge { /** - * DROP TABLE statement + * CREATE TABLE IF statement * * @var string */ - protected $_drop_table = 'DROP TABLE %s'; - - // -------------------------------------------------------------------- - - /** - * Create 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 - */ - 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/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 @@ + '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_forge.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php new file mode 100644 index 000000000..c01a0fb81 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php @@ -0,0 +1,173 @@ + '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; + } + + // -------------------------------------------------------------------- + + /** + * 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_forge.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php new file mode 100644 index 000000000..fb33127fd --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php @@ -0,0 +1,136 @@ + '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_forge.php b/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php new file mode 100644 index 000000000..88c53510a --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php @@ -0,0 +1,228 @@ + '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_forge.php b/system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php new file mode 100644 index 000000000..6a2c9b87e --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php @@ -0,0 +1,146 @@ + '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_forge.php b/system/database/drivers/pdo/subdrivers/pdo_informix_forge.php new file mode 100644 index 000000000..715a7cbba --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_informix_forge.php @@ -0,0 +1,155 @@ + '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_forge.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php new file mode 100644 index 000000000..dc856ed2c --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php @@ -0,0 +1,198 @@ +_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['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE "; + } + + $field[$i] = $field['_literal'].$this->_process_column($field[$i]); + } + } + + return array($sql.implode(',', $field)); + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + 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']; + } + + // -------------------------------------------------------------------- + + /** + * 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_forge.php b/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php new file mode 100644 index 000000000..dbcb64d31 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php @@ -0,0 +1,133 @@ +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_forge.php b/system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php new file mode 100644 index 000000000..cd6b19c68 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php @@ -0,0 +1,62 @@ + '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 + * + * @return void + */ + public function __construct() + { + parent::__construct(); + + 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_forge.php b/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php new file mode 100644 index 000000000..414826212 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php @@ -0,0 +1,228 @@ +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_forge.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php new file mode 100644 index 000000000..c62720d48 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php @@ -0,0 +1,136 @@ + '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_forge.php b/system/database/drivers/postgre/postgre_forge.php index b08fa5177..ad26763a4 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -36,188 +36,149 @@ defined('BASEPATH') OR exit('No direct script access allowed'); class CI_DB_postgre_forge extends CI_DB_forge { /** - * DROP TABLE statement + * 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 $_drop_table = 'DROP TABLE IF EXISTS %s CASCADE'; + protected $_null = 'NULL'; // -------------------------------------------------------------------- /** - * Process Fields + * Class constructor * - * @param mixed $fields - * @param array $primary_keys - * @return string + * @return void */ - protected function _process_fields($fields, $primary_keys = array()) + public function __construct() { - $sql = ''; - $current_field_count = 0; + parent::__construct(); - 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) { - $sql .= "\n\t".$attributes; + return FALSE; } - else + + if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type'])) { - $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.' 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 (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 $sql; - } + return $sqls; + } // -------------------------------------------------------------------- /** - * Create Table + * Field attribute TYPE * - * @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 + * Performs a data type mapping between different databases. + * + * @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)).')'; - } - - $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).');'; - } - } + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + default: return; } - - 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 $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/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 5650af7be..6ad583560 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -35,10 +35,33 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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 = '') @@ -53,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 = '') @@ -77,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/sqlite3/sqlite3_forge.php b/system/database/drivers/sqlite3/sqlite3_forge.php index e1dd3fa91..7ba0f7bab 100644 --- a/system/database/drivers/sqlite3/sqlite3_forge.php +++ b/system/database/drivers/sqlite3/sqlite3_forge.php @@ -35,10 +35,43 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ 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 + * + * @return void + */ + public function __construct() + { + parent::__construct(); + + 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 = '') @@ -53,7 +86,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 = '') @@ -85,125 +118,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/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php index 8155565c0..da8f68c56 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_forge.php +++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php @@ -36,130 +36,98 @@ defined('BASEPATH') OR exit('No direct script access allowed'); class CI_DB_sqlsrv_forge extends CI_DB_forge { /** - * DROP TABLE statement + * CREATE TABLE IF statement * * @var string */ - protected $_drop_table = 'DROP TABLE %s'; - - // -------------------------------------------------------------------- + protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE"; /** - * 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 = ($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']; + protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE"; - if (stripos($attributes['TYPE'], 'INT') === FALSE && ! empty($attributes['CONSTRAINT'])) - { - $sql .= '('.$attributes['CONSTRAINT'].')'; - } - - if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) - { - $sql .= ' UNSIGNED'; - } - - if (isset($attributes['DEFAULT'])) - { - $sql .= " DEFAULT '".$attributes['DEFAULT']."'"; - } - - $sql .= ( ! empty($attributes['NULL']) && $attribues['NULL'] === TRUE) - ? ' NULL' : ' NOT NULL'; - - 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)'; + } } } -- cgit v1.2.3-24-g4f1b From 137a742409b2a643e70f422efa17ca535b47d218 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 5 Nov 2012 23:46:44 +0200 Subject: Fix Forge add_column() and modify_column() --- system/database/DB_forge.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index d8ecefe77..c284d7d82 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -564,7 +564,7 @@ abstract class CI_DB_forge { for ($i = 0, $c = count($sqls); $i < $c; $i++) { - if ($this->db->query($sql) === FALSE) + if ($this->db->query($sqls[$i]) === FALSE) { return FALSE; } @@ -644,7 +644,7 @@ abstract class CI_DB_forge { for ($i = 0, $c = count($sqls); $i < $c; $i++) { - if ($this->db->query($sql) === FALSE) + if ($this->db->query($sqls[$i]) === FALSE) { return FALSE; } -- cgit v1.2.3-24-g4f1b From d743cdbe448258cc7f02abf15e8dc797dc6403eb Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 6 Nov 2012 00:00:01 +0200 Subject: Re-fix multiple-column non-primary key indexes --- system/database/DB_forge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index c284d7d82..2b9fb169a 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -239,7 +239,7 @@ abstract class CI_DB_forge { show_error('Key information is required for that operation.'); } - if (is_array($key)) + if ($primary === TRUE && is_array($key)) { foreach ($key as $one) { -- cgit v1.2.3-24-g4f1b From eaa60c71082c1e49f8a48d633347c98b68a387c0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 6 Nov 2012 01:11:22 +0200 Subject: Added possibility to pass custom database objects to DB Forge and DB Utilities Also, their property is no longer public and the utility class no longer extends CI_DB_forge. --- system/database/DB_forge.php | 9 ++++----- system/database/DB_utility.php | 11 +++++------ system/database/drivers/mysql/mysql_forge.php | 5 +++-- system/database/drivers/mysqli/mysqli_forge.php | 5 +++-- system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php | 5 +++-- system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php | 5 +++-- system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php | 5 +++-- system/database/drivers/postgre/postgre_forge.php | 5 +++-- system/database/drivers/sqlite3/sqlite3_forge.php | 5 +++-- 9 files changed, 30 insertions(+), 25 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 2b9fb169a..34140c6e0 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -40,7 +40,7 @@ abstract class CI_DB_forge { * * @var object */ - public $db; + protected $db; /** * Fields data @@ -150,13 +150,12 @@ abstract class CI_DB_forge { /** * 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'); } diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index f7bef6a2c..a8e34c92d 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -33,14 +33,14 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @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 { /** * Database object * * @var object */ - public $db; + protected $db; // -------------------------------------------------------------------- @@ -70,13 +70,12 @@ abstract class CI_DB_utility extends CI_DB_forge { /** * 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'); } diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index ea3207760..019f6d353 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -74,11 +74,12 @@ class CI_DB_mysql_forge extends CI_DB_forge { /** * Class constructor * + * @param object &$db Database object * @return void */ - public function __construct() + public function __construct(&$db) { - parent::__construct(); + parent::__construct($db); $this->_create_table .= ' DEFAULT CHARSET '.$this->db->char_set.' COLLATE '.$this->db->dbcollat; } diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 914d6a268..088a6a09a 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -74,11 +74,12 @@ class CI_DB_mysqli_forge extends CI_DB_forge { /** * Class constructor * + * @param object &$db Database object * @return void */ - public function __construct() + public function __construct(&$db) { - parent::__construct(); + parent::__construct($db); $this->_create_table .= ' DEFAULT CHARSET '.$this->db->char_set.' COLLATE '.$this->db->dbcollat; } diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php index dc856ed2c..2add7d204 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php @@ -88,11 +88,12 @@ class CI_DB_pdo_mysql_forge extends CI_DB_pdo_forge { /** * Class constructor * + * @param object &$db Database object * @return void */ - public function __construct() + public function __construct(&$db) { - parent::__construct(); + parent::__construct($db); $this->_create_table .= ' DEFAULT CHARSET '.$this->db->char_set.' COLLATE '.$this->db->dbcollat; } diff --git a/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php index b5235d24b..1e4d2ac59 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php @@ -71,11 +71,12 @@ class CI_DB_pdo_pgsql_forge extends CI_DB_pdo_forge { /** * Class constructor * + * @param object &$db Database object * @return void */ - public function __construct() + public function __construct(&$db) { - parent::__construct(); + parent::__construct($db); if (version_compare($this->db->version(), '9.0', '>')) { diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php b/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php index 414826212..2e5f12379 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php @@ -68,11 +68,12 @@ class CI_DB_pdo_sqlite_forge extends CI_DB_pdo_forge { /** * Class constructor * + * @param object &$db Database object * @return void */ - public function __construct() + public function __construct(&$db) { - parent::__construct(); + parent::__construct($db); if (version_compare($this->db->version(), '3.3', '<')) { diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index ad26763a4..425622fac 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -64,11 +64,12 @@ class CI_DB_postgre_forge extends CI_DB_forge { /** * Class constructor * + * @param object &$db Database object * @return void */ - public function __construct() + public function __construct(&$db) { - parent::__construct(); + parent::__construct($db); if (version_compare($this->db->version(), '9.0', '>')) { diff --git a/system/database/drivers/sqlite3/sqlite3_forge.php b/system/database/drivers/sqlite3/sqlite3_forge.php index 7ba0f7bab..e9b91e972 100644 --- a/system/database/drivers/sqlite3/sqlite3_forge.php +++ b/system/database/drivers/sqlite3/sqlite3_forge.php @@ -54,11 +54,12 @@ class CI_DB_sqlite3_forge extends CI_DB_forge { /** * Class constructor * + * @param object &$db Database object * @return void */ - public function __construct() + public function __construct(&$db) { - parent::__construct(); + parent::__construct($db); if (version_compare($this->db->version(), '3.3', '<')) { -- cgit v1.2.3-24-g4f1b From a7ddd2d48ec30f10250b045dbec651fc0e07532e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 6 Nov 2012 11:53:45 +0200 Subject: Fix an escape_identifiers() bug --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 39db16150..dfaf0e0c1 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1236,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; } -- cgit v1.2.3-24-g4f1b From bdd9c118c6e04ec8dc9b6bb1a2fb8a39214dca72 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 6 Nov 2012 12:07:16 +0200 Subject: Add an optional escape parameter to insert() and insert_batch() "Fixes" #1895 --- system/database/DB_query_builder.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 41b30aec3..a3ba77360 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -1403,13 +1403,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver { * * @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) @@ -1432,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(); } @@ -1558,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) @@ -1574,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) -- cgit v1.2.3-24-g4f1b From 083e3c8d39a4fb9f8ef37f61f0ea42ec3fe1389f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 6 Nov 2012 12:48:32 +0200 Subject: Fix #589 --- system/database/DB_query_builder.php | 8 ++++---- system/database/drivers/mssql/mssql_driver.php | 23 ++++++++++++++++++++++ system/database/drivers/oci8/oci8_driver.php | 2 +- .../drivers/pdo/subdrivers/pdo_dblib_driver.php | 23 ++++++++++++++++++++++ .../drivers/pdo/subdrivers/pdo_oci_driver.php | 2 +- .../drivers/pdo/subdrivers/pdo_sqlsrv_driver.php | 23 ++++++++++++++++++++++ system/database/drivers/sqlsrv/sqlsrv_driver.php | 23 ++++++++++++++++++++++ 7 files changed, 98 insertions(+), 6 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index a3ba77360..364397721 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -1444,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) diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index c74f9683b..67557196c 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -488,6 +488,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_unsuported_feature') : FALSE; + } + + // -------------------------------------------------------------------- + /** * Close DB Connection * diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index b2663e2c5..eb01dd17e 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -604,7 +604,7 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Insert_batch statement + * Insert batch statement * * Generates a platform-specific insert string from the supplied data * diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php index 6ac32fc16..2a3e0b6f6 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php @@ -262,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_unsuported_feature') : FALSE; + } + } /* End of file pdo_dblib_driver.php */ diff --git a/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php index 2e28476ba..e1beb3683 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php @@ -172,7 +172,7 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- /** - * Insert_batch statement + * Insert batch statement * * @param string $table Table name * @param array $keys INSERT keys diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php index b8c60c6b2..65825dd34 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php @@ -296,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_unsuported_feature') : FALSE; + } + } /* End of file pdo_sqlsrv_driver.php */ diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index d3999bf75..3196ac103 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -495,6 +495,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_unsuported_feature') : FALSE; + } + + // -------------------------------------------------------------------- + /** * Close DB Connection * -- cgit v1.2.3-24-g4f1b From 8d3afde93f9ff7f461095d5b9147b662610c045b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 6 Nov 2012 12:53:47 +0200 Subject: Fix a lang key typo --- system/database/DB_forge.php | 16 ++++++++-------- system/database/DB_utility.php | 10 +++++----- system/database/drivers/cubrid/cubrid_utility.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mssql/mssql_utility.php | 2 +- system/database/drivers/oci8/oci8_utility.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/odbc/odbc_utility.php | 2 +- system/database/drivers/pdo/pdo_result.php | 2 +- system/database/drivers/pdo/pdo_utility.php | 2 +- .../database/drivers/pdo/subdrivers/pdo_dblib_driver.php | 2 +- .../drivers/pdo/subdrivers/pdo_sqlsrv_driver.php | 2 +- system/database/drivers/postgre/postgre_utility.php | 2 +- system/database/drivers/sqlite/sqlite_utility.php | 2 +- system/database/drivers/sqlite3/sqlite3_utility.php | 2 +- system/database/drivers/sqlsrv/sqlsrv_driver.php | 2 +- system/database/drivers/sqlsrv/sqlsrv_utility.php | 2 +- 17 files changed, 28 insertions(+), 28 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 34140c6e0..7c9c03e24 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -171,7 +171,7 @@ abstract class CI_DB_forge { { 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))) { @@ -203,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))) { @@ -339,7 +339,7 @@ abstract class CI_DB_forge { $this->_reset(); if ($sql === 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; } } @@ -434,7 +434,7 @@ abstract class CI_DB_forge { $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) { @@ -507,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, @@ -558,7 +558,7 @@ abstract class CI_DB_forge { $this->_reset(); if ($sqls === 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; } for ($i = 0, $c = count($sqls); $i < $c; $i++) @@ -596,7 +596,7 @@ abstract class CI_DB_forge { $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name); if ($sql === 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; } return $this->db->query($sql); @@ -638,7 +638,7 @@ abstract class CI_DB_forge { $this->_reset(); if ($sqls === 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; } for ($i = 0, $c = count($sqls); $i < $c; $i++) diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index a8e34c92d..488ebf3ac 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -95,7 +95,7 @@ abstract class CI_DB_utility { } 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(); @@ -139,7 +139,7 @@ abstract class CI_DB_utility { { 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))); @@ -163,7 +163,7 @@ abstract class CI_DB_utility { { 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(); @@ -200,7 +200,7 @@ abstract class CI_DB_utility { { 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))); @@ -361,7 +361,7 @@ abstract class CI_DB_utility { { 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_utility.php b/system/database/drivers/cubrid/cubrid_utility.php index 82d37af3c..d76eca432 100644 --- a/system/database/drivers/cubrid/cubrid_utility.php +++ b/system/database/drivers/cubrid/cubrid_utility.php @@ -63,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/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 67557196c..a9d53fb57 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -506,7 +506,7 @@ class CI_DB_mssql_driver extends CI_DB { return parent::_insert_batch($table, $keys, $values); } - 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; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index a011d5974..76c7cb9c2 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -58,7 +58,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { 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/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index e5aae8132..d15537fdf 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -51,7 +51,7 @@ class CI_DB_oci8_utility extends CI_DB_utility { 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 88df615e6..1710aafae 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -250,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; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index bfa94f469..908674a9d 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -44,7 +44,7 @@ class CI_DB_odbc_utility extends CI_DB_utility { 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_result.php b/system/database/drivers/pdo/pdo_result.php index 1de5a47ec..32ab1c280 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -163,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; diff --git a/system/database/drivers/pdo/pdo_utility.php b/system/database/drivers/pdo/pdo_utility.php index 03b309249..86f2b120a 100644 --- a/system/database/drivers/pdo/pdo_utility.php +++ b/system/database/drivers/pdo/pdo_utility.php @@ -44,7 +44,7 @@ class CI_DB_pdo_utility extends CI_DB_utility { 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_dblib_driver.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php index 2a3e0b6f6..7121819ec 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php @@ -282,7 +282,7 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver { return parent::_insert_batch($table, $keys, $values); } - 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; } } diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php index 65825dd34..7bb7f8806 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php @@ -316,7 +316,7 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver { return parent::_insert_batch($table, $keys, $values); } - 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; } } diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index bae1c6704..d3b2b9cdc 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -60,7 +60,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { 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_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 2fd5c85f6..222d02712 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -44,7 +44,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { 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_utility.php b/system/database/drivers/sqlite3/sqlite3_utility.php index 6f276ebcc..c7736cc6d 100644 --- a/system/database/drivers/sqlite3/sqlite3_utility.php +++ b/system/database/drivers/sqlite3/sqlite3_utility.php @@ -44,7 +44,7 @@ class CI_DB_sqlite3_utility extends CI_DB_utility { 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 3196ac103..09ccc0200 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -513,7 +513,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { return parent::_insert_batch($table, $keys, $values); } - 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; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlsrv/sqlsrv_utility.php b/system/database/drivers/sqlsrv/sqlsrv_utility.php index 315090049..2bc7f9e03 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_utility.php +++ b/system/database/drivers/sqlsrv/sqlsrv_utility.php @@ -60,7 +60,7 @@ class CI_DB_sqlsrv_utility extends CI_DB_utility { protected function _backup($params = array()) { // Currently unsupported - return $this->db->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsupported_feature'); } } -- cgit v1.2.3-24-g4f1b From e8b896348dc29a1c1e02d97b06b7497613924ad6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 8 Nov 2012 12:05:00 +0200 Subject: Fix #1985 --- system/database/drivers/mysql/mysql_forge.php | 4 ++-- system/database/drivers/mysqli/mysqli_forge.php | 4 ++-- system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 019f6d353..9cee385df 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -118,10 +118,10 @@ class CI_DB_mysql_forge extends CI_DB_forge { } else { - $field[$i]['_literal'] = empty($field['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE "; + $field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE "; } - $field[$i] = $field['_literal'].$this->_process_column($field[$i]); + $field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]); } } diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 088a6a09a..294fc20b6 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -118,10 +118,10 @@ class CI_DB_mysqli_forge extends CI_DB_forge { } else { - $field[$i]['_literal'] = empty($field['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE "; + $field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE "; } - $field[$i] = $field['_literal'].$this->_process_column($field[$i]); + $field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]); } } diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php index 2add7d204..1e69d693e 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php @@ -132,10 +132,10 @@ class CI_DB_pdo_mysql_forge extends CI_DB_pdo_forge { } else { - $field[$i]['_literal'] = empty($field['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE "; + $field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE "; } - $field[$i] = $field['_literal'].$this->_process_column($field[$i]); + $field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]); } } -- cgit v1.2.3-24-g4f1b From 53b8ef524529e6ca9f32ad49d36c5140df84feb0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 8 Nov 2012 21:38:53 +0200 Subject: Polish docs for HTML, Inflector, Language, Number, Path, Security and Smiley helpers Also fixed a DB_cache bug introduced in previous commit and removed an unused parameter in a smiley helper --- system/database/DB_cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index b8f8995fa..1be80c5c7 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -199,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); } } -- cgit v1.2.3-24-g4f1b From b0a97c100f5e7edc5e21ec7d07f768cd3b5618da Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 11 Nov 2012 13:58:53 +0200 Subject: Fix DBForge index creation on MySQL and CUBRID --- system/database/drivers/cubrid/cubrid_forge.php | 10 ++++++++++ system/database/drivers/mysql/mysql_forge.php | 10 ++++++++++ system/database/drivers/mysqli/mysqli_forge.php | 10 ++++++++++ system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php | 10 ++++++++++ system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php | 10 ++++++++++ 5 files changed, 50 insertions(+) (limited to 'system/database') diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php index e3f8bc334..86a41e57b 100644 --- a/system/database/drivers/cubrid/cubrid_forge.php +++ b/system/database/drivers/cubrid/cubrid_forge.php @@ -42,6 +42,16 @@ class CI_DB_cubrid_forge extends CI_DB_forge { */ 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 * diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 9cee385df..d4a8b4ff7 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -42,6 +42,16 @@ class CI_DB_mysql_forge extends CI_DB_forge { */ protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s'; + /** + * CREATE TABLE keys flag + * + * Whether table keys are created from within the + * CREATE TABLE statement. + * + * @var bool + */ + protected $_create_table_keys = TRUE; + /** * UNSIGNED support * diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 294fc20b6..5a6560b25 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -42,6 +42,16 @@ class CI_DB_mysqli_forge extends CI_DB_forge { */ protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s'; + /** + * CREATE TABLE keys flag + * + * Whether table keys are created from within the + * CREATE TABLE statement. + * + * @var bool + */ + protected $_create_table_keys = TRUE; + /** * UNSIGNED support * diff --git a/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php index c01a0fb81..d63a4b0a6 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php @@ -49,6 +49,16 @@ class CI_DB_pdo_cubrid_forge extends CI_DB_pdo_forge { */ 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 * diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php index 1e69d693e..24c470a83 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php @@ -49,6 +49,16 @@ class CI_DB_pdo_mysql_forge extends CI_DB_pdo_forge { */ 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 * -- cgit v1.2.3-24-g4f1b From b67277b8063b0e6aab051ce269194255ef83e808 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 12 Nov 2012 12:51:14 +0200 Subject: Bring back the AFTER clause for DB Forge add_column() (it was temporarily removed due to multiple inconsistencies with other drivers) This commit also fixes issue #1988. Also added support for the FIRST clause (again, MySQL and CUBRID only). --- system/database/DB_forge.php | 10 ++++++- system/database/drivers/cubrid/cubrid_forge.php | 29 ++++++++++++++++++++ system/database/drivers/mysql/mysql_forge.php | 11 +++++++- system/database/drivers/mysqli/mysqli_forge.php | 11 +++++++- .../drivers/pdo/subdrivers/pdo_cubrid_forge.php | 31 +++++++++++++++++++++- .../drivers/pdo/subdrivers/pdo_dblib_forge.php | 2 +- .../drivers/pdo/subdrivers/pdo_firebird_forge.php | 2 +- .../drivers/pdo/subdrivers/pdo_ibm_forge.php | 2 +- .../drivers/pdo/subdrivers/pdo_informix_forge.php | 2 +- .../drivers/pdo/subdrivers/pdo_mysql_forge.php | 13 +++++++-- .../drivers/pdo/subdrivers/pdo_oci_forge.php | 2 +- .../drivers/pdo/subdrivers/pdo_odbc_forge.php | 2 +- .../drivers/pdo/subdrivers/pdo_pgsql_forge.php | 2 +- .../drivers/pdo/subdrivers/pdo_sqlite_forge.php | 2 +- .../drivers/pdo/subdrivers/pdo_sqlsrv_forge.php | 2 +- 15 files changed, 108 insertions(+), 15 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 7c9c03e24..21046012a 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -532,11 +532,13 @@ abstract class CI_DB_forge { /** * Column Add * + * @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()) + public function add_column($table = '', $field = array(), $_after = NULL) { if ($table === '') { @@ -551,6 +553,12 @@ abstract class CI_DB_forge { 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'])) + { + $field[$k]['after'] = $_after; + } + $this->add_field(array($k => $field[$k])); } diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php index 86a41e57b..05762ba5a 100644 --- a/system/database/drivers/cubrid/cubrid_forge.php +++ b/system/database/drivers/cubrid/cubrid_forge.php @@ -122,6 +122,35 @@ class CI_DB_cubrid_forge extends CI_DB_forge { // -------------------------------------------------------------------- + /** + * 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 * diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index d4a8b4ff7..6c5dfc665 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -148,6 +148,14 @@ class CI_DB_mysql_forge extends CI_DB_forge { */ 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'] @@ -155,7 +163,8 @@ class CI_DB_mysql_forge extends CI_DB_forge { .$field['null'] .$field['default'] .$field['auto_increment'] - .$field['unique']; + .$field['unique'] + .$extra_clause; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 5a6560b25..a70eef88f 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -148,6 +148,14 @@ class CI_DB_mysqli_forge extends CI_DB_forge { */ 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'] @@ -155,7 +163,8 @@ class CI_DB_mysqli_forge extends CI_DB_forge { .$field['null'] .$field['default'] .$field['auto_increment'] - .$field['unique']; + .$field['unique'] + .$extra_clause; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php index d63a4b0a6..e8421ec41 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php @@ -1,4 +1,4 @@ -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 * diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php index fb33127fd..236e1cce2 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php @@ -1,4 +1,4 @@ -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'] @@ -169,7 +177,8 @@ class CI_DB_pdo_mysql_forge extends CI_DB_pdo_forge { .$field['null'] .$field['default'] .$field['auto_increment'] - .$field['unique']; + .$field['unique'] + .$extra_clause; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php b/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php index dbcb64d31..8052d218f 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php @@ -1,4 +1,4 @@ - Date: Mon, 12 Nov 2012 14:29:49 +0200 Subject: Let's follow the style guide... --- system/database/DB.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 79e5c7ad2..f4062fa73 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -50,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); } } } @@ -85,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) { @@ -106,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); -- cgit v1.2.3-24-g4f1b