webman使用think-orm问题

/**
     * 执行查询 返回数据集
     * @access protected
     * @param BaseQuery $query 查询对象
     * @param mixed     $sql   sql指令
     * @param array     $bind  参数绑定
     * @param bool      $master 主库读取
     * @return array
     * @throws BindParamException
     * @throws \PDOException
     * @throws \Exception
     * @throws \Throwable
     */
    protected function pdoQuery(BaseQuery $query, $sql, array $bind = [], bool $master = null): array
    {
        // 分析查询表达式
        $query->parseOptions();

        if ($query->getOptions('cache')) {
            // 检查查询缓存
            $cacheItem = $this->parseCache($query, $query->getOptions('cache'));
            $key       = $cacheItem->getKey();

            $data = $this->cache->get($key);
            // 此处判断有问题
            // if (null !== $data) {
            if (!empty($data) && null !== $data) {
                return $data;
            }
        }

        if ($sql instanceof Closure) {
            $sql  = $sql($query);
            $bind = $query->getBind();
        }

        if (!isset($master)) {
            $master = $query->getOptions('master') ? true : false;
        }

        $procedure = $query->getOptions('procedure') ? true : in_array(strtolower(substr(trim($sql), 0, 4)), ['call', 'exec']);

        $this->getPDOStatement($sql, $bind, $master, $procedure);

        $resultSet = $this->getResult($procedure);

        if (isset($cacheItem) && $resultSet) {
            // 缓存数据集
            $cacheItem->set($resultSet);
            $this->cacheData($cacheItem);
        }

        return $resultSet;
    }

 

posted @ 2020-10-29 11:14  lobtao  阅读(550)  评论(0)    收藏  举报