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/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 ++- 16 files changed, 32 insertions(+), 16 deletions(-) (limited to 'system/database/drivers/pdo') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 32a9e7509..5fc3f67c5 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_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/pdo/pdo_forge.php | 7 +++++++ system/database/drivers/pdo/pdo_utility.php | 6 ++---- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/pdo') 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()) -- 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/pdo/pdo_result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/pdo') 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') -- 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/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 ++++++++++++----- 13 files changed, 363 insertions(+), 189 deletions(-) (limited to 'system/database/drivers/pdo') 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) -- 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/pdo/pdo_driver.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'system/database/drivers/pdo') 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 -- 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/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 ++++++++++++ 13 files changed, 2002 insertions(+), 126 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/drivers/pdo') 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 -- 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/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 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) (limited to 'system/database/drivers/pdo') 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', '<')) { -- 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 --- .../drivers/pdo/subdrivers/pdo_dblib_driver.php | 23 ++++++++++++++++++++++ .../drivers/pdo/subdrivers/pdo_oci_driver.php | 2 +- .../drivers/pdo/subdrivers/pdo_sqlsrv_driver.php | 23 ++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) (limited to 'system/database/drivers/pdo') 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 */ -- 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/pdo/pdo_result.php | 2 +- system/database/drivers/pdo/pdo_utility.php | 2 +- system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php | 2 +- system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/pdo') 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; } } -- 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/pdo/subdrivers/pdo_mysql_forge.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/pdo') 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 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/pdo/subdrivers/pdo_cubrid_forge.php | 10 ++++++++++ system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php | 10 ++++++++++ 2 files changed, 20 insertions(+) (limited to 'system/database/drivers/pdo') 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). --- .../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 +- 11 files changed, 50 insertions(+), 12 deletions(-) (limited to 'system/database/drivers/pdo') 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 @@ -