Generates validation rules for the specified table.
@param \yii\db\TableSchema $table the table schema
@return array the generated validation rules
192680
protected function generateColumns($table)
    {
        $columns = [];
        $needPK = true;
        foreach ($table->columns as $column) {
            if ($column->autoIncrement) {
                $columns[$column->name] = $column->type == Schema::TYPE_BIGINT ? '$this->bigPrimaryKey()' : '$this->primaryKey()';
                $needPK = false;
                continue;
            }
            $columns[$column->name] = $this->getSchemaType($column);
        }
        if ($needPK && !empty($table->primaryKey)) {
            $pks = implode(']], [[', $table->primaryKey);
            $columns[0] = "PRIMARY KEY ([[{$pks}]])";
        }

        return $columns;
    }
645317
public function getTableSchema($table)
    {
        $backup = [];
        //get the schema
        $schema = $this->getColumns($table);
        if (count($schema)) {
            //lets rebuild this schema
            $query = $this->getCreateQuery()->setName($table);

            foreach ($schema as $field) {
                //first try to parse what we can from each field
                $fieldTypeArray = explode(' ', $field['Type']);
                $typeArray = explode('(', $fieldTypeArray[0]);
                
                $type = $typeArray[0];
                
                $length = null;
                if (isset($typeArray[1])) {
                    $length = str_replace(')', '', $typeArray[1]);
                }
                
                $attribute = isset($fieldTypeArray[1]) ? $fieldTypeArray[1] : null;
                
                $null = strtolower($field['Null']) == 'no' ? false : true;
                
                $increment = strtolower($field['Extra']) == 'auto_increment' ? true : false;
                
                //lets now add a field to our schema class
                $query->addField($field['Field'], [
                    'type'              => $type,
                    'length'            => $length,
                    'attribute'         => $attribute,
                    'null'              => $null,
                    'default'           => $field['Default'],
                    'auto_increment'    => $increment
                ]);
                
                //set keys where found
                switch ($field['Key']) {
                    case 'PRI':
                        $query->addPrimaryKey($field['Field']);
                        break;
                    case 'UNI':
                        $query->addUniqueKey($field['Field'], [$field['Field']]);
                        break;
                    case 'MUL':
                        $query->addKey($field['Field'], [$field['Field']]);
                        break;
                }
            }
            
            //store the query but dont run it
            $backup[] = $query;
        }
        
        //get the rows
        $rows = $this->query($this->getSelectQuery()->from($table)->getQuery());
        
        if (count($rows)) {
            //lets build an insert query
            $query = $this->getInsertQuery($table);

            foreach ($rows as $index => $row) {
                foreach ($row as $key => $value) {
                    $query->set($key, $value, $index);
                }
            }
            
            //store the query but dont run it
            $backup[] = $query->getQuery(true);
        }
        
        return implode("\n\n", $backup);
    }
1168211
function generateTableSchema( $tableName, $table, $params )
    {
        return $this->generateTableSQL( $tableName, $table, $params, false, false );
    }
700514
public function PrimaryKeyRange($Table) {
      $Model = $this->CreateModel($Table);
      
      $Data = $this->SQL
         ->Select($Model->PrimaryKey, 'min', 'MinValue')
         ->Select($Model->PrimaryKey, 'max', 'MaxValue')
         ->From($Table)
         ->Get()->FirstRow(DATASET_TYPE_ARRAY);
      
      if ($Data)
         return array($Data['MinValue'], $Data['MaxValue']);
      else
         return array(0, 0);
   }
481259
protected function generateProperties($table)
    {
        $properties = [];
        foreach ($table->columns as $column) {
            $columnPhpType = $column->phpType;
            if ($columnPhpType === 'integer') {
                $type = 'int';
            } elseif ($columnPhpType === 'boolean') {
                $type = 'bool';
            } else {
                $type = $columnPhpType;
            }
            $properties[$column->name] = [
                'type' => $type,
                'name' => $column->name,
                'comment' => $column->comment,
            ];
        }

        return $properties;
    }
884456
public function generateExistRules($table, $columnBehaviors)
    {
        $rules = [];
        foreach ($table->foreignKeys as $refs) {
            $refClassName = $this->generateClassName($refs[0]);
            unset($refs[0]);
            $attributes = implode("', '", array_keys($refs));
            $targetAttributes = [];
            foreach ($refs as $key => $value) {
                if (isset($columnBehaviors[$key]) && $columnBehaviors[$key] !== false) {
                    continue 2;
                }
                $targetAttributes[] = "'$key' => '$value'";
            }
            $targetAttributes = implode(', ', $targetAttributes);
            $rules[] = "[['$attributes'], 'exist', 'skipOnError' => true, "
                . "'targetClass' => $refClassName::className(), 'targetAttribute' => [$targetAttributes]],";
        }
        return $rules;
    }
376876
protected function parseSchemaAndTable($table)
    {
        $table = explode('.', $table);

        if (is_array($schema = $this->connection->getConfig('schema'))) {
            if (in_array($table[0], $schema)) {
                return [array_shift($table), implode('.', $table)];
            }

            $schema = head($schema);
        }

        return [$schema ?: 'public', implode('.', $table)];
    }
