public static function getFields($statement)
    {
        if (empty($statement->fields)
            || (! is_array($statement->fields))
            || (! $statement->options->has('TABLE'))
        ) {
            return [];
        }

        $ret = [];

        foreach ($statement->fields as $field) {
            // Skipping keys.
            if (empty($field->type)) {
                continue;
            }

            $ret[$field->name] = [
                'type' => $field->type->name,
                'timestamp_not_null' => false,
            ];

            if ($field->options) {
                if ($field->type->name === 'TIMESTAMP') {
                    if ($field->options->has('NOT NULL')) {
                        $ret[$field->name]['timestamp_not_null'] = true;
                    }
                }

                if ($option = $field->options->has('DEFAULT')) {
                    $ret[$field->name]['default_value'] = $option;
                    if ($option === 'CURRENT_TIMESTAMP') {
                        $ret[$field->name]['default_current_timestamp'] = true;
                    }
                }

                if ($option = $field->options->has('ON UPDATE')) {
                    if ($option === 'CURRENT_TIMESTAMP') {
                        $ret[$field->name]['on_update_current_timestamp'] = true;
                    }
                }

                if ($option = $field->options->has('AS')) {
                    $ret[$field->name]['generated'] = true;
                    $ret[$field->name]['expr'] = $option;
                }
            }
        }

        return $ret;
    }
public static function getFields($statement)
    {
        if (empty($statement->fields)
            || (! is_array($statement->fields))
            || (! $statement->options->has('TABLE'))
        ) {
            return [];
        }

        $ret = [];

        foreach ($statement->fields as $field) {
            // Skipping keys.
            if (empty($field->type)) {
                continue;
            }

            $ret[$field->name] = [
                'type' => $field->type->name,
                'timestamp_not_null' => false,
            ];

            if ($field->options) {
                if ($field->type->name === 'TIMESTAMP') {
                    if ($field->options->has('NOT NULL')) {
                        $ret[$field->name]['timestamp_not_null'] = true;
                    }
                }

                if ($option = $field->options->has('DEFAULT')) {
                    $ret[$field->name]['default_value'] = $option;
                    if ($option === 'CURRENT_TIMESTAMP') {
                        $ret[$field->name]['default_current_timestamp'] = true;
                    }
                }

                if ($option = $field->options->has('ON UPDATE')) {
                    if ($option === 'CURRENT_TIMESTAMP') {
                        $ret[$field->name]['on_update_current_timestamp'] = true;
                    }
                }

                if ($option = $field->options->has('AS')) {
                    $ret[$field->name]['generated'] = true;
                    $ret[$field->name]['expr'] = $option;
                }
            }
        }

        return $ret;
    }
public static function getFields ( $ statement ) { if ( empty ( $ statement -> fields ) || ( ! is_array ( $ statement -> fields ) ) || ( ! $ statement -> options -> has ( 'TABLE' ) ) ) { return [ ] ; } $ ret = [ ] ; foreach ( $ statement -> fields as $ field ) { // Skipping keys. if ( empty ( $ field -> type ) ) { continue ; } $ ret [ $ field -> name ] = [ 'type' => $ field -> type -> name , 'timestamp_not_null' => false , ] ; if ( $ field -> options ) { if ( $ field -> type -> name === 'TIMESTAMP' ) { if ( $ field -> options -> has ( 'NOT NULL' ) ) { $ ret [ $ field -> name ] [ 'timestamp_not_null' ] = true ; } } if ( $ option = $ field -> options -> has ( 'DEFAULT' ) ) { $ ret [ $ field -> name ] [ 'default_value' ] = $ option ; if ( $ option === 'CURRENT_TIMESTAMP' ) { $ ret [ $ field -> name ] [ 'default_current_timestamp' ] = true ; } } if ( $ option = $ field -> options -> has ( 'ON UPDATE' ) ) { if ( $ option === 'CURRENT_TIMESTAMP' ) { $ ret [ $ field -> name ] [ 'on_update_current_timestamp' ] = true ; } } if ( $ option = $ field -> options -> has ( 'AS' ) ) { $ ret [ $ field -> name ] [ 'generated' ] = true ; $ ret [ $ field -> name ] [ 'expr' ] = $ option ; } } } return $ ret ; }
Gets fields of the table.

@param CreateStatement $statement the statement to be processed

@return array
Gets fields of the table .