Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

DBI::ODBC Delete Error

by vbrtrmn (Pilgrim)
on Jan 07, 2004 at 19:58 UTC ( [id://319581]=perlquestion: print w/replies, xml ) Need Help??

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

UPDATE: Sorry about the links, I didn't realize I'd need to use html codes, instead of square brackets.

I'm having some issues deleting from a table, the error message seems a bit ambiguous, I tried googling for it, but didn't find anything useful. Can anyone throw me a bone?

Error Message:
[Wed Jan 7 19:15:33 2004] delete.pl: DBD::ODBC::st execute failed: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1. (SQL-07002)(DBD: st_execute/SQLExecute err=-1) at ./delete.pl line 30.

Code Snipet (line 30 is the $sth->execute):

$DSN = 'DBI:ODBC:SearchWords'; $USER= ''; $PASS= 'password'; $DBH = DBI->connect( $DSN, $USER, $PASS, { RaiseError => 1} ); my $SQL = "DELETE FROM [Production Words] WHERE areaId=ofn01506"; my $sth = $DBH->prepare($SQL); $sth->execute || die "Could not execute SQL statement ... maybe invali +d?\n$!"; $sth->finish; $DBH->disconnect();

--
paul

Replies are listed 'Best First'.
Re: DBI::ODBC Delete Error
by CountZero (Bishop) on Jan 07, 2004 at 20:44 UTC
    (Warning: Untested code)

    What happens when you quote the parameter of areaID?

    my $SQL = 'DELETE FROM [Production Words] WHERE areaId="ofn01506"';

    Or even better, use a placeholder:

    my $SQL = "DELETE FROM [Production Words] WHERE areaId=?"; my $sth = $DBH->prepare($SQL); $sth->execute('ofn01506') || die "Could not execute SQL statement ... +maybe invalid?\n$!";

    Placeholders take care of the quoting automagically.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      CountZero, your suggestion worked great, thanks!

      --
      paul

Re: DBI::ODBC Delete Error
by Sandy (Curate) on Jan 07, 2004 at 21:53 UTC
    I'm guessing here, so bear with me...

    I remember reading in the camel book how one ought to be careful about using || vs. 'or' when used in conjuction with list operators (or subs without parenthesis).

    i.e. use
     open FILE, ">$file" or die "Oops";
    or
     open (FILE, ">$file") || or die "Oops";
    but not
     open FILE, ">$file" || or die "Oops";

    So, I'm a guessing that you need to change line 30 to (note additional parenthesis) ...

    $sth->execute() || die "Could not execute SQL statement ... maybe inva +lid?\n$!";
    or maybe change the || to 'or'
    $sth->execute or die "Could not execute SQL statement ... maybe invali +d?\n$!";
    Let me know if I guessed right (or even if I guessed wrong).

    Sandy

    Quote from the camel book:

    As lower precedence alternatives to &&, ||, and !, Perl proveds the and, or, and not operators. The behaviour of these operators is identical -- in particular, and and or short-ciruit like their counterparts, which makes them useful not only for logical expressions but also for control flow.

    Since the precedence of these operators is much lower than the ones borrowed from C, you can safely use them after a list operator without the need for parentheses:

    unlink "alpha", "beta", "gamma" or gripe (), next LINE;
    With the C-style operators you'd have to write it like this:
    unlink("alpha", "beta", "gamma") || (gripe(), next LINE);

      I've used $sth->execute with and without the parenthesis, in the past, either way seems to work fine. Sans the code above, though CountZero's suggestion of quoting what I want to match in the SQL query worked.

      In your second open FILE example you duplicate the use of or. Read aloud it sounds like a stutter or you're mad.
      Open the file .. OR .. OR DIE!!!

      --
      paul

        In your second open FILE example you duplicate the use of or. Read aloud it sounds like a stutter or you're mad.

        Ooops...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-29 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found