You left out one crucial piece of information: Which line is line 340?
I'm going to guess that it's the line print("jobs = $jobs");, because the warning would show up on two different lines if it was the join causing it.
If my guess is right, then the warning means that $jobs is undefined, which in turn means that @row contains a single undef value. And that would mean that you've retrieved a database row in which the job_id field is NULL. Have you run the SQL query manually and verified that every returned record has a value in job_id?
Incidentally, since you're only selecting a single field from the database, there's no need for the join. join combines multiple values from an array into a single string, but your array will never contain multiple values.
As a broader point, you should make a habit of never inserting variables directly into your SQL statements. It's much, much safer to use SQL placeholders instead. Here's a quick revision of your posted code which demonstrates doing so, as well as testing for whether NULLs have been returned:
Code:
print("\nFinding job sets id from table jobs..\n");
my $sql =<<"EOF";
select job_id from moose.jobs
where parent_id = ?
EOF
debug("SQL>$sql", 2);
my $s = $db->prepare($sql);
$s->execute($job_app);
while (my @row = $s->fetchrow_array){
my $job = $row[0];
unless (defined $job) {
warn "Found NULL job_id with parent_id $job_app\n";
next;
}
print("job = $job");
}
Bookmarks