diff options
author | Jamie Matthews <[email protected]> | 2010-11-03 22:54:01 +0000 |
---|---|---|
committer | Jamie Matthews <[email protected]> | 2010-11-03 22:54:01 +0000 |
commit | da6d31366f809720d0cd411ddc02249c518ce9f5 (patch) | |
tree | cd00fc19ce5444e26555669b833cc8b78f1cbcce | |
parent | e4d6bad6924fa50b8295da971293671ec3122a51 (diff) |
Parameters to where_raw method are now optional
-rw-r--r-- | README.markdown | 2 | ||||
-rw-r--r-- | idiorm.php | 2 | ||||
-rw-r--r-- | test/test_queries.php | 4 |
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. @@ -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); |