Perly Eyed has asked for the wisdom of the Perl Monks concerning the following question:

I am having difficulty deleting rows in DBD::AnyData.
Below is a sample that does not work for me. The return from the do() says 4 rows, but then the count(*) says there are still 4 rows in the table.

Thanks for any information

installation specs:

Linux myserver 2.6.26-2-686 #1 SMP Wed May 12 21:56:10 UTC 2010 i686 GNU/Linux
This is perl, v5.10.0 built for i486-linux-gnu-thread-multi
Module id = DBD::AnyData
DESCRIPTION DBI access to XML, CSV and other formats
CPAN_USERID JZUCKER (Jeff Zucker <jeff@vpservices.com>)
CPAN_VERSION 0.110


use strict; use DBI; my($sql, $sth); my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); $dbh->{TraceLevel} = 1; $dbh->func( 'obs', 'CSV', [<DATA>], 'ad_import'); $sql = "delete from obs"; my $ret = $dbh->do($sql); print "ret: $ret\n"; $sql = "select count(*) from obs"; $sth = $dbh->prepare($sql); $sth->execute(); my $count = $sth->fetchrow_array(); $sth->finish(); print "$count rows in obs after delete\n"; __DATA__ "obs_id","flow_nm","event_type_nm","event_subtype_nm","event_selected" 1,nw,flow_nw_pyro,pyro_1_less,0 2,nw,flow_nw_pyro,pyro_1_2,0 3,nw,flow_nw_pyro,pyro_2_3,0 4,nw,flow_nw_pyro,pyro_3_more,1

Replies are listed 'Best First'.
Re: DBD::AnyData delete rows
by ahmad (Hermit) on Aug 06, 2010 at 23:51 UTC

    What you're doing is "loading data in memory" ... And you're not committing the changes you've made.

    This is explained clearly in the docs DBD::AnyData

      I have tried $dbh->commit() with no difference. Auto commit is on by default and you can't turn it off.
      Also tried with ad_catalog and ad_import with no difference.
      Inserts and updates work very well, just deletes don't work.
      Thanks for you response
Re: DBD::AnyData delete rows
by apl (Monsignor) on Aug 07, 2010 at 13:21 UTC
    You should replace
    my $ret = $dbh->do($sql);
    with
    my $ret = $dbh->do($sql) or die $dbh->errstr;

    The delete could be failing for any of a dozen reasons, all on the database side. (You should make similar changes for all other DBI calls, as well.)