baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:
i'm seeking for monks wisdom on this one :)
ok, im using DBI for retrieving data from my database tables , and the procedure that i'm using is :
so where is the problem ?my $datahash = $self->_fetchall(table => 'Table1'); open (NROUT, ">", "./bin/PhyloStr/tmp/tmp.txt") || die "$!"; foreach (@$datahash){ print NROUT ">G$_->{column1}T$_->{column2}\n$_->{column3}\n"; } close NROUT; undef($nrdatahash); # # # am i actually doing anything here? ################## sub for _fetchall: sub _fetchall { my ($self,%arg) = @_; my $stm = "select * from $arg{table}"; my $stmt = $dbh->prepare($stm) || die $dbh->errstr; $stmt->execute || die $dbh->errstr; ; my $array = $stmt->fetchall_arrayref({}); $stmt->finish() || die $dbh->errstr; ; return $array; }
fetchall_arrayref is consuming too much of my ram (1.5 GB) because the tables are pretty big. so my question is should i switch to fetchrow_array(), -> is it going to slow this process a lot or not. or should i retrieve ref , like fetchrow_arrayref().
the reason i'm asking this question and not testing it by myself is because the process takes to long on my PS
thank you !!
Update:
as far as type of databases goes . i'm on sqlite because it has proven to be very practical, small but fast and eays to use db (or should i say db library)
i love Perl and SQLite , what can you do !!
Update:
i hope this thread is still alive
well what i've done is :
so the problem still persists , my ram is jumping through the roof , switching form fetchall to fetchrow just decreased the memory used but not as much as i expectedactual script (in module one): $self->_connectdb(connection => "./db/db/db.db"); open (NROUT, ">", "./bin/PhyloStr/tmp/NROUTtmp") || die "$! \n"; $self->_doit(statement => 'begin'); $self->_fetchrow_stmt(table => 'TABE'); while (my $row = $self->_return_row()){ print NROUT ">G$row->[0]T$row->[1]\n$row->[2]\n";; } $self->_finish_stmt(); close NROUT; $self->_disconnectdb(); ######################### sub in a module two: my $fetchrow_stmt; sub _fetchrow_stmt { my ($self,%arg) = @_; my $stm = "select * from $arg{table}"; $fetchrow_stmt = $dbh->prepare($stm) || die $dbh->errstr; ; $fetchrow_stmt->execute || die $dbh->errstr; } sub _return_row { my ($self,%arg) =@_; return $fetchrow_stmt->fetchrow_arrayref(); } sub _finish_stmt { my ($self,%arg) = @_; $fetchrow_stmt->finish() || die $dbh->errstr; undef($fetchrow_stmt); }
it's like dbi module stores the fetched rows somewhere.
so does anyone know how to loop through table rows without memorizing fetched data.(because i think this is the problem)
Thank you !
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: fetchall_arrayref DBI question ?
by runrig (Abbot) on Mar 16, 2009 at 20:14 UTC | |
|
Re: fetchall_arrayref DBI question ?
by szbalint (Friar) on Mar 16, 2009 at 21:37 UTC | |
|
Re: fetchall_arrayref DBI question ?
by bellaire (Hermit) on Mar 16, 2009 at 20:14 UTC | |
|
Re: fetchall_arrayref DBI question ?
by perrin (Chancellor) on Mar 17, 2009 at 03:05 UTC | |
|
Re: fetchall_arrayref DBI question ?
by Herkum (Parson) on Mar 16, 2009 at 20:12 UTC | |
|
Re: fetchall_arrayref DBI question ?
by bradcathey (Prior) on Mar 17, 2009 at 00:09 UTC | |
|
Re: fetchall_arrayref DBI question ?
by locked_user sundialsvc4 (Abbot) on Mar 18, 2009 at 12:47 UTC |