Permalink
Browse files

update various docs to use DB:expr() properly (refs #4617)

  • Loading branch information...
1 parent 6458ca7 commit cda8c90e872c26b633c0600685f7d4c9fe981535 @Zeelot Zeelot committed Oct 21, 2012
Showing with 3 additions and 4 deletions.
  1. +1 −2 classes/Kohana/Database.php
  2. +1 −1 guide/database/examples.md
  3. +1 −1 guide/database/results.md
@@ -485,8 +485,7 @@ public function quote($value)
*
* You can also use SQL methods within identifiers.
*
- * // The value of "column" will be quoted
- * $column = $db->quote_column('COUNT("column")');
+ * $column = $db->quote_column(DB::expr('COUNT(`column`)'));
@cbandy

cbandy Oct 21, 2012

Member

It seems like this note can just go away. This method treats Database_Expressions the same way all the other quote methods do.

*
* Objects passed to this function will be converted to strings.
* [Database_Expression] objects will be compiled.
@@ -25,7 +25,7 @@ In this example, we loop through an array of whitelisted input fields and for ea
//copy the query & execute it
$pagination_query = clone $query;
- $count = $pagination_query->select('COUNT("*") AS mycount')->execute()->get('mycount');
+ $count = $pagination_query->select(DB::expr('COUNT(*)) AS mycount')->execute()->get('mycount');
//pass the total item count to Pagination
$config = Kohana::$config->load('pagination');
@@ -70,7 +70,7 @@ To return a non-associative array, leave `$key` as NULL and just pass a `$value`
Sometime you only want a single value from a query. The `get()` method returns the value of the named column from the current row. The second parameter, `$default`, is used to supply a default value when the result is NULL.
- $total_users = DB::select(array('COUNT("username")', 'total_users'))->from('users')->execute()->get('total_users', 0);
+ $total_users = DB::select(array(DB::expr('COUNT(`username`)'), 'total_users'))->from('users')->execute()->get('total_users', 0);
### Select - `cached()`

0 comments on commit cda8c90

Please sign in to comment.