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/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 ++- 4 files changed, 8 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/sqlite3') diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index 22c72b9b8..92aecef4b 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -1,4 +1,4 @@ - Date: Fri, 2 Nov 2012 02:04:59 +0200 Subject: [ci skip] DocBlocks for DB drivers' utility classes Partially fixes issue #1295. --- system/database/drivers/sqlite3/sqlite3_utility.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/sqlite3') 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()) -- 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/sqlite3/sqlite3_result.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'system/database/drivers/sqlite3') 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) -- 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/drivers/sqlite3/sqlite3_driver.php | 37 ++++++++++++++-------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'system/database/drivers/sqlite3') 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) -- 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/drivers/sqlite3/sqlite3_forge.php | 201 +++++++++++----------- 1 file changed, 102 insertions(+), 99 deletions(-) (limited to 'system/database/drivers/sqlite3') 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(); + } } } -- 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/drivers/sqlite3/sqlite3_forge.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/sqlite3') 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 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/drivers/sqlite3/sqlite3_utility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/sqlite3') 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'); } } -- cgit v1.2.3-24-g4f1b