summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/pdo/pdo_driver.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-03-20 14:34:17 +0100
committerAndrey Andreev <narf@bofh.bg>2012-03-20 14:34:17 +0100
commit407219ddff7e11516c7f295ee3e07c31ba3fe9ee (patch)
tree55f910d2f6d57f6436f28b7ce06666d77f41d6bc /system/database/drivers/pdo/pdo_driver.php
parent99f31cd1a487d209fd9632b40baf12406bd897c1 (diff)
parent820999cb0d82c80d6dc5dde133568812c8113e29 (diff)
Merge branch 'develop' of github.com:EllisLab/CodeIgniter into develop-zip
Diffstat (limited to 'system/database/drivers/pdo/pdo_driver.php')
-rw-r--r--system/database/drivers/pdo/pdo_driver.php122
1 files changed, 57 insertions, 65 deletions
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index de2b0abeb..658a3d5a0 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -59,8 +59,7 @@ class CI_DB_pdo_driver extends CI_DB {
var $_count_string = "SELECT COUNT(*) AS ";
var $_random_keyword;
- // need to track the pdo DSN, driver and options
- var $dsn;
+ // need to track the pdo driver and options
var $pdodriver;
var $options = array();
@@ -289,29 +288,15 @@ class CI_DB_pdo_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Set client character set
+ * Database version number
*
- * @access public
- * @param string
- * @param string
- * @return resource
- */
- function db_set_charset($charset, $collation)
- {
- return TRUE;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Version number query string
- *
- * @access public
* @return string
*/
- function _version()
+ public function version()
{
- return $this->conn_id->getAttribute(PDO::ATTR_CLIENT_VERSION);
+ return isset($this->data_cache['version'])
+ ? $this->data_cache['version']
+ : $this->data_cache['version'] = $this->conn_id->getAttribute(PDO::ATTR_SERVER_VERSION);
}
// --------------------------------------------------------------------
@@ -510,33 +495,19 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Insert ID
- *
- * @access public
- * @return integer
+ *
+ * @return int
*/
- function insert_id($name=NULL)
+ public function insert_id($name = NULL)
{
- if ($this->pdodriver == 'pgsql')
- {
- //Convenience method for postgres insertid
- $v = $this->_version();
-
- $table = func_num_args() > 0 ? func_get_arg(0) : NULL;
-
- if ($table == NULL && $v >= '8.1')
- {
- $sql='SELECT LASTVAL() as ins_id';
- }
-
- $query = $this->query($sql);
- $row = $query->row();
-
- return $row->ins_id;
- }
- else
+ if ($this->pdodriver === 'pgsql' && $name === NULL && $this->version() >= '8.1')
{
- return $this->conn_id->lastInsertId($name);
+ $query = $this->query('SELECT LASTVAL() AS ins_id');
+ $query = $query->row();
+ return $query->ins_id;
}
+
+ return $this->conn_id->lastInsertId($name);
}
// --------------------------------------------------------------------
@@ -558,8 +529,7 @@ class CI_DB_pdo_driver extends CI_DB {
return 0;
}
- $sql = $this->_count_string.$this->_protect_identifiers('numrows').' FROM ';
- $sql .= $this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ $sql = $this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
$query = $this->query($sql);
if ($query->num_rows() == 0)
@@ -591,6 +561,11 @@ class CI_DB_pdo_driver extends CI_DB {
// Analog function to show all tables in postgre
$sql = "SELECT * FROM information_schema.tables WHERE table_schema = 'public'";
}
+ elseif ($this->pdodriver == 'sqlite')
+ {
+ // Analog function to show all tables in sqlite
+ $sql = "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'";
+ }
else
{
$sql = "SHOW TABLES FROM `".$this->database."`";
@@ -633,35 +608,52 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _field_data($table)
{
+ if ($this->pdodriver == 'mysql' or $this->pdodriver == 'pgsql')
+ {
+ // Analog function for mysql and postgre
+ return 'SELECT * FROM '.$this->_from_tables($table).' LIMIT 1';
+ }
+ elseif ($this->pdodriver == 'oci')
+ {
+ // Analog function for oci
+ return 'SELECT * FROM '.$this->_from_tables($table).' WHERE ROWNUM <= 1';
+ }
+ elseif ($this->pdodriver == 'sqlite')
+ {
+ // Analog function for sqlite
+ return 'PRAGMA table_info('.$this->_from_tables($table).')';
+ }
+
return 'SELECT TOP 1 FROM '.$this->_from_tables($table);
}
// --------------------------------------------------------------------
/**
- * The error message string
+ * Error
*
- * @access private
- * @return string
+ * Returns an array containing code and message of the last
+ * database error that has occured.
+ *
+ * @return array
*/
- function _error_message()
+ public function error()
{
- $error_array = $this->conn_id->errorInfo();
+ $error = array('code' => '00000', 'message' => '');
+ $pdo_error = $this->conn_id->errorInfo();
- return $error_array[2];
- }
+ if (empty($pdo_error[0]))
+ {
+ return $error;
+ }
- // --------------------------------------------------------------------
+ $error['code'] = isset($pdo_error[1]) ? $pdo_error[0].'/'.$pdo_error[1] : $pdo_error[0];
+ if (isset($pdo_error[2]))
+ {
+ $error['message'] = $pdo_error[2];
+ }
- /**
- * The error message number
- *
- * @access private
- * @return integer
- */
- function _error_number()
- {
- return $this->conn_id->errorCode();
+ return $error;
}
// --------------------------------------------------------------------
@@ -950,4 +942,4 @@ class CI_DB_pdo_driver extends CI_DB {
}
/* End of file pdo_driver.php */
-/* Location: ./system/database/drivers/pdo/pdo_driver.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/pdo/pdo_driver.php */