Skip to content
Permalink
Browse files

Fixing code markers in docs and documentatin limit()

  • Loading branch information...
lorenzo committed Feb 9, 2013
1 parent 8d34e5a commit 7aedcacd6ddad3e84a7c920cb4e99eec867e1995
Showing with 66 additions and 44 deletions.
  1. +66 −44 lib/Cake/Model/Datasource/Database/Query.php
@@ -263,12 +263,12 @@ protected function _buildSelect($builder) {
*
* ##Examples:
*
* {{
* {{{
* $query->select(['id', 'title']); // Produces SELECT id, title
* $query->select(['author' => 'author_id']); // Appends author: SELECT id, title, author_id as author
* $query->select('id', true); // Resets the list: SELECT id
* $query->select(['total' => $countQuery]); // SELECT id, (SELECT ...) AS total
* }}
* }}}
*
* @param array|Expression|string $fields fields to be added to the list
* @param boolean $overwrite whether to reset fields with passed list or not
@@ -304,7 +304,7 @@ public function select($fields = [], $overwrite = false) {
*
* ##Examples:
*
* {{
* {{{
* // Filters products with the same name and city
* $query->select(['name', 'city'])->from('products')->distinct();
*
@@ -313,7 +313,7 @@ public function select($fields = [], $overwrite = false) {
*
* // Filter products with the same name
* $query->distinct(['name'], true);
* }}
* }}}
*
* @param array|Expression fields to be filtered on
* @param boolean $overwrite whether to reset fields with passed list or not
@@ -384,12 +384,12 @@ protected function _buildSelectPart($parts) {
*
* ##Examples:
*
* {{
* {{{
* $query->from(['p' => 'posts']); // Produces FROM posts p
* $query->from('authors'); // Appends authors: FROM posts p, authors
* $query->select(['products'], true); // Resets the list: FROM products
* $query->select(['sub' => $countQuery]); // FROM (SELECT ...) sub
* }}
* }}}
*
* @param array|Expression|string $tables tables to be added to the list
* @param boolean $overwrite whether to reset tables with passed list or not
@@ -450,18 +450,18 @@ public function _buildFromPart($parts) {
*
* A join can be fully described and aliased using the array notation:
*
* {{
* {{{
* $query->join([
* 'a' => [
* 'table' => 'authors', 'type' => 'LEFT', 'conditions' => 'a.id = b.author_id'
* ]
* ]);
* // Produces LEFT JOIN authors a ON (a.id = b.author_id)
* }}
* }}}
*
* You can even specify multiple joins in an array, including the full description:
*
* {{
* {{{
* $query->join([
* 'a' => [
* 'table' => 'authors', 'type' => 'LEFT', 'conditions' => 'a.id = b.author_id'
@@ -472,7 +472,7 @@ public function _buildFromPart($parts) {
* ]);
* // LEFT JOIN authors a ON (a.id = b.author_id)
* // INNER JOIN products p (a.owner_id = p.id)
* }}
* }}}
*
* ## Using conditions and types
*
@@ -484,7 +484,7 @@ public function _buildFromPart($parts) {
* the literal values to the correct database representation. This is achieved
* using the second parameter of this function.
*
* {{
* {{{
* $query->join(['a' => [
* 'table' => 'articles',
* 'conditions' => [
@@ -493,7 +493,7 @@ public function _buildFromPart($parts) {
* 'a.author_id = authors.id'
* ]
* ]], ['a.posted' => 'datetime', 'a.published' => 'boolean'])
* }}
* }}}
*
* ## Overwriting joins
*
@@ -502,11 +502,11 @@ public function _buildFromPart($parts) {
* calls to this function or you can replace all previously defined joins
* with another list if the third parameter for this function is set to true
*
* {{
* {{{
* $query->join(['alias' => 'table']); // joins table with as alias
* $query->join(['alias' => 'another_table']); // joins another_table with as alias
* $query->join(['something' => 'different_table'], [], true); // resets joins list
* }}
* }}}
*
* @param array|string $tables list of tables to be joined in the query
* @param array $types associative array of type names used to bind values to query
@@ -584,13 +584,13 @@ protected function _buildJoinPart($parts) {
*
* ## Conditions using operators:
*
* {{
* {{{
* $query->where([
* 'posted >=' => new DateTime('3 days ago'),
* 'title LIKE' => 'Hello W%',
* 'author_id' => 1,
* ], ['posted' => 'datetime']);
* }}
* }}}
*
* The previous example produces:
*
@@ -601,13 +601,13 @@ protected function _buildJoinPart($parts) {
*
* ## Nesting conditions with conjunctions:
*
* {{
* {{{
* $query->where([
* 'author_id !=' => 1,
* 'OR' => ['published' => true, 'posted <' => new DateTime('now')],
* 'NOT' => ['title' => 'Hello']
* ], ['published' => boolean, 'posted' => 'datetime']
* }}
* }}}
*
* The previous example produces:
*
@@ -626,10 +626,10 @@ protected function _buildJoinPart($parts) {
*
* ## Using expressions objects:
*
* {{
* {{{
* $exp = $query->newExpr()->add(['id !=' => 100, 'author_id' != 1])->type('OR');
* $query->where(['published' => true], ['published' => 'boolean'])->where($exp);
* }}
* }}}
*
* The previous example produces:
*
@@ -644,25 +644,25 @@ protected function _buildJoinPart($parts) {
* as second argument. Functions must return an expression object, that will be
* added the list of conditions for the query using th AND operator
*
* {{
* {{{
* $query
* ->where(['title !=' => 'Hello World'])
* ->where(function($exp, $query) {
* $or = $exp->or_(['id' => 1]);
$and = $exp->and_(['id >' => 2, 'id <' => 10]);
return $or->add($and);
* });
* }}
* }}}
*
* * The previous example produces:
*
* ``WHERE title != 'Hello World' AND (id = 1 OR (id > 2 AND id < 10))``
*
* ## Conditions as strings:
*
* {{
* {{{
* $query->where(['articles.author_id = authors.id', 'modified IS NULL']);
* }}
* }}}
*
* The previous example produces:
*
@@ -707,33 +707,33 @@ public function where($conditions = null, $types = [], $overwrite = false) {
*
* ##Examples:
*
* {{
* {{{
* $query->where(['title' => 'Hello World')->andWhere(['author_id' => 1]);
* }}
* }}}
*
* Will produce:
*
* ``WHERE title = 'Hello World' AND author_id = 1``
*
* {{
* {{{
* $query
* ->where(['OR' => ['published' => false, 'published is NULL']])
* ->andWhere(['author_id' => 1, 'comments_count >' => 10])
* }}
* }}}
*
* Produces:
*
* ``WHERE (published = 0 OR published IS NULL) AND author_id = 1 AND comments_count > 10``
*
* {{
* {{{
* $query
* ->where(['title' => 'Foo'])
* ->andWhere(function($exp, $query) {
* return $exp
* ->add(['author_id' => 1])
* ->or_(['author_id' => 2]);
* });
* }}
* }}}
*
* Generates the following conditions:
*
@@ -768,33 +768,33 @@ public function andWhere($conditions, $types = []) {
*
* ##Examples:
*
* {{
* {{{
* $query->where(['title' => 'Hello World')->orWhere(['title' => 'Foo']);
* }}
* }}}
*
* Will produce:
*
* ``WHERE title = 'Hello World' OR title = 'Foo'``
*
* {{
* {{{
* $query
* ->where(['OR' => ['published' => false, 'published is NULL']])
* ->orWhere(['author_id' => 1, 'comments_count >' => 10])
* }}
* }}}
*
* Produces:
*
* ``WHERE (published = 0 OR published IS NULL) OR (author_id = 1 AND comments_count > 10)``
*
* {{
* {{{
* $query
* ->where(['title' => 'Foo'])
* ->orWhere(function($exp, $query) {
* return $exp
* ->add(['author_id' => 1])
* ->or_(['author_id' => 2]);
* });
* }}
* }}}
*
* Generates the following conditions:
*
@@ -826,26 +826,26 @@ public function orWhere($conditions, $types = []) {
*
* ##Examples:
*
* {{
* {{{
* $query->order(['title' => 'DESC', 'author_id' => 'ASC']);
* }}
* }}}
*
* Produces:
*
* ``ORDER BY title DESC, author_id ASC``
*
* {{
* {{{
* $query->order(['title' => 'DESC NULLS FIRST'])->order('author_id');
* }}
* }}}
*
* Will generate:
*
* ``ORDER BY title DESC NULLS FIRST, author_id``
*
* {{
* {{{
* $expression = $query->newExpr()->add(['id % 2 = 0']);
* $query->order($expression)->order(['title' => 'ASC']);
* }}
* }}}
*
* Will become:
*
@@ -873,10 +873,10 @@ public function order($fields, $overwrite = false) {
*
* ##Examples:
*
* {{
* {{{
* $query->group(['id', 'title']); // Produces GROUP BY id, title
* $query->group('title'); // Produces GROUP BY title
* }}
* }}}
*
* @param array|Expression|string $fields fields to be added to the list
* @param boolean $overwrite whether to reset fields with passed list or not
@@ -948,12 +948,34 @@ public function orHaving($conditions, $types = []) {
return $this;
}
/**
* Sets the number of records that should be retrieved from database,
* accepts an integer or an expression object that evaluates to an integer.
* In some databases, this operation might not be supported or will require
* the query to be transformed in order to limit the result set size.
*
* ## Examples
*
* {{{
* $query->limit(10) // generates LIMIT 10
* $query->limit($query->newExpr()->add(['1 + 1'])); // LIMIT (1 + 1)
* }}}
*
* @param integer|Expression $num number of records to be returned
* @return Query
*/
public function limit($num) {
if (!is_object($num)) {
$num = (int)$num;
}
$this->_parts['limit'] = $num;
return $this;
}
public function offset($num) {
if (!is_object($num)) {
$num = (int)$num;
}
$this->_parts['offset'] = $num;
return $this;
}

0 comments on commit 7aedcac

Please sign in to comment.
You can’t perform that action at this time.