-
Notifications
You must be signed in to change notification settings - Fork 0
/
Manadmin.pm
35 lines (32 loc) · 866 Bytes
/
Manadmin.pm
1
2
3
4
5
6
7
8
9
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
package Manadmin;
use ManateeSQL;
sub dumpTable{
my ($sql,$table,$file) = @_;
if(&ManateeSQL::table_exists($sql,$table)){
my $cmd = qq(SHOW CREATE TABLE $table;);
$result = &ManateeSQL::doQuery(0,$sql,$cmd);
if ($result) {
print $file "$result->[1]";
}
my $cmd = qq(SELECT * FROM $table;);
$result = &ManateeSQL::doQuery(1,$sql,$cmd);
$cmd = qq(SHOW COLUMNS FROM $table);
$columns = &ManateeSQL::doQuery(1,$sql,$cmd);
foreach my $row (@{$result}) {
my $line = "INSERT INTO $table (";
my $line2 = ") VALUES(";
foreach my $cname (@{$columns}) {
$line = "$line$cname->{Field},";
$line2 = "$line2'$row->{$cname->{Field}}',";
}
$line = substr($line,0,length($line)-1);
$line2 = substr($line2,0,length($line2)-1);
$line2 = "$line2);\n";
print $file "$line$line2";
}
return 0;
} else {
return -1;
}
}
1;