From c6ad0237eb6957046343ca654ab1c7d26787d466 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 29 Jan 2008 18:44:54 +0000 Subject: Abstracted FROM table listing in Active Record for databases that do not support parenthetic grouping of tables to explicitly define operator precedence --- system/database/DB_active_rec.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/mysql/mysql_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/mysqli/mysqli_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/oci8/oci8_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/odbc/odbc_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/postgre/postgre_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/sqlite/sqlite_driver.php | 22 ++++++++++++++++++++++ 8 files changed, 155 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 1ad4f3d1f..37bf9ed05 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1343,7 +1343,7 @@ class CI_DB_active_record extends CI_DB_driver { if (count($this->ar_from) > 0) { $sql .= "\nFROM "; - $sql .= '(' . implode(', ', $this->ar_from) . ')'; + $sql .= $this->_from_tables($this->ar_from); } if (count($this->ar_join) > 0) diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index e0c4db75c..ad747d4ad 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -438,6 +438,28 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return implode(', ', $tables); + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 6e53537b4..f00257250 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -479,6 +479,28 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index d645cc820..b2e97f927 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -473,6 +473,28 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 99f7d57bd..ddc0fba99 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -584,6 +584,28 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 604dd778c..03c0e6a86 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -449,6 +449,28 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 96cf2dfe9..20f91650a 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -469,6 +469,28 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 9cc69bb63..38febca29 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -465,6 +465,28 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * -- cgit v1.2.3-24-g4f1b