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 $_; }
In reply to DBI - Handling NULL values by McDarren
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |