7 * create an exception with relevant information, if a query fails
\r
11 class QueryException extends \Exception {
\r
15 * @param $objPDO - the PDO object which caused the error when executed
\r
16 * @param $arrQueryDefinition - the complete query definition
\r
18 * create an error message which contains all relevant informations
\r
19 * and print them as exception
\r
22 public function __construct(\PDOStatement $objPDO, array $arrQueryDefinition) {
\r
24 $strMessage = self::createErrorMessage($objPDO, $arrQueryDefinition);
\r
26 parent::__construct($strMessage);
\r
32 * @param $objPDO - the PDO object related with the error
\r
33 * @param $arrQueryDefinition - the complete query definition
\r
35 * @return (string) the complete exception message
\r
37 * build and return the exception message out of the given error info
\r
38 * and query definition
\r
41 private function createErrorMessage(\PDOStatement $objPDO, array $arrQueryDefinition) {
\r
43 $strMessage = self::flattenQueryErrorInfo($objPDO);
\r
44 $strMessage .= self::flattenQueryDefiniton($arrQueryDefinition);
\r
52 * @param $objPDO - PDO object to get error information from
\r
54 * @return (string) a flatten error info from the query object
\r
56 * build and return a flatten error-info
\r
57 * from the driver specific error message
\r
60 private function flattenQueryErrorInfo(\PDOStatement $objPDO) {
\r
62 $arrErrorInfo = $objPDO->errorInfo();
\r
66 if(!empty($arrErrorInfo) && !empty($arrErrorInfo[0]) && '00000' !== $arrErrorInfo[0])
\r
67 $strMessage = "\nError-Code: {$arrErrorInfo[0]}\nError-Message: {$arrErrorInfo[2]}\n";
\r
75 * @param $arrQueryDefinition - the complete query definition
\r
77 * @return (string) a text version of the query definition
\r
79 * create an text, which contains all *scalar* information
\r
80 * of the query definition. if there are non-scalar information
\r
81 * added, the will be excluded from output
\r
84 private function flattenQueryDefiniton(array $arrQueryDefinition) {
\r
86 $strMessage = "\nQuery-Definiton:\n";
\r
88 foreach($arrQueryDefinition AS $strKeyword => $strContent)
\r
89 if(is_scalar($strContent))
\r
90 $strMessage .= "$strKeyword: $strContent\n";
\r
92 return $strMessage . "\n";
\r