List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:May 3 2001 1:48am
Subject:Re: DELETE question
View as plain text  
At 1:43 PM -0500 5/2/01, Dawn H wrote:
>Anybody got a clue why this isn't deleting? The number is input in the
>previous section of code and I know it works correctly, but for some reason

How do you know?

>when it gets to here, it just skips to view (apparently), (even if I # out
>the Lock lines, so it isn't a lock problem). Am I going about getting the
>number into the query in the wrong way? If so, what is the correct manner to
>achieve this?
>Thanks in advance for your help,
>Dawn H
>-----CODE BELOW-----
>sub delete {
>  $num=param('delete');
>  $num=$dbh->quote($num);
>  GET_LOCK("edit",10)
>  or bail_out("Cannot get lock, please wait a moment and try again");

What's the deal with this? GET_LOCK() is a MySQL function, but it looks
like you're executing executing it as a Perl function?

>  $sth = $dbh->prepare("DELETE FROM database WHERE id=$num")

Is database a database name or a table name?

>  or bail_out("Cannot prepare to be deleted");
>  $sth->execute()
>  or bail_out("Cannot delete");
>  RELEASE_LOCK("edit")
>  or bail_out("An error occurred when attempting to release lock");

Ditto for RELEASE_LOCK().

I suggest you use trace() to turn on debugging, or enable RaiseError
when you connect to MySQL to force errors to terminate your program with
an error message.

>  view();


- For a DELETE, you don't need prepare() + execute().  Just use do().
- You don't need GET_LOCK() and RELEASE_LOCK() anyway for a single
   statement. The DELETE will execute atomically.  MySQL will lock the
   table for your automatically while it's processing the DELETE.

But it does look like you're quoting the number properly before inserting
it into the query string.

Paul DuBois, paul@stripped
select query questionJon Rosenberg2 May
  • RE: select query questionBraxton Robbason2 May
    • Re: select query questionJon Rosenberg2 May
    • DELETE questionDawn H2 May
      • Re: DELETE questionPaul DuBois3 May