PDA

View Full Version : Use of uninitialized value in concatenation (.) or string at


adeptz
07-22-2006, 04:44 AM
Ok everyone, first time PERL scripter here, although I have worked with many other languages. I was recently asked to help out a friend with his accounting scripts and for the life of me I cant seem to get this one damn script to compile I know this is a probably due to some miniscule little mistake on my behalf in the coding and thus have hit the net looking for assistance.

firstly I'll start off by stating, I know what that error means. but I cant see why this is not initializing my variable. The error related to the following lines of code.

my $query = "";
<ERROR HERE> $query = "SELECT chart.accno, chart.description, parts.income_accno_id
FROM invoice
WHERE invoice.trans_id = $acc_trans_id
AND parts.id = invoice.parts_id
AND chart.id = parts.income_accno_id
";

my $sth = $dbh->prepare($query);

$sth->execute;

if ($DBI::errstr) {
$dbh->disconnect;
exit 0;
}

here is the full error i receive when compiling with komodo
-Use of uninitialized value in concatenation (.) or string at line <ERROR>
-DBD::Pg::st execute failed: ERROR: syntax error at or near "AND" at character 104
-disconnect(DBI::db=HASH(0x21d2680)) invalidates 4 active statements. Either destroy statement handles or call finish on them before disconnecting.

this is only one part of my script, if anyone would care to help me out with this It would be greatly appreciated

I will attach a copy of my script incase anyone wants to try and compile it in its entirety

FishMonger
07-22-2006, 05:31 AM
Use of uninitialized value in concatenation (.) or stringThat is most likely comming from $acc_trans_id not beeing assigned. Are you sure it's been assigned a value prior to this statement?

Also, you should add quotes around the values of the where clause.

$query = "SELECT chart.accno, chart.description, parts.income_accno_id
FROM invoice
WHERE invoice.trans_id = '$acc_trans_id'
AND parts.id = 'invoice.parts_id'
AND chart.id = 'parts.income_accno_id'";

You should also rework your error handling so that it doesn't give you
-disconnect(DBI::db=HASH(0x21d2680)) invalidates 4 active statements. Either destroy statement handles or call finish on them before disconnecting.

FishMonger
07-22-2006, 05:40 AM
Personaly, I've never liked the style of assigning the select statement to a var, when it's just as easy to put it directly into the prepare statement. This is the style that I normally use.
my $sth = $dbh->prepare("SELECT chart.accno,
chart.description,
parts.income_accno_id
FROM invoice
WHERE invoice.trans_id = '$acc_trans_id'
AND parts.id = 'invoice.parts_id'
AND chart.id = 'parts.income_accno_id'");

nmehta
12-01-2011, 09:32 AM
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..?