取得数据表的字段信息
@access public
@param string $tableName
@return array
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);
    }
1311178
protected function findItems($tableName)
  {
    $tableAlias = $this->getTableAlias($tableName);

    $qb = $this->dbConn->createQueryBuilder();
    $qb->select($this->getTableSelects($tableName,$tableAlias));
    $qb->from($tableName,$tableAlias);

    $stmt  = $qb->execute();
    $items = [];
    while ($row = $stmt->fetch()) {
      $items[] = $this->extractItem($tableAlias . '__',$row);
    }
    return $items;
  }
987455
public function getTableInfo($table)
    {
        if (!$this->tableExists($table)) {
            return null;
        }
        
        $rtable = static::buildRealTableName($table, true);
        $key = 'db/tableinfo/' . $rtable;
        $data = static::getCache()->get($key);
        
        if (!$data) {
            $data = ['table_name' => $table];
            $data['fields'] = $this->getColumns($table);
            $pk = [];
            foreach ($data['fields'] as $key => $val) {
                if($val['is_primary']) {
                    $pk[] = $key;
                }
            }
            $data['primary_key'] = $pk ? $pk[0] : null;
            
            static::getCache()->set($key, $data);
        }
        
        return $data;
    }
1212305
protected function &retrieveColumnsMetadata($tableName)
    {
        /* @noinspection PhpUnhandledExceptionInspection */
        $result = $this->connection->query('SHOW COLUMNS FROM ' . $tableName);
        $result = $result->fetchAll();

        $fields       = [];
        $fieldTypes   = [];
        $fieldLengths = [];

        $cnt = count($result);
        for ($i = 0; $i < $cnt; $i++) {
            $fName                = &$result[$i]['Field'];
            $fType                = &$result[$i]['Type'];
            $fields[]             = &$fName;
            $fieldTypes[$fName]   = explode('(', $fType)[0];
            $fieldLengths[$fName] = $this->extractFieldTypeLength($fType);
        }

        $returnArray = [ // compact() ???
            'fields'       => &$fields,
            'fieldTypes'   => &$fieldTypes,
            'fieldLengths' => &$fieldLengths,
        ];

        return $returnArray;
    }
1214195
public function getTableInfoStr($tableName)
    {
        $metadata = Factory::createSourceFromAdapter($this->db);
        $table = $metadata->getTable($tableName);
        $spaces = function ($count) {
            return str_repeat(' ', $count);
        };

        $result = "{$spaces(4)}With columns:" . PHP_EOL;

        /** @var ColumnObject $column */
        foreach ($table->getColumns() as $column) {
            $result .= "{$spaces(8)}{$column->getName()} -> {$column->getDataType()}" . PHP_EOL;
        }

        $result .= PHP_EOL;
        $result .= "{$spaces(4)}With constraints:" . PHP_EOL;

        /** @var ConstraintObject $constraint */
        foreach ($metadata->getConstraints($tableName) as $constraint) {
            $result .= "{$spaces(8)}{$constraint->getName()} -> {$constraint->getType()}" . PHP_EOL;

            if (!$constraint->hasColumns()) {
                continue;
            }

            $result .= "{$spaces(12)}column: " . implode(', ', $constraint->getColumns());

            if ($constraint->isForeignKey()) {
                $foreignKeyColumns = [];

                foreach ($constraint->getReferencedColumns() as $referenceColumn) {
                    $foreignKeyColumns[] = "{$constraint->getReferencedTableName()}.{$referenceColumn}";
                }

                $result .= ' => ' . implode(', ', $foreignKeyColumns) . PHP_EOL;
                $result .= "{$spaces(12)}OnDeleteRule: {$constraint->getDeleteRule()}" . PHP_EOL;
                $result .= "{$spaces(12)}OnUpdateRule: {$constraint->getUpdateRule()}" . PHP_EOL;
            } else {
                $result .= PHP_EOL;
            }
        }

        return $result;
    }
854123
public function getTableRows(string $tableName)
    {
        $statement = $this->connection->prepare("SELECT * FROM information_schema.columns WHERE table_catalog = :database AND table_name = :table");
        $statement->execute([
            ':database' => $this->Databaser->database,
            ':table'    => $tableName
        ]);

        return $statement->fetchAll(\PDO::FETCH_ASSOC);
    }
533834
public function getFields($tableName) {
        $this->initConnect(true);
        list($tableName) = explode(' ', $tableName);
        $sql='SELECT RF.RDB$FIELD_NAME AS FIELD,RF.RDB$DEFAULT_VALUE AS DEFAULT1,RF.RDB$NULL_FLAG AS NULL1,TRIM(T.RDB$TYPE_NAME) || \'(\' || F.RDB$FIELD_LENGTH || \')\' as TYPE FROM RDB$RELATION_FIELDS RF LEFT JOIN RDB$FIELDS F ON (F.RDB$FIELD_NAME = RF.RDB$FIELD_SOURCE) LEFT JOIN RDB$TYPES T ON (T.RDB$TYPE = F.RDB$FIELD_TYPE) WHERE RDB$RELATION_NAME=UPPER(\''.$tableName.'\') AND T.RDB$FIELD_NAME = \'RDB$FIELD_TYPE\' ORDER By RDB$FIELD_POSITION';
        $result = $this->query($sql);
        $info   =   array();
        if($result){
            foreach($result as $key => $val){
                $info[trim($val['field'])] = array(
                    'name'    => trim($val['field']),
                    'type'    => $val['type'],
                    'notnull' => (bool) ($val['null1'] ==1), // 1表示不为Null
                    'default' => $val['default1'],
                    'primary' => false,
                    'autoinc' => false,
                );
            }
        }
        //获取主键
        $sql='select b.rdb$field_name as field_name from rdb$relation_constraints a join rdb$index_segments b on a.rdb$index_name=b.rdb$index_name where a.rdb$constraint_type=\'PRIMARY KEY\' and a.rdb$relation_name=UPPER(\''.$tableName.'\')';
        $rs_temp = $this->query($sql);
        foreach($rs_temp as $row) {
            $info[trim($row['field_name'])]['primary']= true;
        }
        return $info;
    }
