summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.markdown2
-rw-r--r--idiorm.php2
-rw-r--r--test/test_queries.php4
3 files changed, 6 insertions, 2 deletions
diff --git a/README.markdown b/README.markdown
index 461a41a..c520e0b 100644
--- a/README.markdown
+++ b/README.markdown
@@ -143,7 +143,7 @@ Both methods accept two arguments. The first is the column name to compare again
##### Raw WHERE clauses #####
-If you require a more complex query, you can use the `where_raw` method to specify the SQL fragment for the WHERE clause exactly. This method takes two arguments: the string to add to the query, and an array of parameters which will be bound to the string. The string should contain question marks to represent the values to be bound, and the parameter array should contain the values to be substituted into the string in the correct order.
+If you require a more complex query, you can use the `where_raw` method to specify the SQL fragment for the WHERE clause exactly. This method takes two arguments: the string to add to the query, and an (optional) array of parameters which will be bound to the string. If parameters are supplied, the string should contain question mark characters (`?`) to represent the values to be bound, and the parameter array should contain the values to be substituted into the string in the correct order.
This method may be used in a method chain alongside other `where_*` methods as well as methods such as `offset`, `limit` and `order_by_*`. The contents of the string you supply will be connected with preceding and following WHERE clauses with AND.
diff --git a/idiorm.php b/idiorm.php
index 4f02ca4..1fbd54c 100644
--- a/idiorm.php
+++ b/idiorm.php
@@ -661,7 +661,7 @@
* contain question mark placeholders, which will be bound
* to the parameters supplied in the second argument.
*/
- public function where_raw($clause, $parameters) {
+ public function where_raw($clause, $parameters=array()) {
return $this->_add_where($clause, $parameters);
}
diff --git a/test/test_queries.php b/test/test_queries.php
index c02e3d1..879a086 100644
--- a/test/test_queries.php
+++ b/test/test_queries.php
@@ -100,6 +100,10 @@
$expected = "SELECT * FROM `widget` WHERE `name` = 'Fred' AND (`age` = '5' OR `age` = '10')";
Tester::check_equal("Raw WHERE clause", $expected);
+ ORM::for_table('widget')->where_raw('`name` = "Fred"')->find_many();
+ $expected = "SELECT * FROM `widget` WHERE `name` = \"Fred\"";
+ Tester::check_equal("Raw WHERE clause with no parameters", $expected);
+
ORM::for_table('widget')->where('age', 18)->where_raw('(`name` = ? OR `name` = ?)', array('Fred', 'Bob'))->where('size', 'large')->find_many();
$expected = "SELECT * FROM `widget` WHERE `age` = '18' AND (`name` = 'Fred' OR `name` = 'Bob') AND `size` = 'large'";
Tester::check_equal("Raw WHERE clause in method chain", $expected);