hi,

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 :

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; }
so where is the problem ?

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 :

actual 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); }
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 expected

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 !


In reply to fetchall_arrayref DBI question ? by baxy77bax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.