获取数据表信息
@access public
@param mixed  $tableName 数据表名 留空自动获取
@param string $fetch     获取信息类型 包括 fields type bind pk
@return mixed
772342
public function getTableInfo($tableName, $fetch = '')
    {
        if (is_array($tableName)) {
            $tableName = key($tableName) ?: current($tableName);
        }

        if (strpos($tableName, ',')) {
            // 多表不获取字段信息
            return false;
        } else {
            $tableName = $this->parseSqlTable($tableName);
        }

        // 修正子查询作为表名的问题
        if (strpos($tableName, ')')) {
            return [];
        }

        list($tableName) = explode(' ', $tableName);

        if (!strpos($tableName, '.')) {
            $schema = $this->getConfig('database') . '.' . $tableName;
        } else {
            $schema = $tableName;
        }

        if (!isset(self::$info[$schema])) {
            // 读取缓存
            $cacheFile = $this->config['schema_path'] . $schema . '.php';
            if (is_file($cacheFile)) {
                $info = include $cacheFile;
            } else {
                $info = $this->getFields($tableName);
            }

            $fields = array_keys($info);
            $bind   = $type   = [];

            foreach ($info as $key => $val) {
                // 记录字段类型
                $type[$key] = $val['type'];
                $bind[$key] = $this->getFieldBindType($val['type']);
                if (!empty($val['primary'])) {
                    $pk[] = $key;
                }
            }

            if (isset($pk)) {
                // 设置主键
                $pk = count($pk) > 1 ? $pk : $pk[0];
            } else {
                $pk = null;
            }

            self::$info[$schema] = ['fields' => $fields, 'type' => $type, 'bind' => $bind, 'pk' => $pk];
        }

        return $fetch ? self::$info[$schema][$fetch] : self::$info[$schema];
    }
712674
public function fetch(int $fetch_style = \PDO::FETCH_ASSOC, int $cursor_orientation = null, int $cursor_offset = null)
    {
        $this->execute();
        
        return $this->stmt->fetch($fetch_style, $cursor_orientation, $cursor_offset);
    }
395409
public function getTableDescription($tableName)
    {
        // simple cache
        if (!isset(self::$tblDescCache[$tableName])) {
            self::$tblDescCache[$tableName] = $this->fetchTableDescription($tableName);
        }

        return self::$tblDescCache[$tableName];
    }
133044
public function getTotalNums($pkField = null, $tableName = null, $tablePrefix = null)
    {
        is_null($tableName) && $tableName = $this->getTableName();
        is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;
        is_null($pkField) && $pkField = $this->db($this->getDbConf())->getPk($tableName, $tablePrefix);
        return $this->db($this->getDbConf())->table($tableName, $tablePrefix)->count($pkField, false, $this->useMaster);
    }
645807
public function getFields($tableName) {
        $this->initConnect(true);
        list($tableName) = explode(' ', $tableName);
        if(strpos($tableName,'.')){
        	list($dbName,$tableName) = explode('.',$tableName);
			$sql   = 'SHOW COLUMNS FROM `'.$dbName.'`.`'.$tableName.'`';
        }else{
        	$sql   = 'SHOW COLUMNS FROM `'.$tableName.'`';
        }
        
        $result = $this->query($sql);
        $info   =   array();
        if($result) {
            foreach ($result as $key => $val) {
				if(\PDO::CASE_LOWER != $this->_linkID->getAttribute(\PDO::ATTR_CASE)){
					$val = array_change_key_case ( $val ,  CASE_LOWER );
				}
                $info[$val['field']] = array(
                    'name'    => $val['field'],
                    'type'    => $val['type'],
                    'notnull' => (bool) ($val['null'] === ''), // not null is empty, null is yes
                    'default' => $val['default'],
                    'primary' => (strtolower($val['key']) == 'pri'),
                    'autoinc' => (strtolower($val['extra']) == 'auto_increment'),
                );
            }
        }
        return $info;
    }
987809
private function getFetchMode($className, $fetchMode) : string
    {
        $fetchModeConstant = sprintf('%s::%s', Mapping\FetchMode::class, $fetchMode);

        if (! defined($fetchModeConstant)) {
            throw Mapping\MappingException::invalidFetchMode($className, $fetchMode);
        }

        return constant($fetchModeConstant);
    }
174042
protected function _fetchField($result, $key = 0)
    {
        $return = null;
        if ($row = $result->fetch_row()) {
            $return = $row[(int)$key];
        }

        $result->free();

        return $return;
    }
1100529
protected function getDeclaringSql($tableName)
    {
        $rows = $this->fetchAll('select * from sqlite_master where `type` = \'table\'');

        $sql = '';
        foreach ($rows as $table) {
            if ($table['tbl_name'] === $tableName) {
                $sql = $table['sql'];
            }
        }

        return $sql;
    }
729505
public function fetch($style = null, $orientation = null, $offset = null)
    {
        set_error_handler(array($this->_pdooci,"errorHandler"));
        try {
            $style = is_null($style) ? $this->_fetch_sty : $style;
            $this->_fetch_sty = $style;
            $rst   = null;

            switch ($style)
            {
            case \PDO::FETCH_BOTH:
            case \PDO::FETCH_BOUND:
                $rst = \oci_fetch_array($this->_stmt, \OCI_BOTH + \OCI_RETURN_NULLS);
                break;
            case \PDO::FETCH_ASSOC:
                $rst = \oci_fetch_array($this->_stmt, \OCI_ASSOC + \OCI_RETURN_NULLS);
                $rst = $this->_fixResultKeys($rst);
                break;
            case \PDO::FETCH_NUM:
                $rst = \oci_fetch_array($this->_stmt, \OCI_NUM + \OCI_RETURN_NULLS);
                break;
            case \PDO::FETCH_OBJ:
                $rst = \oci_fetch_object($this->_stmt);
                break;
            }
            $this->_current = $rst;
            $this->_checkBinds();
        } catch (\Exception $e) {
            throw new \PDOException($e->getMessage());
        }
        restore_error_handler();
        return $rst;
    }
225678
public function query($query, array $binds = [], $fetch = null)
    {
        $request = new StdClass();

        $request->query = $query;
        $request->binds = $binds;

        $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
            throw SqlException::forQueryError($query, $error[2]);
        }

        //clear binds
        $this->binds = [];

        if (!is_callable($fetch)) {
            $results = $stmt->fetchAll(PDO::FETCH_ASSOC);

            //log query
            $this->log([
                'query'     => $query,
                'binds'     => $binds,
                'results'   => $results
            ]);

            return $results;
        }

        if ($fetch instanceof Closure) {
            $fetch = $fetch->bindTo($this, get_class($this));
        }

        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            if (call_user_func($fetch, $row, $this) === false) {
                break;
            }
        }

        return $this;
    }
171419
public function getFields($tableName)
    {
        list($tableName) = explode(' ', $tableName);
        $tableNames      = explode('.', $tableName);
        $tableName       = isset($tableNames[1]) ? $tableNames[1] : $tableNames[0];

        $sql = "SELECT   column_name,   data_type,   column_default,   is_nullable
        FROM    information_schema.tables AS t
        JOIN    information_schema.columns AS c
        ON  t.table_catalog = c.table_catalog
        AND t.table_schema  = c.table_schema
        AND t.table_name    = c.table_name
        WHERE   t.table_name = '$tableName'";

        $pdo    = $this->query($sql, [], false, true);
        $result = $pdo->fetchAll(PDO::FETCH_ASSOC);
        $info   = [];

        if ($result) {
            foreach ($result as $key => $val) {
                $val                       = array_change_key_case($val);
                $info[$val['column_name']] = [
                    'name'    => $val['column_name'],
                    'type'    => $val['data_type'],
                    'notnull' => (bool) ('' === $val['is_nullable']), // not null is empty, null is yes
                    'default' => $val['column_default'],
                    'primary' => false,
                    'autoinc' => false,
                ];
            }
        }

        $sql = "SELECT column_name FROM information_schema.key_column_usage WHERE table_name='$tableName'";

        // 调试开始
        $this->debug(true);

        $pdo = $this->linkID->query($sql);

        // 调试结束
        $this->debug(false, $sql);

        $result = $pdo->fetch(PDO::FETCH_ASSOC);

        if ($result) {
            $info[$result['column_name']]['primary'] = true;
        }

        return $this->fieldCase($info);
    }
