Front page | perl.dbi.users |
Postings from December 2006
Re: out of memory
Thread Previous
|
Thread Next
From:
louis fridkis
Date:
December 29, 2006 08:46
Subject:
Re: out of memory
Message ID:
dcab49ed0612290846w6a382a6em1e285b3f2edc434c@mail.gmail.com
Thanks for your reply's. No, I'm not insulted. This is a quick-and-dirty to
generate some test data. But, I do appreciate the comments since I am eager
to improve.
There is no suppressed code. I showed you the whole program except for the
header. Here is the full program (except where I substituted foo, bar, jar):
#!/usr/bin/perl
use strict;
use DBI;
my $dbh_from = DBI->connect(
'dbi:Pg:dbname=jar;host=foo');
my ($table_name, $sqlstring) = @ARGV;
$dbh_from->do('SET search_path TO cel, part_elementresult, public');
my $cel_sth = $dbh_from->prepare($sqlstring);
$cel_sth->execute();
#
# added & replaced:
#while(my (@rowvalues) = $cel_sth->fetchrow_array()){
#
my @rowvalues;
my $rv;
my $elementresult_id;
my $element_id;
my $quantification_id;
my $signal;
$rv = $cel_sth->bind_columns(\($elementresult_id, $element_id,
$quantification_id, $signal));
while($cel_sth->fetch()){
@rowvalues = ($elementresult_id, $element_id, $quantification_id,
$signal);
#
# end
# added & replaced
#
my $printstring= "insert into $table_name values(";
foreach my $column (@rowvalues){
if (defined $column){
if($column =~ /\D/){
$column = "'".$column."'"
unless ($column =~ /\d*\.\d+/);
}
$printstring.= "$column,";
} else {
$printstring.= "NULL,";
}
}
$printstring =~ s/,$/);/;
print "$printstring\n";
#my $dbh_to = DBI->connect(
# 'dbi:Pg:dbname=TestIO;host=bar');
# $dbh_to->do($printstring);
}
As you can see from the comments I originally used: fetchrow_array(). I
changed in the hopes that fetch() would work better. The reason I think it
tries to hold all the rows in memory is because it works when the query in
$sqlstring returns a small number of rows, but fails with the "out of
memory" error when it returns a large number of rows.
On 12/28/06, Marius Feraru <altblue@n0i.net> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Ron Savage wrote:
> > On Fri, 29 Dec 2006 05:08:48 +0200, Marius Feraru wrote:
> >> You forgot to notice Louis' ugly way (and error prone) of
> > No I didn't - I was just too polite to hammer OP despite the low
> > quality of the code, so I chose a gentle hint or two.
>
> Oops, does this mean I was rude to point out some more hints? My
> apologies then ;-)
>
> happy coding everyone :)
> - --
> Marius Feraru
> -----BEGIN PGP SIGNATURE-----
>
> iD8DBQFFlKLJtZHp/AYZiNkRAvthAJ9h4GLmwA1CTgMUPooF+PnZVjAD2ACgjFD/
> 63pWRvMIKO1YncCHZhwxdYY=
> =IA9T
> -----END PGP SIGNATURE-----
>
--
Lou Fridkis
Human Genetics
57920
Thread Previous
|
Thread Next