Creates the descriptor from an existent MySQL table.
@param string $name Table name.
@param string $schema Table schema.
@return CMySQLDescriptor Returns a descriptor instance or null if no descriptor available.
333711
private function describeTable($name, $schema)
    {
        $data = $this->connector->getQueryAsSingleRow(
                'SELECT t.table_schema AS table_schema, t.table_name AS table_name, t.engine AS engine,
                        t.auto_increment AS auto_increment, t.table_collation AS table_collation,
                        t.table_comment AS table_comment, cs.character_set_name AS table_charset,
                        t.create_options AS create_options
                   FROM information_schema.tables t, information_schema.character_sets cs
                  WHERE t.table_schema=\'%schema$s\'
                    AND t.table_name = \'%table$s\'
                    AND t.table_collation = cs.default_collate_name',
                array(
                    'schema' => $schema,
                    'table' => $name
                )
        );

        if (is_array($data)) {
            $fields = $this->describeTableFields($name, $schema);
            $table['schema'] = $data['table_schema'];
            $table['name'] = $data['table_name'];
            $table['engine'] = $data['engine'];
            $table['type'] = CMySQLConnector::TYPE_TABLE;
            $table['autoincrement'] = $this->validateAutoIncrement($data['auto_increment'], $fields);
            $table['charset'] = $data['table_charset'];
            $table['collation'] = $data['table_collation'];
            $table['create_options'] = $data['create_options'];
            $table['comment'] = $data['table_comment'];
            $table['fields'] = $fields;
            $table['constraints'] = $this->describeTableConstraints($name, $table['fields'], $schema);
            $descriptor = new CMySQLDescriptor($this->connector, $table);
        } else {
            $descriptor = null;
        }

        return $descriptor;
    }
991149
public function getSchemaTables(Schema $schema)
    {
        $tables = [];

        foreach ($this->tables->keys() as $name) {
            /** @var BaseTable $table */
            $table = $this->tables[$name];
            $tables[$name] = $table->buildTable($schema, $name, $this->charset, $this->collate);
        }

        foreach ($this->tableGenerators as $generator) {
            $table = $generator($schema);

            if (is_array($table)) {
                /** @var Table[] $table */
                foreach ($table as $t) {
                    $alias = str_replace($this->prefix, '', $t->getName());
                    $t->addOption('alias', $alias);
                    $t->addOption('charset', $this->charset);
                    $t->addOption('collate', $this->collate);
                    $tables[$alias] = $t;
                }
            } else {
                /** @var Table $table */
                $alias = str_replace($this->prefix, '', $table->getName());
                $table->addOption('alias', $alias);
                $table->addOption('charset', $this->charset);
                $table->addOption('collate', $this->collate);
                $tables[$alias] = $table;
            }
        }

        return $tables;
    }
301328
public static function fromTableSchema(TableSchema $schema)
    {
        $properties = [];
        $required = [];
        foreach ($schema->getColumns() as $column) {
            if ($column->getRequired()) {
                $required[] = $column->getName();
            }

            $properties[$column->getName()] = static::fromColumnSchema($column);
        }

        return [
            'type'       => 'object',
            'required'   => $required,
            'properties' => $properties
        ];
    }
1171882
public function create($table, $schema)
    {
        return $this
            ->destroy($schema, $table)
            ->initialize($schema, $table)
            ;
    }
1223781
public function build($name = null)
    {
        $tables = [$name];
        if (empty($name)) {
            $tables = $this->_schema->listTables();
        }

        foreach ($tables as $table) {
            $this->_schema->describe($table, ['forceRefresh' => true]);
        }

        return $tables;
    }
947720
public static function fromQName( $name )
	{
		if ( $name instanceof QName )
		{
			$name = "{$name->prefix}:{$name->localName}";
		}
		if ( ! is_string( $name ) )
		{
			throw new \InvalidArgumentException( "$name must be string or a QName instanxe" );
		}

		$types = SchemaTypes::getInstance();
		$attribute = $types->getElement( $name );

		if ( ! $attribute )
		{
			return null;
		}

		$result = new DOMSchemaAttribute();
		error_log( __CLASS__ . " need to populate the DOMSchemaAttribute instance" );
		return $result;
	}
