Output:#!/perl/bin/perl use strict; use warnings; use Data::Dumper; use SQL::Abstract; my %fd = ( txtName => 'OK', txtCreated => '', txtDateren => '', # will use NOW() function txtOldname => 'NOT OK', txtDel => '', ); my $id = 1234; # column name mapping my %cols = ( txtName => 'Listname', txtCreated => 'DateCreated', txtDateren => 'DateRenamed', txtOldname => 'OldListname', txtDel => 'DateDeleted', ); # which column to update? my %column = map { $cols{$_} => $fd{$_} } grep { $fd{$_} } keys %fd; $column{DateRenamed} = \'NOW()'; my $sql = SQL::Abstract->new; my($query, @binds) = $sql->update('table', \%column, { id => id }); print Data::Dumper::Dumper($query, \@binds);
$VAR1 = 'UPDATE table SET DateRenamed = NOW(), Listname = ?, OldListna +me = ? WHERE ( id = ? )'; $VAR2 = [ 'OK', 'NOT OK', 1234 ];
Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
In reply to Re: Looping an array and placing into SQL
by naikonta
in thread Looping an array and placing into SQL
by Quicksilver
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |