Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Rows fail to delete without error

by Ovid (Cardinal)
on Apr 08, 2002 at 21:14 UTC ( [id://157560]=note: print w/replies, xml ) Need Help??


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:

  • Do you set the RaiseError flag when you instantiate the DBI object?
  • Are you sure that your values from the split are correct? You're splitting on a comma and an extra comma could make life difficult.
  • Have you tried printing out all of the @key values and creating the SQL by hand? If even one of your values does not match a value in the database, the SQL will fail.

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://157560]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-19 05:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found