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/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 ++- 4 files changed, 8 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/sqlite') diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 2fd39346f..5e6746d46 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_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/sqlite/sqlite_utility.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/sqlite') 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()) -- 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/sqlite/sqlite_result.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/database/drivers/sqlite') 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') -- 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/sqlite/sqlite_driver.php | 39 +++++++++++++++--------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'system/database/drivers/sqlite') 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) -- 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/sqlite/sqlite_forge.php | 192 ++++++++++++------------ 1 file changed, 92 insertions(+), 100 deletions(-) (limited to 'system/database/drivers/sqlite') 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(); + } } } -- 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/sqlite/sqlite_utility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/sqlite') 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'); } } -- cgit v1.2.3-24-g4f1b