-
Notifications
You must be signed in to change notification settings - Fork 1
Fixes for insertid issues with postgresql driver #2
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
Changes from all commits
fbe7606
31f0952
2a94a01
9881248
bd747b5
a97e2ff
559c69e
8d6e9e1
a4aa9f7
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 |
|---|---|---|
|
|
@@ -1703,7 +1703,7 @@ CREATE TABLE "#__menu" ( | |
| "img" character varying(255) DEFAULT '' NOT NULL, | ||
| "template_style_id" integer DEFAULT 0 NOT NULL, | ||
| -- JSON encoded data for the menu item. | ||
| "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. +1 |
||
| -- Nested set lft. | ||
| "lft" bigint DEFAULT 0 NOT NULL, | ||
| -- Nested set rgt. | ||
|
|
@@ -2385,4 +2385,4 @@ BEGIN | |
|
|
||
| RETURN soundex; | ||
| END; | ||
| $$; | ||
| $$; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -233,7 +233,7 @@ public function getCollation() | |
| */ | ||
| public function getNumRows( $cur = null ) | ||
| { | ||
| return pg_num_rows($cur ? $cur : $this->cursor); | ||
| return pg_num_rows((int)$cur ? $cur : $this->cursor); | ||
|
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'm reading pg_num_rows doc, it accepts only resources so casting null to integer doesn't seem to be a resource. 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. $cur parameter comes with boolean value (false) and is causing php to issue warnings... What about this: 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 think the error is $cur value set to false, it has to be a resource link . 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 think so, but to fix this I will need to revisit all getNumRows calls and this is out of my possibilities, now. |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -450,10 +450,6 @@ public function insertObject($table, &$object, $key = null) | |
| $fields = array(); | ||
| $values = array(); | ||
|
|
||
| // Create the base insert statement. | ||
| $query = $this->getQuery(true); | ||
| $query->insert($this->quoteName($table)); | ||
|
|
||
| // Iterate over the object variables to build the query fields and values. | ||
| foreach (get_object_vars($object) as $k => $v) | ||
| { | ||
|
|
@@ -474,24 +470,35 @@ public function insertObject($table, &$object, $key = null) | |
| $values[] = is_numeric($v) ? $v : $this->quote($v); | ||
| } | ||
|
|
||
| $query->columns($fields); | ||
| $query->values(implode(',', $values)); | ||
| // Create the base insert statement. | ||
| $query = $this->getQuery(true); | ||
|
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. Interesting change, could be better implemented without same code replication, maybe doing what you've proposed for database.php 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. The real effort of this block is replacement of "insertid" with "returning" JDatabasePostgresqlQuery element. Ps |
||
|
|
||
| $query->insert($this->quoteName($table)) | ||
| ->columns($fields) | ||
| ->values(implode(',', $values)); | ||
|
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. These changes are what I wanted to do after merging this pull, thank you. |
||
|
|
||
| if ($key) | ||
| { | ||
| $query->returning($key); | ||
| } | ||
|
|
||
| // Set the query and execute the insert. | ||
| $this->setQuery($query); | ||
| if (!$this->query()) | ||
|
|
||
| if ($key) | ||
| { | ||
| $id = $this->loadResult(); | ||
| if ($id) | ||
| { | ||
| $object->$key = $id; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| // Update the primary key if it exists. | ||
| $id = $this->insertid(); | ||
| if ($key && $id) | ||
| } | ||
| else | ||
| { | ||
| $object->$key = $id; | ||
| return $this->query(); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -541,11 +541,11 @@ public function install() | |
| return false; | ||
| } | ||
|
|
||
| $eid = $db->insertid(); | ||
| $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. Why did you do 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. Why did you do 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. To avoid pitfalls related on calling insertid after JTable::store. 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. Your intention is correct, but are they equal? Eng. Gabriele Pongelli 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. extension_id is just the primary key of the installed component, which is the same value of $row->$key. I'm just callind $key by primary key name: extension_id. The real value of extension_id is set inside JDatabase::insertObject, which is called by JTable::store, which call insertid in right context (just after setQuery). Calling insertid here again is redundant and may lead to unexpected results. 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! 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 didn't do that because there is more uses of $row->extension_id in this function. So, I decided to keep the code following the original guidelines. |
||
|
|
||
| // Clobber any possible pending updates | ||
| $update = JTable::getInstance('update'); | ||
| $uid = $update->find(array('element' => $this->get('element'), 'type' => 'component', 'client_id' => '', 'folder' => '')); | ||
| $uid = $update->find(array('element' => $this->get('element'), 'type' => 'component', 'client_id' => 1, 'folder' => '')); | ||
|
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. +1 for this and next three. |
||
|
|
||
| if ($uid) | ||
| { | ||
|
|
@@ -1021,7 +1021,7 @@ public function update() | |
|
|
||
| // Clobber any possible pending updates | ||
| $update = JTable::getInstance('update'); | ||
| $uid = $update->find(array('element' => $this->get('element'), 'type' => 'component', 'client_id' => '', 'folder' => '')); | ||
| $uid = $update->find(array('element' => $this->get('element'), 'type' => 'component', 'client_id' => 1, 'folder' => '')); | ||
|
|
||
| if ($uid) | ||
| { | ||
|
|
@@ -1323,7 +1323,7 @@ public function uninstall($id) | |
|
|
||
| // Clobber any possible pending updates | ||
| $update = JTable::getInstance('update'); | ||
| $uid = $update->find(array('element' => $row->element, 'type' => 'component', 'client_id' => '', 'folder' => '')); | ||
| $uid = $update->find(array('element' => $row->element, 'type' => 'component', 'client_id' => 1, 'folder' => '')); | ||
|
|
||
| if ($uid) | ||
| { | ||
|
|
@@ -1950,7 +1950,7 @@ public function discover_install() | |
|
|
||
| // Clobber any possible pending updates | ||
| $update = JTable::getInstance('update'); | ||
| $uid = $update->find(array('element' => $this->get('element'), 'type' => 'component', 'client_id' => '', 'folder' => '')); | ||
| $uid = $update->find(array('element' => $this->get('element'), 'type' => 'component', 'client_id' => 1, 'folder' => '')); | ||
|
|
||
| if ($uid) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -254,9 +254,6 @@ public function install() | |
| return false; | ||
| } | ||
|
|
||
| // Set the insert id | ||
| $row->set('extension_id', $db->insertid()); | ||
|
|
||
| // Since we have created a module item, we add it to the installation step stack | ||
| // so that if we have to rollback the changes we can undo 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. Have you removed this row (and similarly in module.php) because "extension_id" is a serial row? 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. No. The real problem is that JDatabasePostgreSQL::insertid is not working for me. I had to manage to remove all calls to insertid when using postgresql. 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 is not only your problem, and it's larger than expected, let me explain. If you read JDatabasePostgresql::insertid dockblock you'll find some useful information on how to use "insertid" call: because I need to extract information from last "INSERT INTO" JDatabasePostgresqlQuery object I MUST run "insertid" after INSERT INTO query execution. In this case, inside file.php and others under this folder, as you can see there's no JDatabaseQuery to insert row, but JTable object. I've opened some discussion under platform mailing list about JTable but till now nobody answer. 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. So, changing JDatabase::insertObject with platform's code will fix these issues because JTable::store calls JDatabase::insertObject and JDatabase::updateObject. I'll try this. 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, but the big problem is logical: why do you call "insertid" if there was an update ? there is no sense on doing this. 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. Look at JTable::store , there you can find an insertid after insertObject or updateObject , depending on which parameter has received JTable::store itself. Eng. Gabriele Pongelli. 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 saw your email on google groups and understood the problem. 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. Remember you're not using only PostgreSQL driver, so removing these "insertid" call in these files probably break compatibility with other database engine, even if they don't work with PostgreSQL too. Eng. Gabriele Pongelli. 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. Compatibility is maintained because JDatabase::insertObject sets the KEY using insertid. Therefore, those calls were redundant. 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 perfect, . |
||
| $this->parent->pushStep(array('type' => 'extension', 'extension_id' => $row->extension_id)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -284,17 +284,24 @@ public function install() | |
|
|
||
| if ($this->route == 'install') | ||
| { | ||
| //insert record in #__template_styles | ||
| $query = $db->getQuery(true); | ||
| $query->insert('#__template_styles'); | ||
| $query->set('template=' . $db->Quote($row->element)); | ||
| $query->set('client_id=' . $db->Quote($clientId)); | ||
| $query->set('home=0'); | ||
| $debug = $lang->setDebug(false); | ||
| $query->set('title=' . $db->Quote(JText::sprintf('JLIB_INSTALLER_DEFAULT_STYLE', JText::_($this->get('name'))))); | ||
|
|
||
| $columns = array('template', 'client_id', 'home', 'title', 'params'); | ||
| $values = array( | ||
| $db->Quote($row->element), $clientId, $db->Quote(0), | ||
| $db->Quote(JText::sprintf('JLIB_INSTALLER_DEFAULT_STYLE', JText::_($this->get('name')))), | ||
| $db->Quote($row->params) ); | ||
|
|
||
| $lang->setDebug($debug); | ||
| $query->set('params=' . $db->Quote($row->params)); | ||
|
|
||
| //insert record in #__template_styles | ||
| $query = $db->getQuery(true); | ||
| $query->insert($db->quoteName('#__template_styles')) | ||
|
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. Seems correct, but you've lost two "setDebug" . 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. Is those really necessary? 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 don't know, they were there so I've maintained them. 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. I'll back them. |
||
| ->columns($columns) | ||
| ->values(implode(',', $values)); | ||
|
|
||
| $db->setQuery($query); | ||
|
|
||
| // There is a chance this could fail but we don't care... | ||
| $db->query(); | ||
| } | ||
|
|
@@ -359,7 +366,7 @@ public function uninstall($id) | |
|
|
||
| // Deny remove default template | ||
| $db = $this->parent->getDbo(); | ||
| $query = 'SELECT COUNT(*) FROM #__template_styles' . ' WHERE home = 1 AND template = ' . $db->Quote($name); | ||
| $query = "SELECT COUNT(*) FROM #__template_styles WHERE home = '1' AND template = " . $db->Quote($name); | ||
|
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. +1 |
||
| $db->setQuery($query); | ||
|
|
||
| if ($db->loadResult() != 0) | ||
|
|
@@ -412,13 +419,17 @@ public function uninstall($id) | |
| } | ||
|
|
||
| // Set menu that assigned to the template back to default template | ||
| $query = 'UPDATE #__menu INNER JOIN #__template_styles' . ' ON #__template_styles.id = #__menu.template_style_id' | ||
| . ' SET #__menu.template_style_id = 0' . ' WHERE #__template_styles.template = ' . $db->Quote(strtolower($name)) | ||
| . ' AND #__template_styles.client_id = ' . $db->Quote($clientId); | ||
|
|
||
| $query = 'UPDATE #__menu' | ||
| . ' SET template_style_id = 0' | ||
| . ' WHERE template_style_id in (' | ||
| . ' SELECT s.id FROM #__template_styles s' | ||
| . ' WHERE s.template = '. $db->Quote(strtolower($name)) .' AND s.client_id = '. $clientId .')'; | ||
|
|
||
|
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. +1 |
||
| $db->setQuery($query); | ||
| $db->Query(); | ||
|
|
||
| $query = 'DELETE FROM #__template_styles' . ' WHERE template = ' . $db->Quote($name) . ' AND client_id = ' . $db->Quote($clientId); | ||
| $query = 'DELETE FROM #__template_styles WHERE template = ' . $db->Quote($name) . ' AND client_id = ' . $clientId; | ||
|
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. +1 |
||
| $db->setQuery($query); | ||
| $db->Query(); | ||
|
|
||
|
|
||
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.
+1