SchemaIterator

SchemaIterator iterates schema objects.

Summary
SchemaIteratorSchemaIterator iterates schema objects.
Variables
$open_comment
$tbl_name
Functions
newCreate a new SchemaIterator object with either a dbh or a file_itr.
_make_filtersCreate schema object filters from OptionParser options.
next_schema_objectReturn the next schema object or undef when no more schema objects.
_iterate_files
_iterate_dbh
database_is_allowed
table_is_allowed
engine_is_allowed
_d

Variables

$open_comment

my $open_comment

$tbl_name

my $tbl_name

Functions

new

sub new

Create a new SchemaIterator object with either a dbh or a file_itr.

Parameters

%argsArguments

Required Arguments

dbhdbh to iterate.  Mutually exclusive with file_itr.
file_itrFileIterator::get_file_itr() iterator for dump file.  Mutually exclusive with dbh.
OptionParserOptionParser object.  All filters are gotten from this obj: --databases, --tables, etc.
QuoterQuoter object.

Optional Arguments

SchemaSchema object to initialize while iterating.
MySQLDumpMySQLDump object to get CREATE TABLE when iterating dbh.
TableParserTableParser object to parse CREATE TABLE for tbl_struct.
keep_ddlKeep CREATE TABLE (default false)

Returns

SchemaIterator object

_make_filters

sub _make_filters

Create schema object filters from OptionParser options.  The OptionParser object passed to new() is checked for filter options like --database, --tables, --ignore-tables, etc.  For all such options, a hash is built keyed off the same option name.  So $filter{tables} represents --tables, etc.  Regex filters are pre-compiled.  It is very important to avoid auto-vivifying certain key-values; see below.  The filter hash is used in sub like database_is_allowed().

This sub is called from new().  That’s the only place and time it needs to be called because options shouldn’t change between runs.

Parameters

%argsArguments

Required Arguments

OptionParserOptionParser object.  All filters are gotten from this obj: --databases, --tables, etc.
QuoterQuoter object.

Returns

Hashref of filters keyed on corresponding option names.

next_schema_object

sub next_schema_object

Return the next schema object or undef when no more schema objects.  Only filtered schema objects are returned.  If iterating dump files (i.e. the obj was created with a file_itr arg), then the returned schema object will always have a ddl (see below).  But if iterating a dbh, then you must create the obj with a MySQLDump obj to get a ddl.  If this object was created with a TableParser, then the ddl, if present, is parsed, too.

Returns

Hashref of schema object with at least a db and tbl keys, like

{
   db         => 'test',
   tbl        => 'a',
   ddl        => 'CREATE TABLE `a` ( ...',  # if keep_ddl
   tbl_struct => <TableParser::parse()> hashref of parsed ddl,
}

The ddl is suitable for TableParser::parse().

_iterate_files

sub _iterate_files

_iterate_dbh

sub _iterate_dbh

database_is_allowed

sub database_is_allowed

table_is_allowed

sub table_is_allowed

engine_is_allowed

sub engine_is_allowed

_d

sub _d
my $open_comment
my $tbl_name
sub new
Create a new SchemaIterator object with either a dbh or a file_itr.
sub _make_filters
Create schema object filters from OptionParser options.
OptionParser parses command line options from a tool’s POD.
sub next_schema_object
Return the next schema object or undef when no more schema objects.
sub _iterate_files
sub _iterate_dbh
sub database_is_allowed
sub table_is_allowed
sub engine_is_allowed
sub _d
sub get_file_itr
Quoter handles value quoting, unquoting, escaping, etc.
Schema encapsulates a data structure representing databases and tables.
MySQLDump gets CREATE TABLE defs from MySQL.
TableParser parses SHOW CREATE TABLE.
sub parse
Parse SHOW CREATE TABLE.
Close