1122504
public function getTableInfo($table=null)
    {
        if (!$table) {
            if (!isset($this['fields'])) {
                $table = $this->getTableName();
                $info = $this->getDb()->getTableInfo($table);
                if ($info) $this->setOption($info);
            }
            return $this->options;
        } else {
            return $this->getDb()->getTableInfo($table);
        }
    }
260483
public function getTableForeignKeys($tableName = null, $connectionName = null)
    {
        $tableName = $this->validateTableName($tableName);

        return $this->getSchema($connectionName)->listTableForeignKeys($tableName);
    }
1081495
public function tableSize(string $tableName)
    {
        $tables = $this->tablesSize();

        if (isset($tables[$tableName])) {
            return $tables[$tableName];
        }

        return null;
    }
500351
protected function describeTable(string $tableName): array
    {
        if (isset($this->_tableDescription[$tableName])) {
            return $this->_tableDescription[$tableName];
        }

        $result = array();
        $statement = 'DESCRIBE ' . $this->getDb()->quoteIdentifier($tableName);
        $cols = $this->fetchAll($statement);

        foreach ($cols as $col) {
            $result[$col['Field']] = $col['Type'];
        }

        $this->_tableDescription[$tableName] = $result;

        return $result;
    }
1012258
public function getFields($tableName)
    {
        $this->initConnect(true);
        list($tableName) = explode(' ', $tableName);
        $sql             = "select a.column_name,data_type,DECODE (nullable, 'Y', 0, 1) notnull,data_default, DECODE (A .column_name,b.column_name,1,0) pk from all_tab_columns a,(select column_name from all_constraints c, all_cons_columns col where c.constraint_name = col.constraint_name and c.constraint_type = 'P' and c.table_name = '" . strtoupper($tableName) . "' ) b where table_name = '" . strtoupper($tableName) . "' and a.column_name = b.column_name (+)";
        $pdo             = $this->linkID->query($sql);
        $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' => $val['notnull'],
                    'default' => $val['data_default'],
                    'primary' => $val['pk'],
                    'autoinc' => $val['pk'],
                ];
            }
        }
        return $this->fieldCase($info);
    }
467804
public static function tableForeignKeys($tableName)
    {
        $result = ['inner' => [], 'outer' => []];
        foreach (Yii::$app->db->schema->tableSchemas as $table) {
            $foreignKeys = static::findConstraints($table);
            /** @var TableSchema $table */
            if ($table->name == $tableName) {
                $result['inner'] = $foreignKeys;
                continue;
            }
            foreach ($foreignKeys as $foreignKey) {
                if ($foreignKey['ftable'] == $tableName) {
                    $result['outer'][] = $foreignKey;
                }
            }
        }
        return $result;
    }
288862
protected function getTableIndexes($tableName = null, $connectionName = null)
    {
        $tableName = $this->validateTableName($tableName);

        return $this->getSchema($connectionName)->listTableIndexes($tableName);
    }
293854
public function getTables($dbName = '')
    {
        $sql    = !empty($dbName) ? 'SHOW TABLES FROM ' . $dbName : 'SHOW TABLES ';
        $pdo    = $this->query($sql, [], false, true);
        $result = $pdo->fetchAll(PDO::FETCH_ASSOC);
        $info   = [];

        foreach ($result as $key => $val) {
            $info[$key] = current($val);
        }

        return $info;
    }
242290
public static function getAllIdps($tableName)
    {
        $databaseConnector = new DatabaseConnector();
        $conn = $databaseConnector->getConnection();
        $whiteListTableName = $databaseConnector->getWhiteListTableName();
        $greyListTableName = $databaseConnector->getGreyListTableName();
        $table = null;
        $listOfIdPs = array();
        assert($conn != null);

        if ($tableName == self::WHITELIST) {
            $table = $whiteListTableName;
        } elseif ($tableName == self::GREYLIST) {
            $table = $greyListTableName;
        }

        $stmt = $conn->prepare("SELECT * FROM " . $table);

        if ($stmt) {
            $ex = $stmt->execute();
            if ($ex === false) {
                Logger::error("Error during select all from " . $table);
            }

            $stmt->bind_result($timestamp, $entityId, $reason);
            while ($stmt->fetch()) {
                $idp = array();
                $idp['timestamp'] = $timestamp;
                $idp['entityid'] = $entityId;
                $idp['reason'] = $reason;
                array_push($listOfIdPs, $idp);
            }

            $stmt->close();
        } else {
            Logger::error("Error during preparing statement");
        }

        $conn->close();
        return $listOfIdPs;
    }
462049
public function getTableColumns($tableName = null, $connectionName = null)
    {
        $tableName = $this->validateTableName($tableName);

        return $this->getSchema($connectionName)->listTableColumns($tableName);
    }