···487487 * Executes query to specify the character set for this connection.
488488 */
489489 abstract function set_encoding($charset);
490490+491491+ /**
492492+ * Specifies whether or not adapter can use LIMIT/ORDER clauses with DELETE & UPDATE operations
493493+ *
494494+ * @internal
495495+ * @returns boolean (FALSE by default)
496496+ */
497497+ public function accepts_limit_and_order_for_update_and_delete() { return false; }
490498};
491499?>
+18
lib/php-activerecord/lib/SQLBuilder.php
···331331 if ($this->where)
332332 $sql .= " WHERE $this->where";
333333334334+ if ($this->connection->accepts_limit_and_order_for_update_and_delete())
335335+ {
336336+ if ($this->order)
337337+ $sql .= " ORDER BY $this->order";
338338+339339+ if ($this->limit)
340340+ $sql = $this->connection->limit($sql,null,$this->limit);
341341+ }
342342+334343 return $sql;
335344 }
336345···388397389398 if ($this->where)
390399 $sql .= " WHERE $this->where";
400400+401401+ if ($this->connection->accepts_limit_and_order_for_update_and_delete())
402402+ {
403403+ if ($this->order)
404404+ $sql .= " ORDER BY $this->order";
405405+406406+ if ($this->limit)
407407+ $sql = $this->connection->limit($sql,null,$this->limit);
408408+ }
391409392410 return $sql;
393411 }
···8282 {
8383 throw new ActiveRecordException("SqliteAdapter::set_charset not supported.");
8484 }
8585+8686+ public function accepts_limit_and_order_for_update_and_delete() { return true; }
8587};
8688?>
···346346 {
347347 $venues = Venue::all(array('select' => 'state', 'group' => 'state', 'having' => 'length(state) = 2', 'order' => 'state', 'limit' => 2));
348348 $this->assert_true(count($venues) > 0);
349349- $this->assert_sql_has($this->conn->limit('SELECT state FROM venues GROUP BY state HAVING length(state) = 2 ORDER BY state',0,2),Venue::table()->last_sql);
349349+ $this->assert_sql_has($this->conn->limit('SELECT state FROM venues GROUP BY state HAVING length(state) = 2 ORDER BY state',null,2),Venue::table()->last_sql);
350350 }
351351352352 public function test_escape_quotes()
+19-1
lib/php-activerecord/test/SQLBuilderTest.php
···150150 {
151151 $this->sql->update(array('id' => 1, 'name' => 'Tito'))->where('id=1 AND name IN(?)',array('Tito','Mexican'));
152152 $this->assert_sql_has("UPDATE authors SET id=?, name=? WHERE id=1 AND name IN(?,?)",(string)$this->sql);
153153- $this->assert_equals(array(1,'Tito','Tito','Mexican'),$this->sql->bind_values());
153153+ $this->assert_equals(array(1,'Tito','Tito','Mexican'),$this->sql->bind_values());
154154+ }
155155+156156+ public function test_update_with_limit_and_order()
157157+ {
158158+ if (!$this->conn->accepts_limit_and_order_for_update_and_delete())
159159+ $this->mark_test_skipped('Only MySQL & Sqlite accept limit/order with UPDATE operation');
160160+161161+ $this->sql->update(array('id' => 1))->order('name asc')->limit(1);
162162+ $this->assert_sql_has("UPDATE authors SET id=? ORDER BY name asc LIMIT 1", $this->sql->to_s());
154163 }
155164156165 public function test_update_with_string()
···183192 $this->sql->delete(array('id' => 1, 'name' => array('Tito','Mexican')));
184193 $this->assert_sql_has("DELETE FROM authors WHERE id=? AND name IN(?,?)",$this->sql->to_s());
185194 $this->assert_equals(array(1,'Tito','Mexican'),$this->sql->get_where_values());
195195+ }
196196+197197+ public function test_delete_with_limit_and_order()
198198+ {
199199+ if (!$this->conn->accepts_limit_and_order_for_update_and_delete())
200200+ $this->mark_test_skipped('Only MySQL & Sqlite accept limit/order with DELETE operation');
201201+202202+ $this->sql->delete(array('id' => 1))->order('name asc')->limit(1);
203203+ $this->assert_sql_has("DELETE FROM authors WHERE id=? ORDER BY name asc LIMIT 1",$this->sql->to_s());
186204 }
187205188206 public function test_reverse_order()