Called before each db query.

Overridden to ensure $this->lastErorr is reset each query

@param string $sql
@param array array of parameters
@param int $type type of query
@param mixed $extrainfo driver specific extra information
@return void
359619
protected function query_start($sql, array $params=null, $type, $extrainfo=null) {
        $this->lastError = null;
        parent::query_start($sql, $params, $type, $extrainfo);
    }
883249
public function query($sql, $query_type = null, $result_type = null) {

		if($this->db === null) $this->connect();

		try {

			// SELECT
			if($query_type === \HybridLogic\DB::SELECT) {

				$stmt = $this->db->query($sql);

				if($result_type === null) {
					$results = $stmt->fetchAll(\PDO::FETCH_ASSOC);
				} else {
					$results = $stmt->fetchAll(\PDO::FETCH_CLASS, $result_type);
				}

				return $results;

			}

			// INSERT, UPDATE & DELETE
			$rows_affected = $this->db->exec($sql);

			if($query_type === \HybridLogic\DB::INSERT) {
				$result = array(
					'insert_id'     => $this->db->lastInsertId(),
					'rows_affected' => $rows_affected,
				);
			} else {
				$result = $rows_affected;
			}

			return $result;

		} catch(\PDOException $e) {
			throw new \HybridLogic\DB\Exception\QueryException($e);
		}

	}
1212412
protected function query ( $sql )
	{
		$sql = $this->sql_printf(func_get_args());
		if (!($res = mysql_query($sql, $this->conn)))
		{
			$this->sql_errcheck($sql);
		}
		if (is_resource($res))
		{
			mysql_free_result($res);
		}
	}
872441
public function stopDebug($type = "")
    {
        if (!Text::isEmpty($type) && !in_array($type, ["exec", "query"])) {
            throw new DbException("Invalid filter type. Valid filter types are 'exec' and 'query'");
        }
        
        $types = Text::isEmpty($type)? ["exec", "query"]: [$type];
        foreach ($types as $type) {
            $this->_debugger->off($type, $this->_debugListener);
        }
    }
1362896
public function set_caching($type)
    {
        if ($type) {
            $this->caching = $type;
        }
        else {
            if ($this->cache) {
                $this->cache->close();
            }
            $this->cache   = null;
            $this->caching = false;
        }
    }
112418
@Override
    public void runReport(Map<String, Object> extra) {
        PreparedStatement prestatement = null;
        PreparedStatement poststatement = null;
        PreparedStatement statement = null;
        try {
            getStartConnection();
            if (StringUtils.isNotBlank(presql))
            {
                FreemarkerSQLResult prefreemarkerSQLResult = freemakerParams(extra, false, presql);
                prestatement = connection.prepareStatement(prefreemarkerSQLResult.getSql());
                for(int i=0;i<prefreemarkerSQLResult.getParams().size();i++) {
                    prestatement.setObject(i + 1, prefreemarkerSQLResult.getParams().get(i));
                }
                prestatement.setQueryTimeout(queryTimeout);
                prestatement.execute();
            }
            FreemarkerSQLResult freemarkerSQLResult = freemakerParams(extra, true, freemarkerSql);
            statement = connection.prepareStatement(freemarkerSQLResult.getSql());
            for(int i=0;i<freemarkerSQLResult.getParams().size();i++) {
                statement.setObject(i + 1, freemarkerSQLResult.getParams().get(i));
            }
            statement.setQueryTimeout(queryTimeout);
            rows = resultSetToMap(statement.executeQuery());
            if (StringUtils.isNotBlank(postsql))
            {
                FreemarkerSQLResult postfreemarkerSQLResult = freemakerParams(extra, false, postsql);
                poststatement = connection.prepareStatement(postfreemarkerSQLResult.getSql());
                for(int i=0;i<postfreemarkerSQLResult.getParams().size();i++) {
                    poststatement.setObject(i + 1, postfreemarkerSQLResult.getParams().get(i));
                }
                poststatement.setQueryTimeout(queryTimeout);
                poststatement.execute();
            }
        } catch (Exception ex) {
            errors.add(ex.getMessage());
        } finally {
            try {
                if (statement != null && !statement.isClosed())
                {
                    statement.close();
                    statement = null;
                }
                if (prestatement != null && !prestatement.isClosed())
                {
                    prestatement.close();
                    prestatement = null;
                }
                if (poststatement != null && !poststatement.isClosed())
                {
                    poststatement.close();
                    poststatement = null;
                }
                if (connection != null && !connection.isClosed())
                {
                    connection.close();
                    connection = null;
                }
            } catch (SQLException e) {
                errors.add(e.getMessage());
                e.printStackTrace();
            }
        }
    }
361381
public function prepare( $sql, $values ) {
		/** @var \wpdb $wpdb */
		global $wpdb;

		return empty( $values ) ? $sql : $wpdb->prepare( $sql, $values );
	}
