Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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

Replies are listed 'Best First'.
Re: printing database rows in a file
by marto (Bishop) 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 suhailck (Friar) on Oct 21, 2010 at 07:25 UTC
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 (Abbot) 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?
[moritz]: ... "so there is no need to do anything"
[LanX]: and the code is a bit of a mess
[LanX]: moritz, no ... jsut copy one line of my code
[moritz]: I'm still using the CB, because ambrus's #cbstream makes it bearable
[LanX]: ... the rest is loaded from a node
[holli]: the best course of action would be to transfer the data to something well tested. even if it isnt perl based
[moritz]: but even if I had all the time in the world, I wouldn't spend much on perlmonks
[LanX]: holli: LOL
[LanX]: moritz: why ? family?
[LanX]: or other language?

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (12)
As of 2017-11-20 19:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (291 votes). Check out past polls.

    Notices?