#!/usr/bin/perl -w
#
# revtext.pl
#
# J. Uckelman (uckelman@iastate.edu)
# 17 March 2001
#

require 5.005;
use DBI;

my $version = 0.1;
my $config = '/home/g1/bin/scripts.conf';

# load the config file 
eval { require $config; }; 
die "$0: $config: $@\n" if $@;
eval { require '/home/g1/bin/mysql.conf'; }; 
die "$0: mysql.conf: $@\n" if $@;

# connect to game database
$dbh = DBI->connect("DBI:mysql:database=$database;host=$host;port=$port", $user, $password);

my ($table, $column, $oldnum, $oldrev, $newnum, $newrev) = @ARGV[0 .. 5];

my $sth = $dbh->prepare("select $column from $table where number = $oldnum and revision = $oldrev");
$sth->execute;
my ($data) = $sth->fetchrow_array;
$sth->finish;

open OUT, ">$TMP/tmp" or die;
print OUT $data;
close OUT;

system "vim $TMP/tmp";

open IN, "<$TMP/tmp" or die;
$data = quotemeta(join '', <IN>);
close IN;

$data =~ s/\\%/%/gs;

$dbh->do("update $table set $column = '$data' where number = $newnum and revision = $newrev");

$dbh->disconnect;
