bichonfrise74 has asked for the wisdom of the Perl Monks concerning the following question:
If I pass all the parameters to the subroutine, it gives me the correct update SQL. The problem starts when I start passing some null parameters.#!/usr/bin/perl use warnings; use strict; update_table( 'test_name', 'test_phone', 'test_city', 'test_country' ); update_table( 'test_name', 'test_phone', '', 'test_country' ); update_table( 'test_name', '', 'test_city', '' ); sub update_table { my ($name, $phone, $city, $country) = @_; my $sql = qq! UPDATE table SET ! . qq! phone = '$phone', ! . qq! city = '$city', ! . qq! country = '$country' ! . qq! WHERE name = '$name' !; print $sql; return 1; }
The correct one that I am hoping for is this (without the city assuming that I pass a null value for this parameter):UPDATE table SET phone = 'test_phone', city = '', country = 'test_country' FROM ...
So, to summary the problems:UPDATE table SET phone = 'test_phone', country = 'test_country' FROM ...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Flexible Update SQL
by Your Mother (Archbishop) on Dec 02, 2010 at 02:25 UTC | |
Re: Flexible Update SQL
by GrandFather (Saint) on Dec 02, 2010 at 01:24 UTC | |
Re: Flexible Update SQL
by PeterPeiGuo (Hermit) on Dec 02, 2010 at 00:58 UTC | |
by bichonfrise74 (Vicar) on Dec 02, 2010 at 01:14 UTC | |
by roboticus (Chancellor) on Dec 02, 2010 at 02:53 UTC | |
Re: Flexible Update SQL
by Anonymous Monk on Dec 02, 2010 at 00:55 UTC | |
by JavaFan (Canon) on Dec 02, 2010 at 01:11 UTC | |
by bichonfrise74 (Vicar) on Dec 02, 2010 at 01:08 UTC | |
Re: Flexible Update SQL
by bichonfrise74 (Vicar) on Dec 02, 2010 at 18:41 UTC |