Exemplo n.º 1
0
 /**
  * @param $matches
  * @return mixed
  */
 private function transformCallback($matches)
 {
     $replacement = $matches[0];
     if (!empty($matches[1])) {
         $tmpPreparedValues = $this->preparedValues;
         $tmpNumberPlaceholder = $this->numberPlaceholder;
         $tmpIsHookSkipValue = $this->isHookSkipValue;
         $replacement = preg_replace_callback($this->getRegexpMain(), [$this, 'transformCallback'], $matches[1]);
         if ($this->isHookSkipValue) {
             $this->isHookSkipValue = $tmpIsHookSkipValue;
             $this->numberPlaceholder = $tmpNumberPlaceholder;
             $this->preparedValues = $tmpPreparedValues;
             return '';
         }
         return $replacement;
     }
     if (!empty($matches[2])) {
         $this->numberPlaceholder++;
         $placeholder = $this->placeholders->getPlaceholder($matches[0]);
         if (count($this->values) == 0) {
             return 'ERROR_NO_VALUE';
         }
         $value = array_shift($this->values);
         if ($value === Database::SKIP_VALUE) {
             $this->isHookSkipValue = true;
         }
         if ($this->isForceExpandValues) {
             $replacement = $placeholder->transformPlaceholder($value);
         } else {
             $replacement = $placeholder->transformPlaceholder($value, $this->adapter->getNativeCommonPlaceholder($this->numberPlaceholder));
             $preparedValue = $placeholder->transformValue($value);
             if ($preparedValue !== Database::SKIP_VALUE) {
                 if (is_array($preparedValue)) {
                     $this->preparedValues = array_merge($this->preparedValues, $preparedValue);
                 } else {
                     $this->preparedValues = array_merge($this->preparedValues, [$preparedValue]);
                 }
             }
         }
     }
     return $replacement;
 }
Exemplo n.º 2
0
 /**
  * @param Query $query
  * @return array
  */
 private function getPreparedErrorMessage(Query $query)
 {
     $error = $this->adapter->getLastError();
     if ($error == false) {
         return false;
     }
     $trace = debug_backtrace();
     $entryPoint = [];
     $entryPoint['file'] = '';
     $entryPoint['line'] = '';
     foreach ($trace as $item) {
         if (empty($item['file'])) {
             continue;
         }
         if (preg_match('~^' . __DIR__ . '~', $item['file'])) {
             continue;
         }
         $entryPoint = $item;
         break;
     }
     return ['message' => sprintf('%s at %s line %s', $error->getMessage(), $entryPoint['file'], $entryPoint['line']), 'info' => ['code' => $error->getCode(), 'message' => $error->getMessage(), 'query' => $this->transformQuery($query, true)->getQueryAsText(), 'context' => sprintf('%s line %s', $entryPoint['file'], $entryPoint['line'])]];
 }