SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Use of uninitialized value in concatenation (.) or string

    hI

    i am running a perl script which is big enough to post here,but i will post the part which throws error.

    I am trying to retrieve rows through an sql query.



    #--------------script--------------------

    #4.1.Finding job sets id
    print("\nFinding job sets id from table jobs..\n");
    $sql =<<"EOF";
    select job_id from moose.jobs
    where parent_id = '$job_app'
    EOF

    debug("SQL>$sql", 2);
    $s = $db->prepare($sql);
    $s->execute();
    while (@row = $s->fetchrow_array){
    print join(",",@row),"\n";
    $jobs = join(",",@row);
    print("jobs = $jobs");
    }



    Now when I run this script,it gives the following error :

    Finding job sets id from table jobs..
    Use of uninitialized value in concatenation (.) or string at ./removeMooseBuild_dev_nidhi.pl line 340.
    Use of uninitialized value in concatenation (.) or string at ./removeMooseBuild_dev_nidhi.pl line 340.
    Use of uninitialized value in concatenation (.) or string at ./removeMooseBuild_dev_nidhi.pl line 340.
    Use of uninitialized value in concatenation (.) or string at ./removeMooseBuild_dev_nidhi.pl line 340.
    Use of uninitialized value in concatenation (.) or string at ./removeMooseBuild_dev_nidhi.pl line 340.
    Use of uninitialized value in concatenation (.) or string at ./removeMooseBuild_dev_nidhi.pl line 340.
    Use of uninitialized value in array element at ./removeMooseBuild_dev_nidhi.pl line 340.
    Use of uninitialized value in concatenation (.) or string at ./removeMooseBuild_dev_nidhi.pl line 340.
    Use of uninitialized value in concatenation (.) or string at ./removeMooseBuild_dev_nidhi.pl line 340.
    Use of uninitialized value in array dereference at ./removeMooseBuild_dev_nidhi.pl line 340.
    SQL> select job_id from moose.jobs
    where parent_id = 1385279
    EOF

    debug("SQL> select job_id from moose.jobs
    where schedule_id = '1385277'
    ", 2);
    DBI::st=HASH(0x51f588) = DBI::db=HASH(0x35cd58)->prepare( select job_id from moose.jobs
    where schedule_id = '1385277'
    );
    DBI::st=HASH(0x51f588)->execute();
    ....and so on..


    Ideally the query returns three rows with a single column integer value in each row such as :
    80
    84
    92

    Also,$job_app is not null..can you please help me out with the possible mistake i am making..?

  2. #2
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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");
    }

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Everything dsheroh said plus is this right?

    Code:
    SQL> select job_id from moose.jobs
    where parent_id = 1385279
    EOF
    
    debug("SQL> select job_id from moose.jobs
    where schedule_id = '1385277'
    ", 2);
    What's the difference between schedule_id and parent_id or are these separate queries?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •