Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

printing database rows in a file

by kalyanrajsista (Scribe)
on Oct 21, 2010 at 07:11 UTC ( #866488=perlquestion: print w/ replies, xml ) Need Help??
kalyanrajsista has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

I'm want to dump database records nearly 90k. what is the preferable module I can choose for the following Options

  • Print all those records into a File
  • Zip it and send it via Email

Currently I'm printing all those records in the email and sending it to the users using sendmail utility(/usr/sbin/sendmail). But Outlook is limiting to only 400+ lines and ignoring all other records. I would like to implement the above method

Any Help is appreciated

Comment on printing database rows in a file
Re: printing database rows in a file
by suhailck (Friar) on Oct 21, 2010 at 07:25 UTC
Re: printing database rows in a file
by marto (Chancellor) on Oct 21, 2010 at 08:32 UTC

      DBI + Text::CSV_XS + PerlIO::gzip =>

      use DBI; use PerlIO::gzip; my $sth = $dbh->prepare ("select * from table"); $sth->execute; my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1 }); open my $fh, ">:gzip", "output.csv.gz" or die "output.csv.gz: $!"; while (my $row = $sth->fetch) { $csv->print ($fh, $row); }

      If needed add the :encoding(utf8) layer


      Enjoy, Have FUN! H.Merijn
Re: printing database rows in a file
by Corion (Pope) on Oct 21, 2010 at 08:37 UTC

    In addition to the mentioned modules, also consider looking at Querylet, which allows easy integration of SQL statements and record output to text files, CSV files, HTML or XLS files.

Re: printing database rows in a file
by sundialsvc4 (Monsignor) on Oct 21, 2010 at 14:34 UTC

    What you’d really like to do, of course, is either to send the items as a zipped-up attachment, or, better yet, provide an internal web-page that users could link to to view the data.

    If you can store the data in a read-only file in a place where everyone can see, just send them an e-mail with a hotlink to it ...   A “UNC” fileref of the form \\servername\filename\ eliminates issues of drive-letter assignments, if you know that every intended recipient can reach and access the referenced file.

    The question really should be asked (by someone if not by you), whether such a voluminous output is really useful and satisfactory to the business needs of its recipients.   I seriously doubt that it is.

      At least in my case, Certainly such a voluminous data is useful for the business to review how much junk data got inserted into the system and take necessary actions on that.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://866488]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (12)
As of 2014-07-10 21:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (216 votes), past polls