MySQL::Dump::Parser::XS - mysqldump SQL parser
use MySQL::Dump::Parser::XS;
open my $fh, '<:encoding(utf-8)', 'backup.sql' or die $!;
my %rows;
my $parser = MySQL::Dump::Parser::XS->new;
while (my $line = <$fh>) {
my @rows = $parser->parse($line);
my $table = $parser->current_target_table();
push @{ $rows{$table} } => @rows if $table;
}
for my $table ($parser->tables()) {
my @columns = $parser->columns($table);
my $row = $rows{$table};
print "[$table] id:$row->{id}\n";
}
MySQL::Dump::Parser::XS is mysqldump
parser written in C/XS.
This module provides schema/data loader from mysqldump
output SQL directly. No need mysqld
.
Creates a new parser instance. This manages parsing states and table's meta information in the parsing context.
Re-initialize parsing context.
Parse a line of mysqldump
output.
Get current target table name in the parsing context.
Get column names as LIST for the table of $table_name
.
This method can get columns from already parsed tables only.
Get table names as LIST. This method can get tables from already parsed tables only.
Some mysqldump
output include poor table schema information only.
So if you just need rich table schema information, I suggest using DBIx::Inspector to solve the problem.
Copyright (C) karupanerura.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
karupanerura karupa@cpan.org