dumpdb 765 Bytes
Newer Older
1 2
#!/usr/bin/perl -w

Leigh B. Stoller's avatar
Leigh B. Stoller committed
3 4 5 6 7 8 9
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# All rights reserved.
#


10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
# This scripts takes a DB and a select statement and dumps the
# results of the table in a format that can easily be inserted into
# atest script for use with tb_compare.

use DBI;

if ($#ARGV != 1) {
    print STDERR "Syntax: $0 <db> <query>\n";
    exit(1);
}

($db,$query) = @ARGV;

$dbh = DBI->connect("DBI:mysql:database=$db;host=localhost") || 
	die "Could not connect to DB.\n";
$sth = $dbh->prepare($query);
$sth->execute;

print "\@result = (\n";
while (@row = $sth->fetchrow_array) {
    print "[\"" . $row[0] . "\"";
    foreach $element (@row[1..$#row]) {
	print ",\"$element\""
    }
    print "\],\n";
}
print ");\n";