Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^6: SQL query using dynamic array

by cocl04 (Sexton)
on Nov 18, 2008 at 21:04 UTC ( [id://724386]=note: print w/replies, xml ) Need Help??


in reply to Re^5: SQL query using dynamic array
in thread SQL query using dynamic array

my $i = 0; # Connect to Oracle database. #When you fetch the data for the below sql statment it is loaded into +array index '0'. There is no way to index it. array = ['0','1','2',. +..'nth']. # Set up Query for ID my $stmt_1 = "select alignment from rd_list"; # Prepare Query my $query = $connection->prepare($stmt_1); # Execute Query $query->execute() or die $connection->errstr; # Create Array_ref for array. my $rows = $query->fetchall_arrayref; # Load data in array. foreach $i(0..$#{$rows}) { foreach $j (0..$#{$rows->[$i]} ) { $rows->[$i][$j]; } } my $num = $query->rows; print "\nThis process returns $num of ID's.\n\n"; while ($i<=2) { my $rd = "$rows->[$i][0]"; print "$rd\n"; $i++; }

In terms of a premade dataset. I know the exact count of $row. I just print the count. I have not created array via hard coding a premade list of $row. I can try that. I know that $row has the correct values because I checked them against the list in my database.

Each time I run the process, it sends an email to my inbox with three reports. I have it set to process while $i < = 2. So, the first email with id = '01' is the only worksheet with data from the sql statement. The other two have all the headers, etc.. but no data from the sql. It is as if the sql prepare holds on to the first value. I know the value changes, because it prints each time and email it each time.

I also know that the first report from array index '0' is correct because I validate the selected data from my data in Oracle.

Replies are listed 'Best First'.
Re^7: SQL query using dynamic array
by Corion (Patriarch) on Nov 18, 2008 at 21:12 UTC

    Your comment does not match your code:

    # Load data in array. foreach $i(0..$#{$rows}) { foreach $j (0..$#{$rows->[$i]} ) { $rows->[$i][$j]; } }

    The code does nothing. It also doesn't make sense. You still haven't answered what you think this code should do.

    Please read perldsc, perlreftut and use Data::Dumper to print out your data structure, so you can see what your data structure is and how to use it.

    You keep talking about "email", but "email" seems to be largely unrelated to the problem you have here. If you think "It is as if the sql prepare holds on to the first value.", what steps did you try to validate or reject that idea? Dumping out your data structure is very helpful in these situations. If you "know the value changes, because it prints each time and email it each time", then the place where you are printing data must be different from the place where you try to use the data in Excel. Investigate these situations and find where your data deviates from your assumptions.

    I'm sorry that I can't be of much more assistance - debugging a program is a process that you need to largely do yourself.

    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://724386]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-03-29 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found