A working example, for select and insert from/into in memory table 'users'. Put the XML from the DATA section in eadata.xml.
# 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.