QueryException.php 5.4 KB

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