126121
protected function buildRows(Table $table)
	{
		//Generate each row
		$rows = array();

		foreach ( $table->getRows() as $row )
		{
			//Build the cells for each row
			$cells = array();

			foreach ( $row as $cell )
			{
				$cells[] = $this->cell($cell);
			}

			$rows[] = $this->row($row, $cells);
		}

		return $rows;
	}
828285
public static function get_table_columns( $table ) {

		global $wpdb;

		self::query( "SHOW COLUMNS FROM `{$table}` " );

		$table_columns = $wpdb->last_result;

		$table_cols_and_types = array();

		foreach ( $table_columns as $table_col ) {
			// Get only the type, not the attributes.
			if ( false === strpos( $table_col->Type, '(' ) ) {
				$modified_type = $table_col->Type;
			} else {
				$modified_type = substr( $table_col->Type, 0, ( strpos( $table_col->Type, '(' ) ) );
			}

			$table_cols_and_types[ $table_col->Field ] = $modified_type;
		}

		return $table_cols_and_types;
	}
15974
public function generate($table)
    {
        $this->checkTable($table);

        $config = $this->Table->behaviors()->Proffer->config();

        foreach ($config as $field => $settings) {
            $records = $this->{$this->Table->alias()}->find()
                ->select([$this->Table->primaryKey(), $field, $settings['dir']])
                ->where([
                    "$field IS NOT NULL",
                    "$field != ''"
                ]);

            foreach ($records as $item) {
                if ($this->param('verbose')) {
                    $this->out(
                        __('Processing ' . $this->Table->alias() . ' ' . $item->get($this->Table->primaryKey()))
                    );
                }

                if (!empty($this->param('path-class'))) {
                    $class = (string)$this->param('path-class');
                    $path = new $class($this->Table, $item, $field, $settings);
                } else {
                    $path = new ProfferPath($this->Table, $item, $field, $settings);
                }

                if (!empty($this->param('image-class'))) {
                    $class = (string)$this->param('image-class');
                    $transform = new $class($this->Table, $path);
                } else {
                    $transform = new ImageTransform($this->Table, $path);
                }

                $transform->processThumbnails($settings);

                if ($this->param('verbose')) {
                    $this->out(__('Thumbnails regenerated for ' . $path->fullPath()));
                } else {
                    $this->out(__('Thumbnails regenerated for ' . $this->Table->alias() . ' ' . $item->get($field)));
                }
            }
        }

        $this->out($this->nl(0));
        $this->out(__('<info>Completed</info>'));
    }
499095
private function getFields($table)
    {
        $fields = $this->entity->getFieldNames();
        if (empty($this->with) && $this->alias === null) {
            return $fields;
        }

        $table = $this->getTableAlias($table);

        $prefixIfMissing = function ($field) use ($table) {
            if (strpos($field, '.') !== false) {
                return $field;
            }

            return $table . '.' . $field;
        };

        return array_map($prefixIfMissing, $fields);
    }
1205531
protected function generateIndexes($table): array
    {
        $result  = [];
        $indexes = $table->getIndexes();
        foreach ($indexes as $index) {
            if ($index->isPrimary()) {
                continue;
            }
            $indexObject = new Index($index);
            $line        = $indexObject->generateAddMigration();
            $result[]    = $line.';';
        }

        return $result;
    }
1263500
public function generate($table, $schema, $database)
    {
        $this->database = $database;
        $columns = $schema->listTableColumns($table);
        if (empty($columns)) {
            return false;
        }

        $indexParser = new IndexParser($table, $schema);
        $fields = $this->setEnum($this->getFields($columns, $indexParser), $table);
        $indexes = $this->getMultiFieldIndexes($indexParser);
        return array_merge($fields, $indexes);
    }
1045794
private function getTextFields($table): array
    {
        $columnsData = $this->model->getReadConnection()->describeColumns($table);
        $textFields = [];

        foreach ($columnsData as $column) {
            switch ($column->getType()) {
                case \Phalcon\Db\Column::TYPE_VARCHAR:
                case \Phalcon\Db\Column::TYPE_TEXT:
                    $textFields[] = $column->getName();
                    break;
            }
        }

        return $textFields;
    }
1289119
public function getValidationRules()
    {
        $rules = parent::getValidationRules();

        foreach ($rules as &$rule) {
            if ($rule !== '_unique') {
                continue;
            }

            $model = $this->resolvePath();
            $table = $model->getTable();

            $rule = 'unique:'.$table.','.$this->getModelAttributeKey();
            if ($model->exists) {
                $rule .= ','.$model->getKey();
            }
        }
        unset($rule);

        return [$this->getPath() => $rules];
    }
1044039
protected function buildHeaders(Table $table)
	{
		//Generate each row
		$rows = array();

		foreach ( $table->getHeaderRows() as $row )
		{
			//Build the cells for each row
			$cells = array();

			foreach ( $row as $cell )
			{
				$cells[] = $this->headerCell($cell);
			}

			$rows[] = $this->headerRow($row, $cells);
		}

		return $rows;
	}
252197
public function getTable($table)
    {
        return array_merge(
            $this->cache['tables'][$table],
            [
                'fields'      => $this->cache['fields'][$table] ?? [],
                'constraints' => $this->cache['constraints'][$table] ?? [],
            ]
        );
    }