uses the parameters to prepare one of our own exceptions and returns it.

@param \PDOException $pdoException
@param string        $query
@param array         $criteria

@return DatabaseException
168267
protected function prepareDatabaseException(\PDOException $pdoException, string $query, array $criteria = []): DatabaseException {
		$databaseException = new DatabaseException(
			$pdoException->getMessage(),
			(int)$pdoException->getCode(),
			$pdoException
		);
		
		$query = $this->getStatement($query, $criteria);
		$databaseException->setQuery($query);
		return $databaseException;
	}
480856
public function update(string $table, array $values, array $criteria = []): int {
		
		// like our insertion methods above, this one can impact one or more rows
		// and we want to return the number of rows we alter.  unlike the insertion
		// methods, all we need to do is build our statement which isn't too hard for
		// us to do.
		
		$where = "";
		$updates = [];
		$valueColumns = array_keys($values);
		foreach ($valueColumns as $column) {
			$updates[] = sprintf("%s%s%s = ?", $this->columnPrefix, $column, $this->columnSuffix);
		}
		
		$statement = "UPDATE $table SET " . join(", ", $updates);
		
		if (sizeof($criteria) > 0) {
			$whereColumns = array_keys($criteria);
			foreach ($whereColumns as $column) {
				$where .= sprintf("%s%s%s = ?", $this->columnPrefix, $column, $this->columnSuffix);
			}
			
			$statement .= " WHERE $where";
		}
		
		// now that we've built our statement, we need to combine the values and criteria values
		// which are then bound to the statement by the ExtendedPdo object.  then, we can perform
		// the statement and return the number of affected rows.
		
		$bindings = $this->mergeBindings($values, $criteria);
		
		try {
			return $this->dbConn->fetchAffected($statement, $bindings);
		} catch (\PDOException $pdoException) {
			throw $this->prepareDatabaseException($pdoException, $statement, $bindings);
		}
	}
1217191
public function run_query($sql, array $params=null, array $driverOptions=array()) {
		try {
			$this->sth = null;
			$this->sth = $this->dbh->prepare($sql, $driverOptions);
			if($this->sth === false) {
				throw new \Exception(__METHOD__ .": STH is false... ". ToolBox::debug_print($this->dbh->errorInfo(),0));
			}
			// TODO: throw an exception on error (and possibly if there were no rows returned)
			$this->sth->execute($params); 
			$this->numRows = $this->sth->rowCount();
		}
		catch(PDOException $px) {
			throw new \Exception(__METHOD__ .": ". $px->getMessage());
		}
		return($this->numRows);
	}
355055
public function query ($query, $data = array(), $entity = null)
		{
			if ($this->cache->isCached($query)) {
				return $this->cache->getCachedResult($query);
			} else {
				try {
					$statement = $this->database->prepare((string) $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
					$result = $statement->execute($data);
					$this->lastQuery = $statement->queryString;
					$this->lastStatement = $statement;

					if (! $result) {
						throw new DatabaseException(implode(': ', $statement->errorInfo()) . PHP_EOL . PHP_EOL . $query);
					}

				} catch (PDOException $e) {
					throw new DatabaseException($e->getMessage() . PHP_EOL . PHP_EOL . $query);
				}

				$databaseResult = $this->createResult($statement, $entity);

				if ($query instanceof DatabaseQuery && $databaseResult instanceof DatabaseResult) {
					$this->cache->cacheQuery($query, $databaseResult);
				}

				if ($query instanceof DatabaseQuery) {
					$this->cache->refreshCache($query);
				}

				if ($databaseResult instanceof DatabaseResult) {
					return $databaseResult;

				} else if ($query instanceof DatabaseQuery && $query->getType() == DatabaseQuery::QUERY_TYPE_INSERT) {
					return $this->insertId($query->getTable());

				} else {
					return $databaseResult;
				}
			}
		}
1167672
public function query($pQuery, array $pParams = array())
    {
        $this->_stm = Agl::app()->getDb()->getConnection()->prepare($pQuery);

        if (! $this->_stm->execute($pParams)) {
            $error = $this->_stm->errorInfo();
            throw new Exception("The query failed with message '" . $error[2] . "'");
        }

        if (Agl::app()->isDebugMode()) {
            Agl::app()->getDb()->incrementCounter();
        }

        return $this->_stm->fetchAll(PDO::FETCH_ASSOC);
    }
311198
public SQLException exceptionWithQuery(ParameterHolder[] parameters, SQLException sqlEx,
      PrepareResult serverPrepareResult) {
    if (sqlEx.getCause() instanceof SocketTimeoutException) {
      return new SQLException("Connection timed out", CONNECTION_EXCEPTION.getSqlState(), sqlEx);
    }
    if (options.dumpQueriesOnException) {
      return new SQLException(exWithQuery(sqlEx.getMessage(), serverPrepareResult, parameters),
          sqlEx.getSQLState(),
          sqlEx.getErrorCode(), sqlEx.getCause());
    }
    return sqlEx;
  }
1197018
function query($query,$bind_arr = null){
    $stmt = $this->mysqli->prepare($query);
    if(!$stmt){
     throw new Exception("can't prepare query:[$query] because [".$this->mysqli->error."]");
    }
    if(isset($bind_arr) && $bind_arr != null){
      call_user_func_array(array($stmt,'bind_param'),$this->makeValuesReferenced($bind_arr));
    }
    /* execute prepared statement */
    if(!$stmt->execute()){
       throw new Exception( $this->mysqli->error );
    }
    $answer = $this->fetch($stmt);
    $stmt->close();
    return $answer;
  }
1023759
public function exec($query)
    {
        try {
            $this->connection->exec($query);
        } catch (DBALException $e) {
            throw new QueryException($e->getMessage(), $e->getCode(), $e);
        }
    }
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;
        }