325391
public function initialize($schema, $table=null)
    {
        $mapper = $this->_mapper($schema);
        $table = $table ? $this->_connection($schema)->table($table) : $mapper->table();

        $sequencePool = $this->_connection($schema)->sequencePool();
        $sequencePool->initialize();

        $columns = array();

        // build a map of properties to create
        foreach ($schema->properties() as $prop) {
            $columns[$prop->name] = $prop->type;

            // reset sequences as we go
            if (property_exists($prop->type, 'sequence')) {
                $sequencePool->delete($mapper->sequenceName($prop));
            }
        }

        $table->create($columns);

        return $this;
    }
290683
public function column($name)
    {
        $column = new ColumnSchema($this, $name);
        $this->columns[$name] = $column;
        return $column;
    }
29070
public static function getSchema($name) {
        if (!isset(self::$schemas[$name])) {
            try {
                self::$schemas[$name] = Schema::i($name);
            } catch (Exception $e) {
                return false;
            }
        }

        return self::$schemas[$name];
    }
1166113
private function findTableSchemas($schema = null)
    {
        $tableNames = $this->getTableNames($schema, true);

        if (is_callable($this->tableNameFilter)) {
            $tableNames = array_filter($tableNames,
                function($tableName) use ($schema) {
                    return call_user_func($this->tableNameFilter, $tableName, $schema);
                }
            );
        }

        $tableSchemas = array_map(
            function($tableName) use ($schema) {
                $tableSchema = new TableSchema();
                $tableNameFull = $schema === null ? $tableName : "$schema.$tableName";
                $this->resolveTableNames($tableSchema, $tableNameFull);
                return $tableSchema;
            },
            $tableNames);

        return $tableSchemas;
    }
472406
public function schema($schema = null) {
        if (!func_num_args()) {
            return $this->_schema;
        }
        $this->_schema = $schema;
        return $this;
    }
1307626
public static function create($name, $script)
    {
        if (!self::existe($name)) {
            $name = self::table($name);
            //
            self::$query = 'create table '.$name.'(';
            //
            $object = new self();
            $script($object);
            //
            $query = '';
            //
            for ($i = 0; $i < Collection::count(self::$colmuns); $i++) {
                $query .= ($i == (Collection::count(self::$colmuns) - 1)) ? self::$colmuns[$i] : self::$colmuns[$i].',';
            }
            //
            self::$query .= $query.') DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;';
            //
            return Database::exec(self::$query);
        } else {
            throw new SchemaTableExistsException($name);
        }
    }
127862
public function refreshTableSchema($name)
    {
        $rawName = $this->getRawTableName($name);
        unset($this->_tableMetadata[$rawName]);
        $this->_tableNames = [];
        /* @var $cache CacheInterface */
        $cache = is_string($this->db->schemaCache) ? Zilf::$app->get($this->db->schemaCache, false) : $this->db->schemaCache;
        if ($this->db->enableSchemaCache && $cache instanceof CacheInterface) {
            $cache->delete($this->getCacheKey($rawName));
        }
    }
982406
public function createTable($table, $schema)
    {
        //
        $columnsArray = [];

        // loop throut schema
        foreach ($schema as $field => $attributes) {
            if (is_numeric($field) && is_string($attributes)) {
                $field = $attributes;
                $attributes = [];
            }

            //
            $column = $this->columnDefinition($attributes, false);

            //
            $columnsArray[] = "`{$field}` {$column}";
        }

        // implode
        $columns = implode(',', $columnsArray);

        // template sql to create table
        $sql = "CREATE TABLE `{$table}` ({$columns})";

        // return the sql
        return $sql;
    }
161226
public function get($name) {
		if (!$this->definitions->has($name)) {
			$this->definitions->set($name, new Schema());
		}
		return $this->definitions->get($name);
	}
1107375
protected function _getSchema( $name )
	{
		if( !isset( $this->_schemas[$name] ) ) {
			return $this->_schema;
		}

		return $this->_schemas[$name];
	}
336704
public function dropTableSql(TableSchema $schema)
    {
        $sql = sprintf(
            'DROP TABLE %s',
            $this->_driver->quoteIdentifier($schema->name())
        );

        return [$sql];
    }