2 Einträge, 1 Seite |
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
36
for ('mysql', $db)
{ my $sth = $dbh->prepare("show tables from $_");
$sth->execute();
while (my $table = $sth->fetchrow_arrayref())
{ $table = $table->[0];
my $filename = "save_db_$_/$table.sql";
open FILE, "> $filename" or die "open $filename\n$!\n";
my $sth = $dbh->prepare("show create table $_.$table");
$sth->execute();
while (my $create = $sth->fetchrow_arrayref())
{ print "$_.$create->[0]\n";
$create = $create->[1];
print FILE
"use $_;\n",
"$create;\n"
or die "print $filename\n$!\n";
}
$sth->finish();
$sth = $dbh->prepare("select * from $_.$table");
$sth->execute();
while (my $value = $sth->fetchrow_arrayref())
{ print FILE
"insert into $table ("
.join(',', @{$sth->{NAME}})
.") values ("
# .join(',', map $dbh->quote($_), @$value) # das Problem
.join(',', map mysql_quote($_), @$value) # so funktioniert's
.");\n"
or die "print $filename\n$!\n";
}
$sth->finish();
close FILE or die "close $filename\n$!\n";
}
$sth->finish();
}
$dbh->disconnect();
1
2
3
4
5
6
7
8
sub mysql_quote
{ local $_ = shift;
defined $_ or return 'NULL';
s/\'/\\'/g;
s/\x0d/\\r/g;
s/\x0a/\\n/g;
return "'$_'";
}
1
2
3
4
1999-08-22 Jochen Wiedmann <joe@ispsoft.de> (1.2203)
* dbd/dbd.xs.in: Fixed a memory leak in $dbh->quote().
Arun Bhalla <abhalla@usgs.gov>
2 Einträge, 1 Seite |