5 my $dsn = "DBI:mysql:blootbot:localhost";
6 my $dbh = DBI->connect($dsn, "USERNAME", "PASSWORD");
11 my $regex = '\\\\([\_\%])';
13 $query = "SELECT factoid_key,factoid_value from factoids";
14 my $sth = $dbh->prepare($query);
16 while (my @row = $sth->fetchrow_array) {
17 if ($row[0] =~ /$regex/) {
18 push(@factkey,$row[0]);
20 $factval{$row[0]} = $row[1] if ($row[1] =~ /$regex/);
25 print "scalar factkey => '". scalar(@factkey) ."'\n";
27 print "factkey => '$_'.\n";
29 $new =~ s/$regex/$1/g;
33 $query = "SELECT factoid_key FROM factoids where factoid_key=".
35 my $sth = $dbh->prepare($query);
37 if (scalar $sth->fetchrow_array) { # exist.
38 print "please remove $new or $_.\n";
42 $query = "UPDATE factoids SET factoid_key=".$dbh->quote($new).
43 " WHERE factoid_key=".$dbh->quote($_);
44 my $sth = $dbh->prepare($query);
50 print "scalar factval => '". scalar(keys %factval) ."\n";
51 foreach (keys %factval) {
52 print "factval => '$_'.\n";
54 my $old = $factval{$_};
56 $new =~ s/$regex/$1/g;
58 next if ($new eq $old);
60 $query = "UPDATE factoids SET factoid_value=".$dbh->quote($new).
61 " WHERE factoid_key=".$dbh->quote($fact);
62 my $sth = $dbh->prepare($query);