# always: use strict; use warnings; use DBI; my $table = 'users'; my $format = 'XML'; my $file = 'eadata.xml'; my $dbh = DBI->connect('dbi:AnyData(RaiseError => 1):'); # insert a new record in to the memory table 'users' $dbh->func( $table, $format, $file, 'ad_import'); # Select data from users my $sql1 = qq{ SELECT * FROM $table }; my $sth = $dbh->prepare($sql1); $sth->execute(); while (my $row = $sth->fetchrow_hashref){ print "Row:\n"; while (my ($key, $value) = each (%{$row})) { print " $key: $value\n"; } } # Insert a new record in to the memory table 'users' my $sql2 = qq{ INSERT INTO users (name, agency, email, org, mailstop, phone, title +) VALUES (?, ?, ?, ?, ?, ?, ?) }; $sth = $dbh->prepare($sql2); # It's easy if we have the data in a hash my $users = { name => 'Testing', agency => 'TT', email => 'test@abc.com', org => 'ABC', mailstop => 'X159', phone => '(555) 123-4567', title => 'Other', }; # Transform hash into two arrays my @fields = keys %{$users}; my @values = map { $users->{$_} } @fields; # And use a generic insert statement # code stolen from the IBPerl module examples ;) $sql2 = "INSERT INTO $table (" . join( ',', @fields ) . ') VALUES (' . ( '?,' x $#fields ) . "?)"; # print "sql=", $sql2, "\n"; $sth->execute(@values); print "\nLet's see the results:\n"; $sth = $dbh->prepare($sql1); $sth->execute(); while (my $row = $sth->fetchrow_hashref){ print "Row:\n"; while (my ($key, $value) = each (%{$row})) { print " $key: $value\n"; } }
In reply to Re: Saving data to XML file using DBD::AnyData
by stefbv
in thread Saving data to XML file using DBD::AnyData
by warsting
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |