Commit b764e169 authored by Jim Winstead's avatar Jim Winstead

Add support for wildcards in mysql_convert_table_format, and add

short options for all of the long options. (Bug #30373, original
contribution by Tobias Asplund)
parent 97d02027
...@@ -27,9 +27,21 @@ $opt_engine="MYISAM"; ...@@ -27,9 +27,21 @@ $opt_engine="MYISAM";
$opt_port=0; $opt_port=0;
$exit_status=0; $exit_status=0;
GetOptions("force","help","host=s","password=s","user=s","engine|type=s","verbose","version","socket=s", "port=i") || GetOptions(
usage(0); "e|engine|type=s" => \$opt_type,
"f|force" => \$opt_force,
"help|?" => \$opt_help,
"h|host=s" => \$opt_host,
"p|password=s" => \$opt_password,
"u|user=s" => \$opt_user,
"v|verbose" => \$opt_verbose,
"V|version" => \$opt_version,
"S|socket=s" => \$opt_socket,
"P|port=i" => \$opt_port
) || usage(0);
usage($opt_version) if ($#ARGV < 0 || $opt_help || $opt_version); usage($opt_version) if ($#ARGV < 0 || $opt_help || $opt_version);
$opt_database=shift(@ARGV); $opt_database=shift(@ARGV);
if (grep { /^$opt_engine$/i } qw(HEAP MEMORY BLACKHOLE)) if (grep { /^$opt_engine$/i } qw(HEAP MEMORY BLACKHOLE))
...@@ -54,21 +66,29 @@ $dbh = DBI->connect("DBI:mysql:$opt_database:${opt_host}$connect_opt", ...@@ -54,21 +66,29 @@ $dbh = DBI->connect("DBI:mysql:$opt_database:${opt_host}$connect_opt",
{ PrintError => 0}) { PrintError => 0})
|| die "Can't connect to database $opt_database: $DBI::errstr\n"; || die "Can't connect to database $opt_database: $DBI::errstr\n";
if ($#ARGV < 0) my @tables;
push(@ARGV, "%") if(!@ARGV);
foreach $pattern (@ARGV)
{ {
# Fetch all table names from the database
my ($sth,$row); my ($sth,$row);
$sth=$dbh->prepare("show tables"); $sth=$dbh->prepare("SHOW TABLES LIKE ?");
$sth->execute || die "Can't get tables from $opt_database; $DBI::errstr\n"; $rv= $sth->execute($pattern);
if(!int($rv))
{
warn "Can't get tables matching '$pattern' from $opt_database; $DBI::errstr\n";
exit(1) unless $opt_force;
}
while (($row = $sth->fetchrow_arrayref)) while (($row = $sth->fetchrow_arrayref))
{ {
push(@ARGV,$row->[0]); push(@tables, $row->[0]);
} }
$sth->finish; $sth->finish;
} }
print "Converting tables:\n" if ($opt_verbose); print "Converting tables:\n" if ($opt_verbose);
foreach $table (@ARGV) foreach $table (@tables)
{ {
my ($sth,$row); my ($sth,$row);
...@@ -106,40 +126,41 @@ sub usage ...@@ -106,40 +126,41 @@ sub usage
Conversion of a MySQL tables to other storage engines Conversion of a MySQL tables to other storage engines
Usage: $0 database [tables] Usage: $0 database [table[ table ...]]
If no tables has been specifed, all tables in the database will be converted. If no tables has been specifed, all tables in the database will be converted.
You can also use wildcards, ie "my%"
The following options are available: The following options are available:
--force -f, --force
Continue even if there is some error. Continue even if there is some error.
--help -?, --help
Shows this help Shows this help
--engine='engine' -e, --engine=ENGINE
Converts tables to the given storage engine (Default: $opt_engine) Converts tables to the given storage engine (Default: $opt_engine)
--host='host name' (Default $opt_host) -h, --host=HOST
Host name where the database server is located. Host name where the database server is located. (Default: $opt_host)
--password='password' -p, --password=PASSWORD
Password for the current user. Password for the current user.
--port=port -P, --port=PORT
TCP/IP port to connect to if host is not "localhost". TCP/IP port to connect to if host is not "localhost".
--socket='/path/to/socket' -S, --socket=SOCKET
Socket to connect with. Socket to connect with.
--user='user_name' -u, --user=USER
User name to log into the SQL server. User name to log into the SQL server.
--verbose -v, --verbose
This is a test specific option that is only used when debugging a test. This is a test specific option that is only used when debugging a test.
Print more information about what is going on. Print more information about what is going on.
--version -V, --version
Shows the version of this program. Shows the version of this program.
EOF EOF
exit(1); exit(1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment