QueryException.php 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /*
  3. * $Id$
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information, see
  19. * <http://www.doctrine-project.org>.
  20. */
  21. namespace Doctrine\ORM\Query;
  22. use Doctrine\ORM\Query\AST\PathExpression;
  23. /**
  24. * Description of QueryException
  25. *
  26. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  27. * @link www.doctrine-project.org
  28. * @since 2.0
  29. * @version $Revision: 3938 $
  30. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  31. * @author Jonathan Wage <jonwage@gmail.com>
  32. * @author Roman Borschel <roman@code-factory.org>
  33. * @author Benjamin Eberlei <kontakt@beberlei.de>
  34. */
  35. class QueryException extends \Doctrine\ORM\ORMException
  36. {
  37. public static function syntaxError($message)
  38. {
  39. return new self('[Syntax Error] ' . $message);
  40. }
  41. public static function semanticalError($message)
  42. {
  43. return new self('[Semantical Error] ' . $message);
  44. }
  45. public static function invalidParameterType($expected, $received)
  46. {
  47. return new self('Invalid parameter type, ' . $received . ' given, but ' . $expected . ' expected.');
  48. }
  49. public static function invalidParameterPosition($pos)
  50. {
  51. return new self('Invalid parameter position: ' . $pos);
  52. }
  53. public static function invalidParameterNumber()
  54. {
  55. return new self("Invalid parameter number: number of bound variables does not match number of tokens");
  56. }
  57. public static function invalidParameterFormat($value)
  58. {
  59. return new self('Invalid parameter format, '.$value.' given, but :<name> or ?<num> expected.');
  60. }
  61. public static function unknownParameter($key)
  62. {
  63. return new self("Invalid parameter: token ".$key." is not defined in the query.");
  64. }
  65. public static function parameterTypeMissmatch()
  66. {
  67. return new self("DQL Query parameter and type numbers missmatch, but have to be exactly equal.");
  68. }
  69. public static function invalidPathExpression($pathExpr)
  70. {
  71. return new self(
  72. "Invalid PathExpression '" . $pathExpr->identificationVariable . "." . $pathExpr->field . "'."
  73. );
  74. }
  75. public static function invalidLiteral($literal) {
  76. return new self("Invalid literal '$literal'");
  77. }
  78. /**
  79. * @param \Doctrine\ORM\Mapping\AssociationMapping $assoc
  80. */
  81. public static function iterateWithFetchJoinCollectionNotAllowed($assoc)
  82. {
  83. return new self(
  84. "Invalid query operation: Not allowed to iterate over fetch join collections ".
  85. "in class ".$assoc['sourceEntity']." assocation ".$assoc['fieldName']
  86. );
  87. }
  88. public static function partialObjectsAreDangerous()
  89. {
  90. return new self(
  91. "Loading partial objects is dangerous. Fetch full objects or consider " .
  92. "using a different fetch mode. If you really want partial objects, " .
  93. "set the doctrine.forcePartialLoad query hint to TRUE."
  94. );
  95. }
  96. public static function overwritingJoinConditionsNotYetSupported($assoc)
  97. {
  98. return new self(
  99. "Unsupported query operation: It is not yet possible to overwrite the join ".
  100. "conditions in class ".$assoc['sourceEntityName']." assocation ".$assoc['fieldName'].". ".
  101. "Use WITH to append additional join conditions to the association."
  102. );
  103. }
  104. public static function associationPathInverseSideNotSupported()
  105. {
  106. return new self(
  107. "A single-valued association path expression to an inverse side is not supported".
  108. " in DQL queries. Use an explicit join instead."
  109. );
  110. }
  111. public static function iterateWithFetchJoinNotAllowed($assoc) {
  112. return new self(
  113. "Iterate with fetch join in class " . $assoc['sourceEntity'] .
  114. " using association " . $assoc['fieldName'] . " not allowed."
  115. );
  116. }
  117. public static function associationPathCompositeKeyNotSupported()
  118. {
  119. return new self(
  120. "A single-valued association path expression to an entity with a composite primary ".
  121. "key is not supported. Explicitly name the components of the composite primary key ".
  122. "in the query."
  123. );
  124. }
  125. public static function instanceOfUnrelatedClass($className, $rootClass)
  126. {
  127. return new self("Cannot check if a child of '" . $rootClass . "' is instanceof '" . $className . "', " .
  128. "inheritance hierachy exists between these two classes.");
  129. }
  130. }