From 21bbbb1f1fbae22c4bf982359367cea41b1ddc15 Mon Sep 17 00:00:00 2001 From: Christian Heinrich Date: Thu, 13 May 2010 00:58:17 +0200 Subject: [PATCH 1/2] Updated query builder docs --- manual/en/query-builder.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/manual/en/query-builder.txt b/manual/en/query-builder.txt index 00d499c33..9c8c95219 100644 --- a/manual/en/query-builder.txt +++ b/manual/en/query-builder.txt @@ -74,7 +74,7 @@ This method is the responsable to build every piece of DQL. It takes 3 parameter ++++ Binding parameters to your query -Doctrine supports dynamic binding of parameters to your query, similar to preparing queries. You can use both strings and numbers as placeholders, although both have a slightly different syntax. Binding parameters can simply be achieved as follows: +Doctrine supports dynamic binding of parameters to your query, similar to preparing queries. You can use both strings and numbers as placeholders, although both have a slightly different syntax. Additionally, you must make your choice: Mixing both styles is not allowed. Binding parameters can simply be achieved as follows: [php] // $qb instanceof QueryBuilder @@ -107,7 +107,7 @@ If you've got several parameters to bind to your query, you can also use setPara // $qb instanceof QueryBuilder // Query here... - $qb->setParameters(array(1 => 'value for ?1', 2 => 'value for ?2', 'whatever' => 'your value for :whatever')); + $qb->setParameters(array(1 => 'value for ?1', 2 => 'value for ?2')); Getting already bound parameters is easy - simply use the abovementioned syntax with "getParameter()" or "getParameters()": @@ -116,9 +116,9 @@ Getting already bound parameters is easy - simply use the abovementioned syntax // $qb instanceof QueryBuilder // See example above - $params = qb->getParameters(array(1, 2, 'whatever')); + $params = qb->getParameters(array(1, 2)); // Equivalent to - $param = array($qb->getParameter(1), $qb->getParameter(2), $qb->getParameter('whatever')); + $param = array($qb->getParameter(1), $qb->getParameter(2)); Note: If you try to get a parameter that was not bound yet, getParameter() simply returns NULL. From 5c79ca25aabaf574d71d6bc622c13fd6045626d2 Mon Sep 17 00:00:00 2001 From: Christian Heinrich Date: Sat, 15 May 2010 00:40:18 +0200 Subject: [PATCH 2/2] Updated formatting and fixed mistakes --- manual/en/query-builder.txt | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/manual/en/query-builder.txt b/manual/en/query-builder.txt index 9c8c95219..b07bf6d79 100644 --- a/manual/en/query-builder.txt +++ b/manual/en/query-builder.txt @@ -76,7 +76,7 @@ This method is the responsable to build every piece of DQL. It takes 3 parameter Doctrine supports dynamic binding of parameters to your query, similar to preparing queries. You can use both strings and numbers as placeholders, although both have a slightly different syntax. Additionally, you must make your choice: Mixing both styles is not allowed. Binding parameters can simply be achieved as follows: - [php] + [php] // $qb instanceof QueryBuilder // example6: how to define: "SELECT u FROM User u WHERE u.id = ? ORDER BY u.name ASC" using QueryBuilder string support @@ -84,12 +84,12 @@ Doctrine supports dynamic binding of parameters to your query, similar to prepar ->add('from', 'User u') ->add('where', 'u.id = ?1') ->add('orderBy', 'u.name ASC'); - ->setParameter(1, 100); // Sets ?1 to 100, and thus we will fetch a user with u.id = 100 + ->setParameter(1, 100); // Sets ?1 to 100, and thus we will fetch a user with u.id = 100 You are not forced to enumerate your placeholders as the alternative syntax is available: - [php] + [php] // $qb instanceof QueryBuilder // example6: how to define: "SELECT u FROM User u WHERE u.id = ? ORDER BY u.name ASC" using QueryBuilder string support @@ -97,28 +97,28 @@ You are not forced to enumerate your placeholders as the alternative syntax is a ->add('from', 'User u') ->add('where', 'u.id = :identifier') ->add('orderBy', 'u.name ASC'); - ->setParameter('identifier', 100); // Sets :identifier to 100, and thus we will fetch a user with u.id = 100 + ->setParameter('identifier', 100); // Sets :identifier to 100, and thus we will fetch a user with u.id = 100 Note that numeric placeholders start with a ? followed by a number while the named placeholders start with a : followed by a string. If you've got several parameters to bind to your query, you can also use setParameters() instead of setParameter() with the following syntax: [php] - // $qb instanceof QueryBuilder + // $qb instanceof QueryBuilder // Query here... - $qb->setParameters(array(1 => 'value for ?1', 2 => 'value for ?2')); + $qb->setParameters(array(1 => 'value for ?1', 2 => 'value for ?2')); Getting already bound parameters is easy - simply use the abovementioned syntax with "getParameter()" or "getParameters()": [php] - // $qb instanceof QueryBuilder + // $qb instanceof QueryBuilder // See example above - $params = qb->getParameters(array(1, 2)); - // Equivalent to - $param = array($qb->getParameter(1), $qb->getParameter(2)); + $params = qb->getParameters(array(1, 2)); + // Equivalent to + $param = array($qb->getParameter(1), $qb->getParameter(2)); Note: If you try to get a parameter that was not bound yet, getParameter() simply returns NULL. @@ -247,8 +247,8 @@ Here it is a complete list of supported helper methods available: public function not($restriction); // Returns Expr\Func instance // Example - $qb->expr()->in('u.id', array(1, 2, 3)) - // Make sure that you do NOT use something similar to $qb->expr()->in('value', array('stringvalue')) as this will cause Doctrine to throw an Exception. - // Instead, use $qb->expr()->in('value', array('?1')) and bind your parameter to ?1 (see section above) + // Make sure that you do NOT use something similar to $qb->expr()->in('value', array('stringvalue')) as this will cause Doctrine to throw an Exception. + // Instead, use $qb->expr()->in('value', array('?1')) and bind your parameter to ?1 (see section above) public function in($x, $y); // Returns Expr\Func instance // Example - $qb->expr()->notIn('u.id', '2')