1263986
public function prepare($statement, $driver_options = [])
    {
        try {
            $this->_last_statement = $statement;

            return parent::prepare($statement, $driver_options);
        } catch (\PDOException $e) {
            throw new Exception($e->getMessage(), 500, Exception::DBSTATEMENT);
        }
    }
174956
public function findBy(array $criteria)
    {
        //Make sure there is a criteria
        if(count($criteria) == 0)
        {
            throw new Exception("Please supply at least one criteria to findBy().");
        }

        $collection = new ArrayCollection();

        //If this repository is for a node
        if($this->meta instanceof Node)
        {
            $query = $this->createIndexQuery($criteria);

            foreach($this->getIndex()->query($query) as $node)
            {
                $collection->add($this->entityManager->loadNode($node));
            }
        }

        //Is a relation
        elseif($this->meta instanceof Relation)
        {
            //Array of different results
            $result_sets = array();

            //Criteria to use for query
            $query_criteria = array();

            //Generate the query criteria
            foreach($criteria as $k => $v)
            {
                $key = Meta\Reflection::normalizeProperty($k);

                //If it's the start or end
                if($key == $this->meta->getStart()->getName() || $key == $this->meta->getEnd()->getName())
                {
                    //Load relation by node (null if the property isn't a start/end)
                    $result_sets[] = $this->getRelationsByNode($key, $v);
                }

                //Regular property, add to query criteria to run later
                else
                {
                    $query_criteria[$k] = $v;
                }
            }

            //Do the query
            if(count($query_criteria) > 0)
            {
                $query = $this->createIndexQuery($query_criteria);
                $result_sets[] = $this->getIndex()->query($query);
            }

            //Intersect the 3 potential result sets (if they are there)
            $results = count($result_sets) > 1 ? call_user_func_array('array_intersect', $result_sets) : $result_sets[0];

            foreach($results as $rel)
            {
                $collection->add($this->entityManager->loadRelation($rel));
            }
        }

        return $collection;
    }
1020915
protected function validate($query)
    {
        if ($this->client->getIndex() == null) {
            throw new SearchException("Index cannot be null");
        }
        if ($this->client->getType() == null) {
            throw new SearchException("Type cannot be null");
        }
        if ($query == null) {
            throw new SearchException("Query can't be null");
        }
    }
875600
protected function convertDatabaseException(\Exception $e)
	{
		if($e instanceof DatabaseException)
		{
			return $e;
		}
		
		// Check for PDO exception in order to determine FK violation:
		$cause = $e;
		
		if(!$cause instanceof \PDOException)
		{
			while(NULL !== ($cause = $cause->getPrevious()))
			{
				if($cause instanceof \PDOException)
				{
					break;
				}
			}
		}
		
		if($cause instanceof \PDOException)
		{
			switch($this->driverName)
			{
				case DB::DRIVER_MYSQL:
					return $this->convertMySqlException($cause, $e);
				case DB::DRIVER_POSTGRESQL:
					return $this->convertPostgresException($cause, $e);
				case DB::DRIVER_SQLITE:
					return $this->convertSqliteException($cause, $e);
			}
		}
		
		return new DatabaseException($e->getMessage(), 0, $e);
	}
408585
public function bind_and_run( $query, $bindings = [] )
	{
		$new_query = $this->bind_params( $query, $bindings );

		$result = $this->db->query( $new_query );

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

		return (array) $result;
	}
486802
protected function explainQuery($dbConnection, $query, $parameters = array())
    {
        $driver = $dbConnection->getAttribute(\PDO::ATTR_DRIVER_NAME);
        $query = $this->getExplainQuery($query, $driver);
        $statement = $dbConnection->prepare($query);
        if ($statement === false) {
            throw new Exception('Invalid query passed to explainQuery method');
        }
        $statement->execute($parameters);
        $result = $statement->fetch(\PDO::FETCH_ASSOC);
        if ($result === false) {
            throw new Exception('Query could not be explained with given parameters');
        }
        return $result;
    }
269015
public function setQuery(string $query, ?PDO $db = null)
    {
        if ($db == null) {
            $db = MDbConnection::getDbConnection();
        }

        if ($db instanceof \PDO) {
            $this->query = new MPDOQuery($query, $db);
        } else {
            throw new \Exception("Database connection not supported.");
        }

        $this->query->exec();
    }
919274
public function query($query, array $binds = array())
    {
        //Argument 1 must be a string or null
        Argument::i()->test(1, 'string', self::QUERY);
        
        $request = new \stdClass();
        
        $request->query = $query;
        $request->binds = $binds;
        
        //event trigger
        $this->trigger('sql-query-before', $request);
        
        $connection = $this->getConnection();
        $query      = (string) $request->query;
        $stmt       = $connection->prepare($query);
        
        //bind some more values
        foreach ($request->binds as $key => $value) {
            $stmt->bindValue($key, $value);
        }
        
        //PDO Execute
        if (!$stmt->execute()) {
            $error = $stmt->errorInfo();
            
            //unpack binds for the report
            foreach ($binds as $key => $value) {
                $query = str_replace($key, "'$value'", $query);
            }
            
            //throw Exception
            Exception::i()
                ->setMessage(Exception::QUERY_ERROR)
                ->addVariable($query)
                ->addVariable($error[2])
                ->trigger();
        }
        
        $results = $stmt->fetchAll(\PDO::FETCH_ASSOC);
        
        if($this->queryCache) {
            //log query
            $this->queries[] = array(
                'query'     => $query,
                'binds'     => $binds,
                'results'   => $results);
        }

        //clear binds
        $this->binds = array();
        
        //event trigger
        $this->trigger('sql-query-after', $query, $binds, $results);
        
        return $results;
    }