Creates a QueryException with the last message, if no last message exists then uses 'Database error'

@param string $query
@param \Throwable|null $previous
@return QueryException
174392
final public function createQueryException(string $query, \Throwable $previous = null): QueryException
    {
        return new QueryException($this->getLastMessage() ?: 'Database error', $query, 0, $previous);
    }
591557
private function setOriginalSoapExceptionContent(\Exception $previous = null)
    {
        if (is_object($previous) && $previous instanceof \SoapFault) {
            $this->originalMessage = $previous->faultstring;
            $this->originalCode = $previous->faultcode;
        }

        return $this;
    }
574658
public static function bindExecuteLastInsertId($query, $parameters = [])
    {
        try {
            return static::$adapter->bindExecuteLastInsertId($query, $parameters);
        } catch (\Exception $e) {
            throw new DatabaseException('Database Error', $e->getMessage());
        }
    }
5277
protected function executeQuery($query)
        {
            $res = @odbc_exec($this->_lnk, $query);
            if(!$res) {
                $error = odbc_errormsg($this->_lnk);
                $this->log('Query failed: '.$error);
                throw new Exception('Executing query failed ' . $error, self::QUERY_FAILED);
            }
            return $res;
        }
375121
public function process(Query $query, $rows)
    {
        $meta = [
            'hasPrevious' => false,
            'previousCursor' => null,
            'hasNext' => false,
            'nextCursor' => null,
        ];

        if ($this->shouldLtrim($query, $rows)) {
            $type = $query->direction()->forward() ? 'previous' : 'next';
            $meta['has' . ucfirst($type)] = true;
            $meta[$type . 'Cursor'] = $this->makeCursor(
                $query,
                $this->offset($rows, (int)$query->exclusive())
            );
            $rows = $this->slice($rows, 1);
        }
        if ($this->shouldRtrim($query, $rows)) {
            $type = $query->direction()->backward() ? 'previous' : 'next';
            $meta['has' . ucfirst($type)] = true;
            $meta[$type . 'Cursor'] = $this->makeCursor(
                $query,
                $this->offset($rows, $query->limit() - $query->exclusive())
            );
            $rows = $this->slice($rows, 0, $query->limit());
        }

        // If we are not using UNION ALL, boolean values are not defined.
        if (!$query->selectOrUnionAll() instanceof UnionAll) {
            $meta[$query->direction()->forward() ? 'hasPrevious' : 'hasNext'] = null;
        }

        return $this->invokeFormatter($this->shouldReverse($query) ? $this->reverse($rows) : $rows, $meta, $query);
    }
1138914
public function selectOne($query, $bindings = [])
    {
        $start = $this->getLogTime();

        try {

            $result = $this->wpdb->get_row($this->bindParams($query, $bindings));

            if ($result === false || $this->wpdb->last_error) {
                throw new QueryException($query, $bindings, new \Exception($this->wpdb->last_error));
            }

            return $result;

        } catch (QueryException $e) {
            throw $e;
        } finally {
            $this->logQuery($query, $bindings, $this->getElapsedTime($start));
        }
    }
990718
public static function query($query)
    {
        $res = self::connection()->sql_query($query);

        if (!$res || self::connection()->sql_errno()) {
            // SQL statement failed
            $errorMsg = sprintf(
                'SQL Error: %s [errno: %s]',
                self::connection()->sql_error(),
                self::connection()->sql_errno()
            );

            if (defined('TYPO3_cliMode')) {
                throw new \Exception($errorMsg);
            } else {
                debug('SQL-QUERY: ' . $query, $errorMsg, __LINE__, __FILE__);
            }

            $res = null;
        }

        return $res;
    }
228427
public function podiumNew($previous = null)
    {
        $transaction = static::getDb()->beginTransaction();
        try {
            $id = null;
            $loggedId = User::loggedId();
            $sameAuthor = !empty($previous->author_id) && $previous->author_id == $loggedId;
            if ($sameAuthor && Podium::getInstance()->podiumConfig->get('merge_posts')) {
                $separator = '<hr>';
                if (Podium::getInstance()->podiumConfig->get('use_wysiwyg') == '0') {
                    $separator = "\n\n---\n";
                }
                $previous->content .= $separator . $this->content;
                $previous->edited = 1;
                $previous->touch('edited_at');
                if (!$previous->save()) {
                    throw new Exception('Previous Post saving error!');
                }
                $previous->markSeen(false);
                $previous->thread->touch('edited_post_at');
                $id = $previous->id;
                $thread = $previous->thread;
            } else {
                if (!$this->save()) {
                    throw new Exception('Post saving error!');
                }
                $this->markSeen(!$sameAuthor);
                if (!$this->forum->updateCounters(['posts' => 1])) {
                    throw new Exception('Forum Post counter adding error!');
                }
                if (!$this->thread->updateCounters(['posts' => 1])) {
                    throw new Exception('Thread Post counter adding error!');
                }
                $this->thread->touch('new_post_at');
                $this->thread->touch('edited_post_at');
                $id = $this->id;
                $thread = $this->thread;
            }
            if (empty($id)) {
                throw new Exception('Saved Post ID missing');
            }
            Subscription::notify($thread->id);
            if ($this->subscribe && !$thread->subscription) {
                $subscription = new Subscription();
                $subscription->user_id = $loggedId;
                $subscription->thread_id = $thread->id;
                $subscription->post_seen = Subscription::POST_SEEN;
                if (!$subscription->save()) {
                    throw new Exception('Subscription saving error!');
                }
            }
            $transaction->commit();
            PodiumCache::clearAfter('newPost');
            Log::info('Post added', $id, __METHOD__);
            return true;
        } catch (Exception $e) {
            $transaction->rollBack();
            Log::error($e->getMessage(), null, __METHOD__);
        }
        return false;
    }
