McDarren has asked for the wisdom of the Perl Monks concerning the following question:
The above code is part of a script that is used to backup tables from several remote hosts to a central database. It works "okay", but after running it a few times I discovered that it wasn't correctly handling NULL's.178 # Build the first half of the INSERT 179 # using the field list we got from the earlier DESCRIBE 180 # Of course we only do this if we have any rows to inser +t 181 if ($affected_rows) { 182 my $base_insert = "INSERT IGNORE INTO $thisTable (host +name, host_id, " 183 . join("," , @fields) 184 . ") VALUES (\"$site_hostname\", \"$site_id\", "; 185 186 # Now we iterate through the result set from the pre +vious query 187 # completing each INSERT as we go, and dumping them +all into a big list 188 while (my @row = $dbq->fetchrow_array) { 189 # Need to check for NULL's 190 for(@row) { $_ = "NULL" if !defined $_; } 191 my $this_insert = $base_insert 192 . join("," , map {qq("$_")} @row) 193 . ");"; 194 push @central_inserts, $this_insert; 195 } 196 }
at line 190.for(@row) { $_ = "NULL" if !defined $_; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI - Handling NULL values
by Tanktalus (Canon) on Sep 29, 2005 at 04:20 UTC | |
by McDarren (Abbot) on Sep 29, 2005 at 06:03 UTC | |
by davidrw (Prior) on Sep 29, 2005 at 12:33 UTC | |
|
Re: DBI - Handling NULL values
by rnahi (Curate) on Sep 29, 2005 at 05:57 UTC | |
|
Re: DBI - Handling NULL values
by jZed (Prior) on Sep 29, 2005 at 06:34 UTC | |
by McDarren (Abbot) on Sep 29, 2005 at 07:03 UTC | |
|
Re: DBI - Handling NULL values
by pg (Canon) on Sep 29, 2005 at 05:17 UTC |