Permalink
Browse files

Making DboSource::order() accept an expression object. Fixes issues with

sql parsing over quoting special SQL syntax. Tests added.  Fixes #747

Signed-off-by: mark_story <mark@mark-story.com>
  • Loading branch information...
1 parent 2d44929 commit 64adfacd3ec9ef11c9c29218e972059bdb6be9f7 @mradosta mradosta committed with markstory May 19, 2010
@@ -2411,6 +2411,9 @@ function order($keys, $direction = 'ASC', $model = null) {
}
}
continue;
+ } elseif (is_object($key) && isset($key->type) && $key->type === 'expression') {
+ $result[] = $key->value;
+ continue;
}
if (preg_match('/\\x20(ASC|DESC).*/i', $key, $_dir)) {
@@ -2966,6 +2966,19 @@ function testFieldsWithExpression() {
);
$this->assertEqual($result, $expected);
}
+
+/**
+ * test that order() will accept objects made from DboSource::expression
+ *
+ * @return void
+ */
+ function testOrderWithExpression() {
+ $expression = $this->testDb->expression("CASE Sample.id WHEN 1 THEN 'Id One' ELSE 'Other Id' END AS case_col");
+ $result = $this->testDb->order($expression);
+ $expected = " ORDER BY CASE Sample.id WHEN 1 THEN 'Id One' ELSE 'Other Id' END AS case_col";
+ $this->assertEqual($result, $expected);
+ }
+
/**
* testMergeAssociations method
*

0 comments on commit 64adfac

Please sign in to comment.