in reply to Rows fail to delete without error

Well, there's the usual part about use strict. If you are using strict, then you're declaring these variables outside of your subroutine. From the way you have the last two lines of the subroutine, it appears to me that you are setting global variables and having other subs rely on them. This is difficult because it can be a problem telling where a variable is initialized, changed, or reused.

I can't tell from your code where the problem is (am I missing something simple?), but you can simplify some stuff:

$sth = $dbh->prepare("DELETE FROM $holding_table WHERE year=? AND month=? AND day=? AND time_start=? AND time_end=? AND title=?"); $sth->bind_param(1, "$key[1]"); $sth->bind_param(2, "$key[2]"); $sth->bind_param(3, "$key[3]"); $sth->bind_param(4, "$key[4]"); $sth->bind_param(5, "$key[5]"); $sth->bind_param(6, "$key[6]"); $sth->execute();

That can become:

$sth = $dbh->prepare("DELETE FROM $holding_table WHERE year=? AND month=? AND day=? AND time_start=? AND time_end=? AND title=?"); $sth->execute( @key );

Questions:

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: Re: Rows fail to delete without error
by extremely (Priest) on Apr 08, 2002 at 21:31 UTC
    Shouldn't that $sth->execute( @key ); actually be $sth->execute( @key[1..6] );?

    --
    $you = new YOU;
    honk() if $you->love(perl)

Re: Re: Rows fail to delete without error
by jerrygarciuh (Curate) on Apr 08, 2002 at 21:34 UTC
    Thx for the reply Ovid.
    The DBI object is instantiated like so:
    my $dbh = DBI->connect($dsn, $user, $password,{'RaiseError' => 1});
    I can't $sth->execute( @key ); as I am using elements 1 - 6 and not 0 or >6 . Element zero is the word radio to distinguish the radio values on which I am acting from the other params.
    The real puzzler here is that the data is the same for each branch and if we are Adding we move the row then delete if we are just Deeting we execute code identical to that which deletes the rows successfully if Add was chosen.

    Anyway I can't see that the split is at fault in one branch and not the other. Oh and yes I am running under strict and -w. Maybe I should create a trash table and just move the rows there and then delete the from $holding_table thereby replicating the success I have when Adding. lol..sigh.
    Thx for looking at it!
    jg