perl/dbi/sql stumped by "operation must use an updatable query" error -
i've perl script builds sql cmd set fields null in table in ms access db ( sorry). here's simplified mockup.
my $nonkeyfields_hashref = { "country" => "zzz", "address3" => "foo" }; $keyfields_hashref = { "address1" => "1212 o'mally street", # embedded single quote here causing problem "client id" => "1234567" }; $sqlcmd = "update mytable set "; $sqlcmd .= join( ", " , map{ "[?} = null "} keys $nonkeyfields_hashref; $sqlcmd .= " "; $sqlcmd .= join( " , " , map{ "[?} = ? "} keys $keyfields_hashref; # sqlcmd contains "update mytable set [?] = null, [?} = null [?] = ? , [?] = ?" $sth = $dbh->prepare( $sqlcmd); if( !defined( $sth)) { _pusherrormsg("sth failed define - ".$dbi::errstr); $errorhit = 1; } else { @cmd_arry = (); push( @cmd_arry, $_ ) keys $nonkeyfields_hashref; push( @cmd_arry, $_ , $keyfields_hashref->{$_} ) keys $keyfields_hashref; print dumper( @cmd_arry); # dumper shows @cmd_arry contains ("country", "address3", "address1", "1212 o'mally street", "client id", "1234567") # 6 elements, jibes query's question-marks $sth->execute( @cmd_arry); # errors here given message .... }
this code works great when data not contain nasty embedded single-quotes. i'd hoped binding solve problem no such luck.
anyone have solution single-quote issue?
thanks in advance,
still-learning steve.
that code contains syntax errors due a) missing closing ) on join calls b) missing use data::dumper. i'm assuming using recent perl since seem expecting $hash_references automatically dereferenced.
it unusual database engine accept parameters column names - not work databases.
the single quote talking has no impact on script far can see - broken wrt code in else pushing many paramaters sql statement. sql statement wants 4 column names , push 4 column names , 2 values.
i presume meant " push( @cmd_arry, $_ , $keyfields_hashref->{$_}" "push( @cmd_arry, $_".
Comments
Post a Comment