summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-10-27 02:22:43 +0200
committerAndrey Andreev <narf@bofh.bg>2012-10-27 02:22:43 +0200
commit485a348a7a633d38f69a963e9f77e23077f75d11 (patch)
treed45c37f73b848e054ad424bfe29fbf839867b944
parentca20d8445312e49e1e974c5ed8cf04400929e615 (diff)
Add database schema configuration support (used by PostgreSQL, fix #158)
-rw-r--r--system/database/drivers/odbc/odbc_driver.php13
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php9
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php9
-rw-r--r--system/database/drivers/postgre/postgre_driver.php9
-rw-r--r--user_guide_src/source/changelog.rst3
-rw-r--r--user_guide_src/source/database/configuration.rst1
6 files changed, 33 insertions, 11 deletions
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index 063a04b98..37f7a28d3 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -50,6 +50,11 @@ class CI_DB_odbc_driver extends CI_DB {
protected $_random_keyword;
/**
+ * @var string Database schema
+ */
+ public $schema = 'public';
+
+ /**
* Constructor
*
* @param array $params
@@ -234,17 +239,17 @@ class CI_DB_odbc_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit = FALSE
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
{
- $sql = 'SHOW TABLES FROM '.$this->database;
+ $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = '".$this->schema."'";
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
{
- //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
- return FALSE; // not currently supported
+ return $sql." AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' "
+ .sprintf($this->_like_escape_str, $this->_like_escape_chr);
}
return $sql;
diff --git a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php
index 5944d55f4..3be7e3c70 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php
@@ -51,6 +51,11 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
protected $_random_keyword = ' RAND()';
/**
+ * @var string Database schema
+ */
+ public $schema = 'public';
+
+ /**
* Constructor
*
* Builds the DSN if not already set.
@@ -122,12 +127,12 @@ 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
+ * @param bool $prefix_limit = FALSE
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
{
- $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'";
+ $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = '".$this->schema."'";
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
{
diff --git a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php
index 74d56e6b8..3efc45a2d 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php
@@ -45,6 +45,11 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
protected $_random_keyword = ' RANDOM()';
/**
+ * @var string Database schema
+ */
+ public $schema = 'public';
+
+ /**
* Constructor
*
* Builds the DSN if not already set.
@@ -92,12 +97,12 @@ 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
+ * @param bool $prefix_limit = FALSE
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
{
- $sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \'public\'';
+ $sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \''.$this->schema."'";
if ($prefix_limit === TRUE && $this->dbprefix !== '')
{
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 1b9474920..91d9a2385 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -47,6 +47,11 @@ class CI_DB_postgre_driver extends CI_DB {
protected $_random_keyword = ' RANDOM()'; // database specific random keyword
/**
+ * @var string Database schema
+ */
+ public $schema = 'public';
+
+ /**
* Constructor
*
* Creates a DSN string to be used for db_connect() and db_pconnect()
@@ -393,12 +398,12 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @param bool
+ * @param bool $prefix_limit = FALSE
* @return string
*/
protected function _list_tables($prefix_limit = FALSE)
{
- $sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \'public\'';
+ $sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \''.$this->schema."'";
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
{
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 59a3a1ff3..c37345933 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -103,7 +103,8 @@ Release Date: Not Released
- Server version checking is now done via ``mysqli::$server_info`` instead of running an SQL query.
- Added persistent connections support for PHP >= 5.3.
- Added support for ``backup()`` in :doc:`Database Utilities <database/utilities>`.
- - Added *dsn* configuration setting for drivers that support DSN strings (PDO, PostgreSQL, Oracle, ODBC, CUBRID).
+ - Added **dsn** configuration setting for drivers that support DSN strings (PDO, PostgreSQL, Oracle, ODBC, CUBRID).
+ - Added **schema** configuration setting (defaults to *public*) for drivers that might need it (currently used by PostgreSQL and ODBC).
- Improved PDO database support.
- Added Interbase/Firebird database support via the *ibase* driver.
- Added an optional database name parameter to ``db_select()``.
diff --git a/user_guide_src/source/database/configuration.rst b/user_guide_src/source/database/configuration.rst
index 668496324..34cefffbd 100644
--- a/user_guide_src/source/database/configuration.rst
+++ b/user_guide_src/source/database/configuration.rst
@@ -182,6 +182,7 @@ Explanation of Values:
customizable by the end user.
**autoinit** Whether or not to automatically connect to the database when the library loads. If set to false,
the connection will take place prior to executing the first query.
+**schema** The database schema, defaults to 'public'. Used by PostgreSQL and ODBC drivers.
**encrypt** Whether or not to use an encrypted connection.
**compress** Whether or not to use client compression (MySQL only).
**stricton** TRUE/FALSE (boolean) - Whether to force "Strict Mode" connections, good for ensuring strict SQL