204002
protected function processQuery($query)
    {
        if (null === $processed = json_decode($this->adapter->getContent($query))) {
            throw new \RuntimeException(sprintf("Impossible to process this query: %s", $query));
        }

        if ('ERROR' === $processed->status) {
            // it looks that the API does still have the old error object structure.
            if (isset($processed->error_message)) {
                $errorMessage = $processed->error_message;
            }

            if (isset($processed->message)) {
                $errorMessage = $processed->message;
            }

            throw new \RuntimeException(sprintf("%s: %s", $errorMessage, $query));
        }

        return $processed;
    }
689381
protected function formatQuery(Query $query)
    {
        // handle numeric where, from 2 to ['id'=>2]
        if (!$query->formatted() && $where = $query->get('where')) {
            $table = static::getFirstTable($query['table']);
            $atable  = static::getFirstTableAlias($query['table']);
            $model  = static::getQueryModel();
            $pk     = isset($model['primary_key']) ? $model['primary_key'] : null;
            $spk    = $atable . '.' . $pk;
            foreach ($where as $k=>$v) {
                if (is_numeric($k)) {
                    if (is_numeric($v)) {
                        if (!$pk) {
                            throw new Exception('pk is not set:' . $table);
                        }
                        $where[$k] = [$spk => $v];
                    } elseif (is_array($v)) {
                        foreach ($v as $k2=>$v2) {
                            if (is_numeric($k2) && is_numeric($v2)) {
                                if (!$pk) {
                                    throw new Exception('pk is not set:' . $table);
                                }
                                $where[$k][$k2] = [$spk => $v2];
                            }
                        }
                    }
                }
            }
            
            $query->setRaw('where', $where);
        }
        
        return $query;
    }
62533
public function unprepared($query)
    {
        $start = $this->getLogTime();

        try {

            $result = $this->wpdb->query($query);

            if ($result === false || $this->wpdb->last_error) {
                throw new QueryException($query, [], new \Exception($this->wpdb->last_error));
            }

            return $result;

        } catch (QueryException $e) {
            throw $e;
        } finally {
            $this->logQuery($query, [], $this->getElapsedTime($start));
        }

    }
540288
protected function _throwRendererException(
        $message = null,
        $code = null,
        RootException $previous = null
    ) {
        return $this->_createRendererException($message, $code, $previous, $this);
    }
103161
protected function handle_error($query)
    {
        $error = $this->dbh->errorInfo();

        if (empty($this->options['ignore_key_errors']) || !in_array($error[0], array('23000', '23505'))) {
            $this->db_error = true;
            $this->db_error_msg = sprintf('[%s] %s', $error[1], $error[2]);

            if (empty($this->options['ignore_errors'])) {
                rcube::raise_error(array(
                        'code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__,
                        'message' => $this->db_error_msg . " (SQL Query: $query)"
                    ), true, false);
            }
        }

        return false;
    }
91691
public function createNotFoundException($message = 'Not Found', \Exception $previous = null)
    {
        if ($this->has('atom.404.logger')) {
            $log = $this->get('atom.404.logger');
            $log->addRecord(400, $message, array('request' => $this->getRequest()->getUri()));
        }

        return new NotFoundHttpException($message, $previous);
    }
621076
public function withQuery($query)
    {
        $new = clone $this;
        try {
            $new->setQuery($query);
        } catch (InvalidArgumentException $ex) {
            throw new InvalidArgumentException('Invalid query provided.', null, $ex);
        }

        return $new;
    }
1281420
protected function prepareMysqlException(\Exception $databaseException, string $query, array $criteria = []): MysqlException {
		$code = $databaseException->getCode();
		
		$mysqlException = new MysqlException(
			$databaseException->getMessage(),
			is_numeric($code) ? $code : 0,
			$databaseException
		);
		
		$mysqlException->setQuery($this->getStatement($query, $criteria));
		return $mysqlException;
	}
883979
public function query($query = null)
    {
        /** @var StmtInterface $result */
        try {
            
            $event = new ConnectionEvent($this, $query);
            $this->container->getDispatcher()->dispatch(ConnectionEvent::ON_QUERY, $event);
            
            $result = parent::query($query);
        } catch (\Exception $exception) {
            throw new ConnectionException(sprintf(
                'Executing SQL Query was failure with error: [%d] (%s)', $exception->getCode(), $exception->getMessage()));
        }
        
        return $result;
    }