diff options
author | Esen Sagynov <kadishmal@gmail.com> | 2011-08-11 09:41:16 +0200 |
---|---|---|
committer | Esen Sagynov <kadishmal@gmail.com> | 2011-08-11 09:41:16 +0200 |
commit | 2ab2b1e3201a1eca2954ca463df744d5cd2e46cd (patch) | |
tree | 1b0ee555b8e61b7278273f62a27ca3d316abe06c /system/database/drivers | |
parent | ee3e594893d28ca6370d24d2a4406c1897959175 (diff) |
Added back /application/* files (removed in previous commit accidently). Corrected formatting/indenting in CUBRID Driver classes. Added myself as the driver author. Applied the MySQL fix, previously accepted in pull request #29, to CUBRID Driver.
Diffstat (limited to 'system/database/drivers')
-rw-r--r-- | system/database/drivers/cubrid/cubrid_driver.php | 98 | ||||
-rw-r--r-- | system/database/drivers/cubrid/cubrid_forge.php | 20 | ||||
-rw-r--r-- | system/database/drivers/cubrid/cubrid_result.php | 15 | ||||
-rw-r--r-- | system/database/drivers/cubrid/cubrid_utility.php | 7 |
4 files changed, 81 insertions, 59 deletions
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index 9b5d86aa6..3f0109249 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -1,4 +1,4 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * @@ -25,15 +25,15 @@ * @package CodeIgniter * @subpackage Drivers * @category Database - * @author ExpressionEngine Dev Team + * @author Esen Sagynov * @link http://codeigniter.com/user_guide/database/ */ -class CI_DB_cubrid_driver extends CI_DB -{ - // Default CUBRID Broker port. Will be used unless user - // explicitly specifies another one. - const DEFAULT_PORT = 33000; - +class CI_DB_cubrid_driver extends CI_DB { + + // Default CUBRID Broker port. Will be used unless user + // explicitly specifies another one. + const DEFAULT_PORT = 33000; + var $dbdriver = 'cubrid'; // The character used for escaping - no need in CUBRID @@ -59,24 +59,30 @@ class CI_DB_cubrid_driver extends CI_DB */ function db_connect() { + // If no port is defined by the user, use the default value if ($this->port == '') { $this->port = self::DEFAULT_PORT; - } - - $conn = cubrid_connect($this->hostname, $this->port, $this->database, $this->username, $this->password); - - if ($conn){ - if (isset($this->auto_commit) && !$this->auto_commit){ - cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_FALSE); - } - else{ - cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_TRUE); - $this->auto_commit = TRUE; - } - } - - return $conn; + } + + $conn = cubrid_connect($this->hostname, $this->port, $this->database, $this->username, $this->password); + + if ($conn) + { + // Check if a user wants to run queries in dry, i.e. run the + // queries but not commit them. + if (isset($this->auto_commit) && ! $this->auto_commit) + { + cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_FALSE); + } + else + { + cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_TRUE); + $this->auto_commit = TRUE; + } + } + + return $conn; } // -------------------------------------------------------------------- @@ -131,8 +137,7 @@ class CI_DB_cubrid_driver extends CI_DB // In CUBRID there is no need to select a database as the database // is chosen at the connection time. // So, to determine if the database is "selected", all we have to - // do is return the connection identifier which can be later - // checked if it has been established or not. + // do is ping the server and return that value. return cubrid_ping($this->conn_id); } @@ -155,7 +160,7 @@ class CI_DB_cubrid_driver extends CI_DB } // -------------------------------------------------------------------- - + /** * Version number query string * @@ -164,6 +169,11 @@ class CI_DB_cubrid_driver extends CI_DB */ function _version() { + // To obtain the CUBRID Server version, no need to run the SQL query. + // CUBRID PHP API provides a function to determin this value. + // This is why we also need to add 'cubrid' value to the list of + // $driver_version_exceptions array in DB_driver class in + // version() function. return cubrid_get_server_info($this->conn_id); } @@ -195,6 +205,7 @@ class CI_DB_cubrid_driver extends CI_DB */ function _prep_query($sql) { + // No need to prepare return $sql; } @@ -224,8 +235,10 @@ class CI_DB_cubrid_driver extends CI_DB // even if the queries produce a successful result. $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - if (cubrid_get_autocommit($this->conn_id)) - cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_FALSE); + if (cubrid_get_autocommit($this->conn_id)) + { + cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_FALSE); + } return TRUE; } @@ -253,9 +266,11 @@ class CI_DB_cubrid_driver extends CI_DB cubrid_commit($this->conn_id); - if ($this->auto_commit && !cubrid_get_autocommit($this->conn_id)) - cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE); - + if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id)) + { + cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE); + } + return TRUE; } @@ -282,9 +297,11 @@ class CI_DB_cubrid_driver extends CI_DB cubrid_rollback($this->conn_id); - if ($this->auto_commit && !cubrid_get_autocommit($this->conn_id)) - cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE); - + if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id)) + { + cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE); + } + return TRUE; } @@ -303,12 +320,12 @@ class CI_DB_cubrid_driver extends CI_DB if (is_array($str)) { foreach ($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } + } - return $str; - } + return $str; + } if (function_exists('cubrid_real_escape_string') AND is_resource($this->conn_id)) { @@ -322,7 +339,6 @@ class CI_DB_cubrid_driver extends CI_DB // escape LIKE condition wildcards if ($like === TRUE) { - //TODO: check this $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str); } @@ -545,7 +561,7 @@ class CI_DB_cubrid_driver extends CI_DB */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$table." (\"".implode('\", \"', $keys)."\") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$table." (\"".implode('", "', $keys)."\") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -648,7 +664,7 @@ class CI_DB_cubrid_driver extends CI_DB { if ($field != $index) { - $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; + $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; } } } diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php index 1de0db108..bab03f748 100644 --- a/system/database/drivers/cubrid/cubrid_forge.php +++ b/system/database/drivers/cubrid/cubrid_forge.php @@ -1,4 +1,4 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * @@ -19,7 +19,7 @@ * CUBRID Forge Class * * @category Database - * @author ExpressionEngine Dev Team + * @author Esen Sagynov * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_cubrid_forge extends CI_DB_forge { @@ -81,7 +81,7 @@ class CI_DB_cubrid_forge extends CI_DB_forge { { $attributes = array_change_key_case($attributes, CASE_UPPER); - $sql .= "\n\t\"".$this->db->_protect_identifiers($field) . "\""; + $sql .= "\n\t\"" . $this->db->_protect_identifiers($field) . "\""; if (array_key_exists('NAME', $attributes)) { @@ -90,7 +90,7 @@ class CI_DB_cubrid_forge extends CI_DB_forge { if (array_key_exists('TYPE', $attributes)) { - $sql .= ' '.$attributes['TYPE']; + $sql .= ' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { @@ -125,17 +125,21 @@ class CI_DB_cubrid_forge extends CI_DB_forge { $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; } - if (array_key_exists('NULL', $attributes)) + if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) { - $sql .= ($attributes['NULL'] === TRUE) ? '' : ' NOT NULL'; + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; } if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) { $sql .= ' AUTO_INCREMENT'; } - - if (array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE) + + if (array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE) { $sql .= ' UNIQUE'; } diff --git a/system/database/drivers/cubrid/cubrid_result.php b/system/database/drivers/cubrid/cubrid_result.php index 06613e356..6f0c2b5f7 100644 --- a/system/database/drivers/cubrid/cubrid_result.php +++ b/system/database/drivers/cubrid/cubrid_result.php @@ -1,4 +1,4 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * @@ -21,7 +21,7 @@ * This class extends the parent result class: CI_DB_result * * @category Database - * @author ExpressionEngine Dev Team + * @author Esen Sagynov * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_cubrid_result extends CI_DB_result { @@ -113,7 +113,8 @@ class CI_DB_cubrid_result extends CI_DB_result { $row = cubrid_fetch_array($res, CUBRID_NUM); $F->primary_key = ($row[0] > 0 ? 1 : null); } - else{ + else + { $F->primary_key = null; } @@ -138,9 +139,9 @@ class CI_DB_cubrid_result extends CI_DB_result { */ function free_result() { - if(is_resource($this->result_id) || - get_resource_type($this->result_id) == "Unknown" && - preg_match('/Resource id #/', strval($this->result_id))) + if(is_resource($this->result_id) || + get_resource_type($this->result_id) == "Unknown" && + preg_match('/Resource id #/', strval($this->result_id))) { cubrid_close_request($this->result_id); $this->result_id = FALSE; @@ -152,7 +153,7 @@ class CI_DB_cubrid_result extends CI_DB_result { /** * Data Seek * - * Moves the internal pointer to the desired offset. We call + * Moves the internal pointer to the desired offset. We call * this internally before fetching results to make sure the * result set starts at zero * diff --git a/system/database/drivers/cubrid/cubrid_utility.php b/system/database/drivers/cubrid/cubrid_utility.php index 9cf8b2ea4..cd16d1e18 100644 --- a/system/database/drivers/cubrid/cubrid_utility.php +++ b/system/database/drivers/cubrid/cubrid_utility.php @@ -1,4 +1,4 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * @@ -19,7 +19,7 @@ * CUBRID Utility Class * * @category Database - * @author ExpressionEngine Dev Team + * @author Esen Sagynov * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_cubrid_utility extends CI_DB_utility { @@ -41,7 +41,8 @@ class CI_DB_cubrid_utility extends CI_DB_utility { { return "SELECT '" . $this->database . "'"; } - else{ + else + { return FALSE; } } |