Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add JOIN support to JDatabaseQuery UPDATE query #547

Merged
merged 1 commit into from

3 participants

@mbabker
Owner

JDatabaseQuery::__toString() currently does not handle JOIN statements in the UPDATE case. This causes UPDATE queries that are joined to another table to fail due to the table not being joined. Added support for this as well as a unit test testing the toString update case.

@joomla-jenkins
Collaborator

Unit testing complete. There were 0 failures and 0 errors from 1736 tests and 10783 assertions.
Checkstyle analysis reported 235 warnings and 0 errors.

@eddieajau

Good one. I didn't know you could do that. Thanks!

@eddieajau eddieajau merged commit 94b0903 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 22, 2011
  1. @mbabker
This page is out of date. Refresh to see the latest.
View
10 libraries/joomla/database/databasequery.php
@@ -349,6 +349,16 @@ public function __toString()
case 'update':
$query .= (string) $this->update;
+
+ if ($this->join)
+ {
+ // special case for joins
+ foreach ($this->join as $join)
+ {
+ $query .= (string) $join;
+ }
+ }
+
$query .= (string) $this->set;
if ($this->where)
View
28 tests/suite/joomla/database/JDatabaseQueryTest.php
@@ -158,6 +158,34 @@ public function test__toStringSelect()
}
/**
+ * Test for the JDatabaseQuery::__string method for a 'update' case.
+ *
+ * @return void
+ *
+ * @since 11.3
+ */
+ public function test__toStringUpdate()
+ {
+ $q = new JDatabaseQueryInspector($this->dbo);
+
+ $q->update('#__foo AS a')
+ ->join('INNER', 'b ON b.id = a.id')
+ ->set('a.id = 2')
+ ->where('b.id = 1');
+
+ $this->assertThat(
+ (string) $q,
+ $this->equalTo(
+ "\nUPDATE #__foo AS a" .
+ "\nINNER JOIN b ON b.id = a.id" .
+ "\nSET a.id = 2" .
+ "\nWHERE b.id = 1"
+ ),
+ 'Tests for correct rendering.'
+ );
+ }
+
+ /**
* Test for the castAsChar method.
*
* @return void
Something went wrong with that request. Please try again.