2
# Copyright (C) 2000, 2004 MySQL AB
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
$opt_help=$opt_Information=$opt_skip_use_db=0;
22
$opt_regexp=$opt_dbregexp=".*";
23
$opt_start_row=1; $opt_rows=9999999999;
25
GetOptions("Information","help","regexp=s","start_row=i","rows=i",
26
"dbregexp=s", "skip-use-db")
28
usage() if ($opt_help || $opt_Information);
30
$query=$search=$database=$set=""; $eoq=0;
33
next if (length($query) == 0 && /^\#/); # Skip comments
37
if ($query =~ /^use /i || $query =~ /^SET / ||
38
($query =~ /$opt_regexp/o && $database =~ /$opt_dbregexp/o))
40
if ($opt_skip_use_db && $query =~ /^use /i)
45
if ($opt_start_row <= 1)
49
print $database, $set;
53
last if (--$opt_rows == 0);
58
if ($query =~ /^use /)
63
elsif ($query =~ /^SET/)
73
$query=""; $search=""; $eoq=0;
84
for ($i=0 ; $i < length($row) ; $i++)
88
if (length($search) > 1)
90
next if (substr($row,$i,length($search)) ne $search);
91
$i+=length($search)-1;
94
elsif (substr($row,$i,1) eq '\\') # Escaped char in string
98
elsif (substr($row,$i,1) eq $search)
100
if (substr($row,$i+1,1) eq $search) # Double " or '
111
if (substr($row,$i,2) eq '/*') # Comment
116
elsif (substr($row,$i,1) eq "'" || substr($row,$i,1) eq '"')
118
$search=substr($row,$i,1);
121
$eoq=1 if (!length($search) && $row =~ /;\s*$/);
131
Prints all SQL queries that matches a regexp or contains a 'use
132
database' or 'set ..' command to stdout. A SQL query may contain
133
newlines. This is useful to find things in a MySQL update log.
135
$0 takes the following options:
137
--help or --Information
141
Print queries that matches this.
144
Start output from this row (first row = 1)
147
Don\'t include \'use database\' commands in the output.
150
Quit after this many rows.
154
$0 --regexp "problem_table" < update.log
156
$0 --regexp "problem_table" update-log.1 update-log.2