ravi45722 has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to upload some rows to DB
INPUTS CID,MSISDN,Preference,TYPE,SEVERITY "9","9596354636","1","A","2" "9","9596560722","2","A","2" "9","9596560722","2#3#4","A","2" "9","9622526453","3","D","2"
if it is "A" I need to add that number in the particular category as '1'. If the number is already exists in DB then update it on duplicate key of msisdn
my $user_sth = $dbh->prepare("insert into user_master (msisdn,cat0,ca +t1,cat2,cat3,cat4,cat5,cat6,cat7,vip,SAcode,phone_type) values (?,?,? +,?,?,?,?,?,?,?,?,?) on duplicate key update ?"); if ( $opty eq "A" ) { if ( $preference =~ tr/0//) #if pref +erence is 0 make all category as 0 { $cat{'0'} =1; $cat{'1'} =0; $cat{'2'} =0; $cat{'3'} =0; $cat{'4'} =0; $cat{'5'} =0; $cat{'6'} =0; $cat{'7'} =0; $db_update_cmd = "cat0=1"; #,c +at1=0,cat2=0,cat3=0,cat4=0,cat5=0,cat6=0,cat7=0"; } else #or made that category as + one in the DB { my @all_cat = split(/\#/,$pref +erence); foreach my $cat (@all_cat) { $cat{$cat} = 1; $db_update_cmd = $db_u +pdate_cmd."cat$cat=1,"; } chop $db_update_cmd; } my @db_values = (sprintf('%0d', $cat{'0'}), sprintf('%0d',$cat{'1'}),s +printf('%0d', $cat{'2'}), sprintf('%0d',$cat{'3'}),sprintf('%0d', $ca +t{'4'}),sprintf('%0d',$cat{'5'}),sprintf('%0d', $cat{'6'}), sprintf(' +%0d',$cat{'7'})); $user_sth->execute($msisdn,@db_values,0,$SAC,$phone_type,$db_update_cm +d) or die $DBI::errstr;
DBD::mysql::st execute failed: You have an error in your SQL syntax; c +heck the manual that corresponds to your MySQL server version for the + right syntax to use near ''cat1=1'' at line 1 at ./dnd_category_mana +gement_incremental_provisioning.pl line 208, <FD> line 1.
But it returning this error because it taking $db_update_cmd with ''. For example if the preference is 1 the $db_update_cmd = "cat1=1". If I pass that in execute function it taking as ...... upadte 'cat1=1'; Due to that single quotes its showing error. How can I simplify this
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Error in $sth->execute()
by 1nickt (Canon) on Feb 20, 2016 at 03:55 UTC | |
by ravi45722 (Pilgrim) on Feb 20, 2016 at 04:24 UTC | |
by ravi45722 (Pilgrim) on Feb 20, 2016 at 04:31 UTC | |
by 1nickt (Canon) on Feb 20, 2016 at 05:01 UTC | |
by poj (Abbot) on Feb 20, 2016 at 15:09 UTC | |
|
Re: Error in $sth->execute()
by Athanasius (Archbishop) on Feb 20, 2016 at 04:14 UTC | |
by ravi45722 (Pilgrim) on Feb 20, 2016 at 04:29 UTC |