634562
protected function _die( $msg, $sql = null )
    {
        if ( $this->db )
        {
            eZDebug::writeError( $sql, "$msg" . mysqli_error( $this->db ) );
        }
        else
        {
            /// @todo to be fixed: will this generate a warning?
            eZDebug::writeError( $sql, "$msg: " . mysqli_error() );
        }
    }
739380
public function addDebugListener($listener, $type = "")
    {
        if (!Text::isEmpty($type) && !in_array($type, ["exec", "query"])) {
            throw new DbException("Invalid filter type. Valid filter types are 'exec' and 'query'");
        }
        
        $types = Text::isEmpty($type)? ["exec", "query"]: [$type];
        foreach ($types as $type) {
            $this->_debugger->on($type, $listener);
        }
    }
279233
public function onAddedToType(TypeInterface &$type)
    {
        parent::onAddedToType($type);

        $type->addTrait(AdditionalPropertiesInterface::class, AdditionalPropertiesInterfaceImplementation::class)->protectFields($this->getName());
    }
1366029
public function startQuery($sql, array $params = NULL, array $types = NULL)
	{
		Debugger::timer('doctrine');

		$source = NULL;
		foreach (debug_backtrace() as $row) {
			if (isset($row['file']) && $this->filterTracePaths(realpath($row['file']))) {
				if (isset($row['class']) && stripos($row['class'], '\\' . Proxy::MARKER) !== FALSE) {
					if (!in_array(Proxy::class, class_implements($row['class']))) {
						continue;
					} elseif (isset($row['function']) && $row['function'] === '__load') {
						continue;
					}
				} elseif (stripos($row['file'], DIRECTORY_SEPARATOR . Proxy::MARKER) !== FALSE) {
					continue;
				}
				$source = [$row['file'], (int) $row['line']];
				break;
			}
		}

		$this->queries[] = [$sql, (array) $params, NULL, (array) $types, $source];
	}
841821
public function setAdditionalCondition($additionalCondition, $additionalConditionSql)
	{
		if ( ! empty($additionalCondition)) {
			$additionalCondition = '(' . $additionalCondition . ')';
		}
		$this->additionalCondition = $additionalCondition;

		if ( ! empty($additionalConditionSql)) {
			$additionalConditionSql = '(' . $additionalConditionSql . ')';
		}
		$this->additionalConditionSql = $additionalConditionSql;
	}
1135464
final public function fetchAll($sql, $type = \PDO::FETCH_ASSOC)
    {
        if (!$this->DB) {
            throw  new Exception('您还没有连接数据库', Exception::CODE_DATABASE_ERROR);
        }
        $sth = $this->DB->query($sql);
        $this->lastQueryAt = time();
        return $this->DB->fetchAll($type);
    }
335367
protected function _run(string $type, string $table, string $sql=NULL, array $vals=NULL, bool $reset=TRUE): PDOStatement
	{
		if ($sql === NULL)
		{
			$sql = $this->_compile($type, $table);
		}

		if ($vals === NULL)
		{
			$vals = array_merge($this->state->getValues(), $this->state->getWhereValues());
		}

		$startTime = microtime(TRUE);

		$res = empty($vals)
			? $this->driver->query($sql)
			: $this->driver->prepareExecute($sql, $vals);

		$endTime = microtime(TRUE);
		$totalTime = number_format($endTime - $startTime, 5);

		// Add this query to the list of executed queries
		$this->_appendQuery($vals, $sql, (int) $totalTime);

		// Reset class state for next query
		if ($reset)
		{
			$this->resetQuery();
		}

		return $res;
	}
1372004
public function addSql($name, $type = self::SQL_START, $value = '') {
        if ($this->_enabled == true) {
            switch ($type) {
                case self::SQL_START:
                    if (isset($this->_sql[$name])) {
                        $this->_lastSql = $name;
                    }
                    else {
                        $this->_lastSql = $name . rand(0, 10);
                    }

                    $this->_sql[$this->_lastSql] = [];
                    $this->_sql[$this->_lastSql]['time'] = microtime(true);
                    break;

                case self::SQL_END:
                    $this->_sql[$this->_lastSql]['time'] = round((microtime(true) - $this->_sql[$this->_lastSql]['time']) * 1000, 4);
                    $this->_sql[$this->_lastSql]['query'] = $value;
                    break;
            }
        }
    }
159710
protected function _getCompile(string $type, string $table, bool $reset): string
	{
		$sql = $this->_compile($type, $table);

		// Reset the query builder for the next query
		if ($reset)
		{
			$this->resetQuery();
		}

		return $sql;
	}
590214
private function debugLogSql($type = Debug::SQL_TYPE_NORMAL, $other = 0)
    {
        Debug::addSqlInfo($this->buildDebugSql(), $type, $other);
    }