-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes and improvements for postgresql #3
base: postgresql_v2
Are you sure you want to change the base?
Changes from 7 commits
230d89b
6325a79
d4894e2
1905950
fdc5dbf
1ed0356
c1d57e8
3928411
7badb2c
248b8e2
4859e14
4e15195
2941517
bdd49f0
64f18d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 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, | ||
|
@@ -1842,7 +1842,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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I mentioned above. I didn't test modules installation with MySQL version. But with PostgreSQL this is absolutely necessary for modules with no parameters in XML file. May be this is a missed bug in MySQL version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there cases with these two fields having null value ? Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested this right now and defacto any module you try to install fail if params has not default to '' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, thanks! |
||
"client_id" smallint DEFAULT 0 NOT NULL, | ||
"language" character varying(7) NOT NULL, | ||
PRIMARY KEY ("id") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -1043,6 +1045,47 @@ 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. | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A comment for $columns is missing. Maybe it's better to have this member private or protected. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. I will fix this tonight. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function enables contacts and all other CMS modules with no modification from master version (mysql). This is accomplished by fixing nulls of dates and numbers for SQL statements in database driver. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, after merging this change I'll add on platform code and I'll create tests for it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect. Just a note: I've already added this method inside platform, as you can see I haven't used reference for $columns and I've to change it, I've handled boolean differently, I've added timestamp without time zone type and doing its test I've seen that numeric needs to be different, including a comma in its $field_name value, it's not handled otherwise. So some suggestion to improve this method:
Really thank you ;) ! |
||
* @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 = strlen($field_value) == 0 ? 'NULL' : $field_value; | ||
break; | ||
case 'date': | ||
if (empty($field_value)) | ||
{ | ||
$field_value = $this->getNullDate(); | ||
} | ||
default: | ||
$val = $this->quote($field_value); | ||
} | ||
return $val; | ||
} | ||
|
||
/** | ||
* Method to commit a transaction. | ||
* | ||
|
@@ -1154,6 +1197,8 @@ public function unlockTables() | |
public function updateObject($table, &$object, $key, $nulls = false) | ||
{ | ||
// Initialise variables. | ||
$columns = $this->getTableColumns($table); | ||
|
||
$fields = array(); | ||
$where = ''; | ||
|
||
|
@@ -1174,7 +1219,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; | ||
} | ||
|
||
|
@@ -1192,10 +1238,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. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -541,7 +541,7 @@ public function install() | |
return false; | ||
} | ||
|
||
$eid = $row->$key; | ||
$eid = $row->extension_id; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you retrieving errors about this change ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. A "there is not $key variable defined" error. This happen because there is no "key" variable in function body. If you look at body's function there is some other lines using $row->extension_id just like I did. So, I decided to let the function like in master branch (using $row->extension_id). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect. |
||
|
||
// Clobber any possible pending updates | ||
$update = JTable::getInstance('update'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MySQL version hasn't default value, see here, why have you added this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must verify what is the exactly error this generated. But as I can remember, PostgreSQL is not so fair like MySQL with bad SQL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this today and this is not necessary anymore. I think I changed this before last fix in postgresql driver. This is related to problems with null values. I will revert this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll wait your changes and then I'll merge.
Thanks!