I once hacked the following in Perl:use strict;
no strict 'refs';
use Win32::OLE qw (in);
use XML::Simple;
use MIME::Base64 ();
use DBI;
#use EaSimulator;
#EaSimulator->new ({'PACKAGE'=>"{088A0FC2-E1E4-41d8-9661-900C18E2243D}"});
my %tableData =
('t_image' => {PRIMARY => 'ImageID', COLUMNS => ['Type', 'Name', 'ImageID', 'Image']},
't_propertytypes' => {PRIMARY => 'Property', COLUMNS => ['Property', 'Description', 'Notes']},
't_statustypes' => {PRIMARY => 'Status', COLUMNS => ['Status', 'Description']});
my $rep = $ENV{'REP'};
my $dbName = $rep->ConnectionString;
my $dbi;
if ($dbName =~ /\.eap$/i) { $dbi = "dbi:ADO:Data Source=$dbName;Provider=Microsoft.Jet.OLEDB.4.0" }
elsif ($dbName =~ /Data Source=([^;]*)/) { $dbi = "dbi:ODBC:$1" }
else { die "can not figure out DB type from $dbName" }
my $dbh = DBI->connect($dbi, "") or die "Can't connect to $dbi";
my $fn = $rep->xmiPath($rep->GetTreeSelectedObject()) . 'RefData.xml';
my $xs = XML::Simple->new(); # convert the XML return string into a hash
my $ref = $xs->XMLin($fn);
for my $key (keys %{$ref->{'DataSet'}}) {
import ($ref->{'DataSet'}->{$key});
}
return 1;
sub import {
my $data = shift;
my $table = $data->{'table'};
my $primary = $tableData{$table}->{PRIMARY} or return;
my %xref;
my $columns = "`" . join ("`, `", @{$tableData{$table}->{COLUMNS}}) . "`";
my $sth;
$sth = $dbh->prepare("delete * from $table where 1");
$sth->execute();
if (ref ($data->{'DataRow'}) eq "HASH") {
$data->{'DataRow'} = [$data->{'DataRow'}];
}
for (in @{$data->{'DataRow'}}) {
my $row = $_->{ 'Column'};
next if $#{$tableData{$table}->{COLUMNS}} < 0;
my $sql;
$sql = "INSERT INTO $table (";
my $values = "";
my $sep = "";
for my $col (@{$tableData{$table}->{COLUMNS}}) {
if ($row->{$col}->{'dt:dt'} eq "bin.base64") {
$values .= $sep . '?';
} else {
next unless $row->{$col}->{'value'};
$values .= $sep . quote ($row->{$col}->{'value'});
}
$sql .= "$sep`$col`";
$sep = ", ";
}
$sql .= ") VALUES ($values)";
$sth = $dbh->prepare($sql);
my $param = 0;
for my $col (@{$tableData{$table}->{COLUMNS}}) {
if ($row->{$col}->{'dt:dt'} eq "bin.base64") {
$param++;
$sth->bind_param($param, MIME::Base64::decode($row->{$col}->{'content'}), DBI::SQL_BLOB);
}
}
$sth->execute();
}
}
sub quote {
$_ = shift();
s/'/''/gm;
s/‰/ä/gm;
s/ˆ/ö/gm;
s/¸/ü/gm;
s/ƒ/Ä/gm;
s/÷/Ö/gm;
s/‹/Ü/gm;
s/[ch64258]/ß/gm;
return "'$_'";
}
I know that for a VB programmer it looks as if an armadillo has been rolled over the keyboard, but it's all I have.
q.