FryingFinn has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to write a script to update a mySQL table. I create a SELECT cmd with placeholders; I copy the updated field values into a bind array. However, one of the fields include a comma in the value. So the DBI::EXECUTE cmd thinks there is one too many values
Results in the following ...#!/usr/bin/perl -w my $dbh = open_admin(); my $table ="test"; my $year = "2018"; my %updates = (); my $k =7749; my $new = q["Boop, Betty"]; ## 'Boop, Betty'; $updates{$k}{name} = $new; $updates{$k}{age} = 33; foreach my $id ( keys %updates ){ my $update = ""; $update .= "UPDATE $table SET "; my @binds = (); my $i = 0; foreach my $fn ( keys %{$updates{$id}} ) { $update .= " $fn=?, "; $binds[$i] = $updates{$id}{$fn}; $i++; } push @binds, $k; $update .= "WHERE course_id =? AND year=$year"; my $xbinds = join ", ", @binds; print "update [$udate]\n"; print "binds --> {$xbinds }\n"; my $sth = $dbh->prepare($update); $sth->execute(@binds, $id); } exit;
-bash-4.1$ ./bbtest update [UPDATE test SET name=?, age=?, WHERE course_id=? AND year=2 +018] binds --> {"Boop, Betty", 33, 7749 } DBD::mysql::st execute failed: called with 4 bind variables when 3 are + needed at ./bbtest line 36.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI UPDATE w comma in field value
by Corion (Patriarch) on May 22, 2018 at 19:01 UTC | |
|
Re: DBI UPDATE w comma in field value
by roboticus (Chancellor) on May 22, 2018 at 19:07 UTC | |
|
Re: DBI UPDATE w comma in field value
by haj (Vicar) on May 22, 2018 at 19:30 UTC | |
|
Re: DBI UPDATE w comma in field value
by Anonymous Monk on May 22, 2018 at 20:47 UTC | |
by Your Mother (Archbishop) on May 25, 2018 at 21:26 UTC | |
by Anonymous Monk on May 25, 2018 at 17:22 UTC |