Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Re: allowed

by Anonymous Monk
on Apr 05, 2001 at 02:48 UTC ( [id://69929]=note: print w/replies, xml ) Need Help??


in reply to Re: allowed
in thread more and more dbi issues

i took it out of the loop i removed the and statements and it works is there anything wrong with the and statements it works in sql manually i cant get it to work if there's even 1 and statement. i know someone who got it to work on the same system here with one and statement any ideas??

Replies are listed 'Best First'.
Re: Re: Re: allowed
by arturo (Vicar) on Apr 05, 2001 at 03:09 UTC

    I see nothing wrong with your SQL as written, though I will say this again:

    Use placeholders. They will prevent certain nasty kinds of errors from cropping up; one thing that might cause problems with your code as written is that IF there any quotes or other zany things in your data, that will result in the SQL string not being well-formed; if you use placeholders, these issues will be dealt with automatically. All this adds up to : use placeholders

    OK, with that out of the way ... check to see whether you've issued a commit to the database (this will have no effect if you're using a DB without commit and rollback, like vanilla MySQL), as sutch recommended. If the statements execute without error but nothing happens in the database, that's one place to look. Also, as thabenskta mentioned, you should always return the value of $dbh->errstr when a call to the database fails. So put those in, they'll help with debugging!

    Now, as to the method: whatdo is good for one-off things, but it forces you to prepare each statement each time through the loop. That's inefficient: prepare once, execute many times! So go with the normal prepare, bind, execute cycle:

    my $sth1 = $db->prepare(q{ UPDATE trees SET department = ? WHERE sport = ? AND round = ? }) or die "Can't prepare first statement: ". $dbh->errstr() . + "\n"; # and so with $sth2 and $sth3 # execution time for my $i (1..13) { # I'd suggest reworking this data structure too, but # I'll work with what you have # smaller sermon : initialize the variables that are # expected to change on each step through the loop # with my *** inside the loop *** # that way, you get a fresh copy of the variable each time # through without potentially having old values intrude my $team = $teams{"team$i"}; my $score = $scores{"score$i'}; $sth1->execute ($team, $sport, $i) or die "Execution of first update failed: ". $dbh->errstr() ." +\n"; $sth2->execute( #blah blah... }

    HTH.

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-29 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found