216765
public function get($name = null, $fetchHandler = null)
    {
        if (!func_num_args()) {
            $data = [];
            foreach ($this->_data as $key => $value) {
                $data[$key] = $this->{$key};
            }
            return $data;
        }
        $keys = is_array($name) ? $name : explode('.', $name);
        $name = array_shift($keys);
        if ($name === null || $name === '') {
            throw new ORMException("Field name can't be empty.");
        }

        if ($keys) {
            $value = $this->get($name);
            if (!$value) {
                return;
            }
            if (!$value instanceof DataStoreInterface) {
                throw new ORMException("The field: `" . $name . "` is not a valid document or entity.");
            }
            return $value->get($keys);
        }

        $fieldName = $this->basePath() ? $this->basePath() . '.' . $name : $name;
        $schema = $this->schema();

        $field = [];

        if ($schema->has($fieldName)) {
            $field = $schema->column($fieldName);
        } else {
            $genericFieldName = $this->basePath() ? $this->basePath() . '.*' : '*';
            if ($schema->has($genericFieldName)) {
                $field = $schema->column($genericFieldName);
                $fieldName = $genericFieldName;
            } elseif ($schema->locked() && !$schema->hasRelation($fieldName, false)) {
                throw new ORMException("Missing schema definition for field: `" . $fieldName . "`.");
            }
        }

        $autoCreate = !empty($field['array']);

        if (!empty($field['getter'])) {
            $data = $field['getter']($this, array_key_exists($name, $this->_data) ? $this->_data[$name] : null, $name);
            if (!empty($field['type'])) {
                $data = $schema->convert('cast', $field['type'], $data, $field);
            }
            return $data;
        } elseif (array_key_exists($name, $this->_data)) {
            return $this->_data[$name];
        } elseif ($schema->hasRelation($fieldName, false)) {
            $relation = $schema->relation($fieldName);
            $hasManyThrough = $relation->type() === 'hasManyThrough';
            if (!$hasManyThrough || ($this->id() !== null && !$this->has($relation->through()))) {
                $belongsTo = $relation->type() === 'belongsTo';
                $foreignKey = $belongsTo ? $this->get($relation->keys('from')) : null;
                if (($this->_exists !== false && !$belongsTo) || $foreignKey !== null) {
                    if ($fetchHandler) {
                        return $fetchHandler($this, $name);
                    }
                    throw new ORMException("The relation `'{$name}'` is an external relation, use `fetch()` to lazy load its data.");
                }
            }
            $autoCreate = $relation->isMany();
            $value = $hasManyThrough ? null : [];
        } elseif (isset($field['default'])) {
            $autoCreate = true;
            $value = $field['default'];
        }

        if ($autoCreate) {
            $this->setAt($name, $value);
            return $this->_data[$name];
        }
    }
1320156
public function find( $table, $fields = null, $where = null, $order = null, $limit = null, $offset = null, $array = array (), $fetchMode = \PDO::FETCH_ASSOC )
     {
         // TODO: Implement find() method.
     }
579966
public function getTableCreateSql($tableName)
    {
        $sql = sprintf('SHOW CREATE TABLE %s', $this->ident($tableName));
        $result = $this->pdo->query($sql)->fetch();

        return $result['CREATE TABLE'];
    }
1014091
public function getData($key, $fetcher = self::DEFAULT_FETCHER_NAME)
    {
        return $this->getDataFetcher($fetcher)->getData($key);
    }
885153
protected function fetch($key)
    {
        $success = false;

        if (function_exists('apcu_fetch')) {
            $data = apcu_fetch($key, $success);
        } else {
            $data = apc_fetch($key, $success);
        }

        $this->debugSection('Fetching a stored variable', $success ? 'OK' : 'FAILED');

        return $data;
    }
1192942
public function query(string $sql, $bind = [])
    {
        $sql = trim($sql);

        // 执行前置 钩子
        $ret = $this->before('Query', $sql, $bind);
        if ($ret === self::INTERRUPT) {
            return null;
        }
        list($sql, $bind) = $ret;

        //修正查询参数
        $this->statement->query($sql, $bind);

        // 如果允许多表访问,直接通过
        if ($this->enableMulti()) {
            // 调用 父类的 查询语句获取结果, 执行后置钩子进行转换
            return $this->after('Query', self::query2());
        }

        // 取表名
        $table = $this->statement->getTable();
        $tables = count($table);

        // 如果未识别出表名,有可能是库操作
        if (!$tables) {
            // 调用 父类的 查询语句获取结果, 执行后置钩子进行转换
            return $this->after('Query', self::query2());
        }

        // 如果识别出多个表名
        if ($tables > 1) {
            trigger_error('查询语句中不允许同时指定多个表名:' . json($tables), E_USER_ERROR);
        }

        // 只有一个表
        $table = $table[0];

        // 如果语句中的表名与初始化时不同,则错误
        if ($table != $this->tableName) {
            trigger_error('表名不匹配:' . $this->tableName . ':' . $this->statement->getSql(), E_USER_ERROR);
        }

        // 调用 父类的 查询语句获取结果, 执行后置钩子进行转换
        return $this->after('Query', self::query2());
    }