From 230d89b65e0315f230dd4c1312b7ea8fe7496ba5 Mon Sep 17 00:00:00 2001 From: Carlo Pires Date: Sun, 8 Apr 2012 19:29:19 -0300 Subject: [PATCH 01/14] Better support to boolean and numeric types to postgresql driver --- .../joomla/database/database/postgresql.php | 48 +++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/libraries/joomla/database/database/postgresql.php b/libraries/joomla/database/database/postgresql.php index 4bad397baaae9..11c32a4b96f9f 100644 --- a/libraries/joomla/database/database/postgresql.php +++ b/libraries/joomla/database/database/postgresql.php @@ -447,6 +447,8 @@ public function insertid() public function insertObject($table, &$object, $key = null) { // Initialise variables. + $columns = $this->getTableColumns($table); + $fields = array(); $values = array(); @@ -467,7 +469,7 @@ public function insertObject($table, &$object, $key = null) // Prepare and sanitize the fields and values for the database query. $fields[] = $this->quoteName($k); - $values[] = is_numeric($v) ? $v : $this->quote($v); + $values[] = $this->sqlValue($columns, $k, $v); } // Create the base insert statement. @@ -1014,6 +1016,42 @@ public function replacePrefix($sql, $prefix = '#__') return $replacedQuery; } + /** + * This function return a field value as a prepared string to be used in a SQL statement. + * + * @param string $table_fields The table fields types returned by ::getTableColumns. + * @param string $value The php variable value. + * + * @return string The quoted string. + * + * @since 11.3 + */ + public function sqlValue($columns, $field_name, $field_value) + { + switch ($columns[$field_name]) { + case 'boolean': + if ($field_value == 't') + { + $field_value = true; + } + $val = is_bool($field_value) ? ( $field_value ? 'TRUE' : 'FALSE' ) : 'NULL'; + break; + case 'bigint': + case 'bigserial': + case 'integer': + case 'money': + case 'numeric': + case 'real': + case 'smallint': + case 'serial': + $val = $field_value; + break; + default: + $val = $this->quote($field_value); + } + return $val; + } + /** * Method to commit a transaction. * @@ -1125,6 +1163,8 @@ public function unlockTables() public function updateObject($table, &$object, $key, $nulls = false) { // Initialise variables. + $columns = $this->getTableColumns($table); + $fields = array(); $where = ''; @@ -1145,7 +1185,8 @@ public function updateObject($table, &$object, $key, $nulls = false) // Set the primary key to the WHERE clause instead of a field to update. if ($k == $key) { - $where = $this->quoteName($k) . '=' . (is_numeric($v) ? $v : $this->quote($v)); + $key_val = $this->sqlValue($columns, $k, $v); + $where = $this->quoteName($k) . '=' . $key_val; continue; } @@ -1163,10 +1204,9 @@ public function updateObject($table, &$object, $key, $nulls = false) continue; } } - // The field is not null so we prep it for update. else { - $val = (is_numeric($v) ? $v : $this->quote($v)); + $val = $this->sqlValue($columns, $k, $v); } // Add the field to be updated. From 6325a793b752554fd84e7b8373fd34a9f0696758 Mon Sep 17 00:00:00 2001 From: Carlo Pires Date: Tue, 10 Apr 2012 18:38:15 -0300 Subject: [PATCH 02/14] Added support to numeric null values Added support to date null values --- libraries/joomla/database/database/postgresql.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/joomla/database/database/postgresql.php b/libraries/joomla/database/database/postgresql.php index 11c32a4b96f9f..5d1a19cabad71 100644 --- a/libraries/joomla/database/database/postgresql.php +++ b/libraries/joomla/database/database/postgresql.php @@ -1044,8 +1044,13 @@ public function sqlValue($columns, $field_name, $field_value) case 'real': case 'smallint': case 'serial': - $val = $field_value; + $val = empty($field_value) ? 'NULL' : $field_value; break; + case 'date': + if (empty($field_value)) + { + $field_value = $this->getNullDate(); + } default: $val = $this->quote($field_value); } From d4894e27c4f7ea8c878221f3c855cf6cbd00e2bb Mon Sep 17 00:00:00 2001 From: Carlo Pires Date: Tue, 10 Apr 2012 19:55:40 -0300 Subject: [PATCH 03/14] Fixed support to numeric null values in postgresql driver --- libraries/joomla/database/database/postgresql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/joomla/database/database/postgresql.php b/libraries/joomla/database/database/postgresql.php index 5d1a19cabad71..a115e00755e04 100644 --- a/libraries/joomla/database/database/postgresql.php +++ b/libraries/joomla/database/database/postgresql.php @@ -1044,7 +1044,7 @@ public function sqlValue($columns, $field_name, $field_value) case 'real': case 'smallint': case 'serial': - $val = empty($field_value) ? 'NULL' : $field_value; + $val = strlen($field_value) == 0 ? 'NULL' : $field_value; break; case 'date': if (empty($field_value)) From 19059506d72c3e457e43ba403dd31a3c45e837f7 Mon Sep 17 00:00:00 2001 From: Carlo Pires Date: Wed, 11 Apr 2012 13:16:13 -0300 Subject: [PATCH 04/14] Fixed installation sql for modules table --- installation/sql/postgresql/joomla.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation/sql/postgresql/joomla.sql b/installation/sql/postgresql/joomla.sql index cd8c4fb1bff95..97b636274b281 100644 --- a/installation/sql/postgresql/joomla.sql +++ b/installation/sql/postgresql/joomla.sql @@ -1830,7 +1830,7 @@ CREATE TABLE "#__modules" ( "id" serial NOT NULL, "title" character varying(100) DEFAULT '' NOT NULL, "note" character varying(255) DEFAULT '' NOT NULL, - "content" text NOT NULL, + "content" text DEFAULT '' NOT NULL, "ordering" bigint DEFAULT 0 NOT NULL, "position" character varying(50) DEFAULT '' NOT NULL, "checked_out" integer DEFAULT 0 NOT NULL, From fdc5dbfa6e032a87cc51437aee5d608b3205fe39 Mon Sep 17 00:00:00 2001 From: Carlo Pires Date: Mon, 16 Apr 2012 19:13:43 -0300 Subject: [PATCH 05/14] More fixes to module installation with postgresql driver --- installation/sql/postgresql/joomla.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation/sql/postgresql/joomla.sql b/installation/sql/postgresql/joomla.sql index 97b636274b281..a3267de73ca4f 100644 --- a/installation/sql/postgresql/joomla.sql +++ b/installation/sql/postgresql/joomla.sql @@ -1841,7 +1841,7 @@ CREATE TABLE "#__modules" ( "module" character varying(50) DEFAULT NULL, "access" bigint DEFAULT 0 NOT NULL, "showtitle" smallint DEFAULT 1 NOT NULL, - "params" text NOT NULL, + "params" text DEFAULT '' NOT NULL, "client_id" smallint DEFAULT 0 NOT NULL, "language" character varying(7) NOT NULL, PRIMARY KEY ("id") From 1ed03568f42faf9822a7383e36781cfefb75e58d Mon Sep 17 00:00:00 2001 From: Carlo Pires Date: Tue, 17 Apr 2012 10:26:11 -0300 Subject: [PATCH 06/14] Revert to use $row->extension_id in component adapter installer due to missing $key variable error --- libraries/joomla/installer/adapters/component.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/joomla/installer/adapters/component.php b/libraries/joomla/installer/adapters/component.php index 88c57419ee636..7d9f17121d010 100644 --- a/libraries/joomla/installer/adapters/component.php +++ b/libraries/joomla/installer/adapters/component.php @@ -541,7 +541,7 @@ public function install() return false; } - $eid = $row->$key; + $eid = $row->extension_id; // Clobber any possible pending updates $update = JTable::getInstance('update'); From 3928411d77111dc415ddb6fb41b580e320c11c97 Mon Sep 17 00:00:00 2001 From: Carlo Pires Date: Tue, 12 Jun 2012 15:03:28 -0300 Subject: [PATCH 07/14] Fixed JDatabasePostgreSQL::sqlValue and SQL script --- installation/sql/postgresql/joomla.sql | 2 +- libraries/joomla/database/database/postgresql.php | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/installation/sql/postgresql/joomla.sql b/installation/sql/postgresql/joomla.sql index a409c19cde71d..26aecf73a3430 100644 --- a/installation/sql/postgresql/joomla.sql +++ b/installation/sql/postgresql/joomla.sql @@ -1831,7 +1831,7 @@ CREATE TABLE "#__modules" ( "id" serial NOT NULL, "title" character varying(100) DEFAULT '' NOT NULL, "note" character varying(255) DEFAULT '' NOT NULL, - "content" text DEFAULT '' NOT NULL, + "content" text NOT NULL, "ordering" bigint DEFAULT 0 NOT NULL, "position" character varying(50) DEFAULT '' NOT NULL, "checked_out" integer DEFAULT 0 NOT NULL, diff --git a/libraries/joomla/database/database/postgresql.php b/libraries/joomla/database/database/postgresql.php index def1d9ad24d30..9435631d90dc1 100644 --- a/libraries/joomla/database/database/postgresql.php +++ b/libraries/joomla/database/database/postgresql.php @@ -1048,14 +1048,15 @@ public function replacePrefix($sql, $prefix = '#__') /** * This function return a field value as a prepared string to be used in a SQL statement. * - * @param string $table_fields The table fields types returned by ::getTableColumns. - * @param string $value The php variable value. + * @param string $columns The array of field columns returned by JDatabasePostgreSQL::getTableColumns. + * @param string $field_name Name of field that will receive the converted SQL value + * @param string $field_value Php variable value to be converted to SQL. * * @return string The quoted string. * * @since 11.3 */ - public function sqlValue($columns, $field_name, $field_value) + public function sqlValue(&$columns, $field_name, $field_value) { switch ($columns[$field_name]) { case 'boolean': From 7badb2c54d2707b3e2d9cfa5b8e228f62490e90e Mon Sep 17 00:00:00 2001 From: Carlo Pires Date: Wed, 13 Jun 2012 15:21:12 -0300 Subject: [PATCH 08/14] Changed behavior of JDatabasePostgreSQL::sqlValue to match platform codebase --- .../joomla/database/database/postgresql.php | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/libraries/joomla/database/database/postgresql.php b/libraries/joomla/database/database/postgresql.php index 9435631d90dc1..2545ce86a70ff 100644 --- a/libraries/joomla/database/database/postgresql.php +++ b/libraries/joomla/database/database/postgresql.php @@ -1058,32 +1058,39 @@ public function replacePrefix($sql, $prefix = '#__') */ public function sqlValue(&$columns, $field_name, $field_value) { - switch ($columns[$field_name]) { + switch ($columns[$field_name]) + { case 'boolean': + $val = 'NULL'; if ($field_value == 't') { - $field_value = true; + $val = 'TRUE'; } - $val = is_bool($field_value) ? ( $field_value ? 'TRUE' : 'FALSE' ) : 'NULL'; - break; - case 'bigint': - case 'bigserial': - case 'integer': - case 'money': - case 'numeric': - case 'real': - case 'smallint': - case 'serial': - $val = strlen($field_value) == 0 ? 'NULL' : $field_value; - break; - case 'date': - if (empty($field_value)) + elseif ($field_value == 'f') { - $field_value = $this->getNullDate(); + $val = 'FALSE'; } - default: - $val = $this->quote($field_value); + break; + case 'bigint': + case 'bigserial': + case 'integer': + case 'money': + case 'real': + case 'smallint': + case 'serial': + case 'numeric,': + $val = strlen($field_value) == 0 ? 'NULL' : $field_value; + break; + case 'date': + case 'timestamp without time zone': + if (empty($field_value)) + { + $field_value = $this->getNullDate(); + } + default: + $val = $this->quote($field_value); } + return $val; } From 248b8e20ef223fc02b9df41887cc5496ad05056b Mon Sep 17 00:00:00 2001 From: Carlo Pires Date: Thu, 14 Jun 2012 17:22:37 -0300 Subject: [PATCH 09/14] Fixed bug in JDatabasePostgreSQL::sqlValue --- .../joomla/database/database/postgresql.php | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/libraries/joomla/database/database/postgresql.php b/libraries/joomla/database/database/postgresql.php index 2545ce86a70ff..85322f2ab4da9 100644 --- a/libraries/joomla/database/database/postgresql.php +++ b/libraries/joomla/database/database/postgresql.php @@ -1070,25 +1070,29 @@ public function sqlValue(&$columns, $field_name, $field_value) { $val = 'FALSE'; } - break; - case 'bigint': - case 'bigserial': - case 'integer': - case 'money': - case 'real': - case 'smallint': - case 'serial': - case 'numeric,': - $val = strlen($field_value) == 0 ? 'NULL' : $field_value; - break; - case 'date': - case 'timestamp without time zone': - if (empty($field_value)) - { - $field_value = $this->getNullDate(); - } - default: - $val = $this->quote($field_value); + elseif (is_bool($field_value)) + { + $val = $field_value ? 'TRUE' : 'FALSE'; + } + break; + case 'bigint': + case 'bigserial': + case 'integer': + case 'money': + case 'real': + case 'smallint': + case 'serial': + case 'numeric': + $val = strlen($field_value) == 0 ? 'NULL' : $field_value; + break; + case 'date': + case 'timestamp without time zone': + if (empty($field_value)) + { + $field_value = $this->getNullDate(); + } + default: + $val = $this->quote($field_value); } return $val; From 4859e146c98089a9242e43038ec6d7214bddea78 Mon Sep 17 00:00:00 2001 From: Carlo Pires Date: Thu, 14 Jun 2012 18:45:16 -0300 Subject: [PATCH 10/14] More bug fixes in JDatabasePostgreSQL::sqlValue --- libraries/joomla/database/database/postgresql.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/joomla/database/database/postgresql.php b/libraries/joomla/database/database/postgresql.php index 85322f2ab4da9..88926503fc158 100644 --- a/libraries/joomla/database/database/postgresql.php +++ b/libraries/joomla/database/database/postgresql.php @@ -1061,7 +1061,6 @@ public function sqlValue(&$columns, $field_name, $field_value) switch ($columns[$field_name]) { case 'boolean': - $val = 'NULL'; if ($field_value == 't') { $val = 'TRUE'; @@ -1074,6 +1073,10 @@ public function sqlValue(&$columns, $field_name, $field_value) { $val = $field_value ? 'TRUE' : 'FALSE'; } + else + { + $val = 'NULL'; + } break; case 'bigint': case 'bigserial': @@ -1083,7 +1086,7 @@ public function sqlValue(&$columns, $field_name, $field_value) case 'smallint': case 'serial': case 'numeric': - $val = strlen($field_value) == 0 ? 'NULL' : $field_value; + $val = strlen($field_value) == 0 ? 'NULL' : strval($field_value); break; case 'date': case 'timestamp without time zone': From 4e15195973861f310b94907499b8e21671ee2e11 Mon Sep 17 00:00:00 2001 From: Carlo Pires Date: Thu, 14 Jun 2012 18:50:04 -0300 Subject: [PATCH 11/14] JDatabasePostgreSQL::sqlValue is now protected method --- libraries/joomla/database/database/postgresql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/joomla/database/database/postgresql.php b/libraries/joomla/database/database/postgresql.php index 88926503fc158..c79f7ab04dc2e 100644 --- a/libraries/joomla/database/database/postgresql.php +++ b/libraries/joomla/database/database/postgresql.php @@ -1056,7 +1056,7 @@ public function replacePrefix($sql, $prefix = '#__') * * @since 11.3 */ - public function sqlValue(&$columns, $field_name, $field_value) + protected function sqlValue(&$columns, $field_name, $field_value) { switch ($columns[$field_name]) { From 2941517e8aa5b824dc881072eed3482eaf38e05c Mon Sep 17 00:00:00 2001 From: Carlo Pires Date: Thu, 14 Jun 2012 19:01:25 -0300 Subject: [PATCH 12/14] Revert JDatabasePostgreSQL::sqlValue to be public. In protected mode extensions installation is broken. --- libraries/joomla/database/database/postgresql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/joomla/database/database/postgresql.php b/libraries/joomla/database/database/postgresql.php index c79f7ab04dc2e..88926503fc158 100644 --- a/libraries/joomla/database/database/postgresql.php +++ b/libraries/joomla/database/database/postgresql.php @@ -1056,7 +1056,7 @@ public function replacePrefix($sql, $prefix = '#__') * * @since 11.3 */ - protected function sqlValue(&$columns, $field_name, $field_value) + public function sqlValue(&$columns, $field_name, $field_value) { switch ($columns[$field_name]) { From bdd49f083e6012bdbfbba05433ed1d6d5e3c707e Mon Sep 17 00:00:00 2001 From: Carlo Pires Date: Thu, 14 Jun 2012 19:24:52 -0300 Subject: [PATCH 13/14] Fixed bug in languages installation. Now JDatabasePostgreSQL::sqlValue is protected again --- libraries/joomla/database/database/postgresql.php | 2 +- libraries/joomla/installer/adapters/language.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/joomla/database/database/postgresql.php b/libraries/joomla/database/database/postgresql.php index 88926503fc158..c79f7ab04dc2e 100644 --- a/libraries/joomla/database/database/postgresql.php +++ b/libraries/joomla/database/database/postgresql.php @@ -1056,7 +1056,7 @@ public function replacePrefix($sql, $prefix = '#__') * * @since 11.3 */ - public function sqlValue(&$columns, $field_name, $field_value) + protected function sqlValue(&$columns, $field_name, $field_value) { switch ($columns[$field_name]) { diff --git a/libraries/joomla/installer/adapters/language.php b/libraries/joomla/installer/adapters/language.php index adcd514c78fbf..34140ba26b786 100644 --- a/libraries/joomla/installer/adapters/language.php +++ b/libraries/joomla/installer/adapters/language.php @@ -283,7 +283,7 @@ protected function _install($cname, $basePath, $clientId, &$element) // Clobber any possible pending updates $update = JTable::getInstance('update'); - $uid = $update->find(array('element' => $this->get('tag'), 'type' => 'language', 'client_id' => '', 'folder' => '')); + $uid = $update->find(array('element' => $this->get('tag'), 'type' => 'language', 'client_id' => $clientId, 'folder' => '')); if ($uid) { $update->delete($uid); From 64f18d016c9577bf8014490e2387df12ce730eab Mon Sep 17 00:00:00 2001 From: Carlo Pires Date: Thu, 14 Jun 2012 20:01:22 -0300 Subject: [PATCH 14/14] Fixed bug in menu editing and postgresql driver --- libraries/joomla/database/table/menu.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/joomla/database/table/menu.php b/libraries/joomla/database/table/menu.php index a0c78a77b961d..304caa909887c 100644 --- a/libraries/joomla/database/table/menu.php +++ b/libraries/joomla/database/table/menu.php @@ -145,7 +145,10 @@ public function store($updateNulls = false) $db = JFactory::getDBO(); // Verify that the alias is unique $table = JTable::getInstance('Menu', 'JTable'); - if ($table->load(array('alias' => $this->alias, 'parent_id' => $this->parent_id, 'client_id' => $this->client_id, 'language' => $this->language)) + + $clientId = strlen($this->client_id) == 0 ? 0 : $this->client_id; + + if ($table->load(array('alias' => $this->alias, 'parent_id' => $this->parent_id, 'client_id' => $clientId, 'language' => $this->language)) && ($table->id != $this->id || $this->id == 0)) { if ($this->menutype == $table->menutype)