Access to sqlite3 database through perl (script example)

Welcome to Linux Screw! If you're new here, you may want to subscribe our RSS feed.

By publishing this post I try to help people who want to get access to popular and simple database engine sqlite through perl script. I use sqlite to store e-mails statistics at small mail server in order to retrieve information about users’ mail activity like average response time, sent and received messages and etc. There is perl script that is used to get this data per every user or get summary statistics. This script is to be run by web server (I use Apache) and has name index.cgi in my case.

Here is part of it:

#!/usr/bin/perl
use DBI;
print “Content-type: text/html\n\n”;
print “<html><head><title>perl and sqlite example script</title></head><body>”;
$dbh = DBI->connect( “dbi:SQLite:dbname=/tmp/mail_data.db”,”", “”, { RaiseError => 1, AutoCommit => 0 });

my $fst = $dbh->selectall_arrayref(“SELECT min(time_1),max(time_1) FROM mail_data”);
foreach my $row (@$fst) {
my ($fst_pr,$lst_pr) = @$row;
print “oldest entry in database: “.gmtime($fst_pr).” gmt<br>newest entry in database: “.gmtime($lst_pr);
}

print “</body>”;
print “</html>”;
$dbh->disconnect;

After you load this example through any web browser (please read your web server’s manual on how to allow cgi/perl script exec, for example here), script will read sqlite database that is located at /tmp/mail_data.db and display minimal and maximal values of field time_1 from mail_data table.

In order to run this script it’s necessary to install perl, sqlite3 and perl-DBI-SQLite cpan module.

You may also be interested in:
CGI Perl scripts debugging (solve 500 Internal Server Error)

 
 
» You might also be interested in the following articles:
CGI Perl scripts debugging (solve 500 Internal Server Error)
Dump ipcad output into sqlite3
Tiny perl script for UDP flooding
Tiny bash scripts: check Internet connection availability
Web server oneliner with bash



» Want to stay up to date? Subscribe to our E-MAIL or RSS feed!

20 Responses to “Access to sqlite3 database through perl (script example)”


  1. 1 Graham

    Might be worth posting the database.

    Or one you have with sample data.

  2. 2 r

    linuxscrew.com/2007/08/14/access-to-sqlite3-database-through-perl-script-example/

  3. 3 Kajetan

    Hello my little friends. I just wanted to say how encouraged I am by your attitude and to see your determination to carry on regardless artist i sense a little sarcasm video cold, picture, Thanks

  4. 4 Zygmunt

    Nice site! Like you I am a avid motorsport fan, and am also currently very involved in marshalling and race control in our local hillclimbs video so anime metal, film mouth, cartoon, Best Wishes!!

  5. 5 Melchior

    Hi all!!! You are the best!!! Congratulations. film Super site ! artist space, quicktime, Thank you for good job!

  6. 6 Edward

    Greetings. well sort of clip Perfect site, i like it! news, Kind regards

  7. 7 Magdalene

    O, super project. What an amazing story! I was aware of the Goodwood incident, of course, but not of the detail pets Brilliant but simple idea. land result, sale call, puppy crowd, dachshund sugar, collar fun, eclectus, Best regards from regular visitor of your site. ;)

  8. 8 John

    All greetings! I can’t be bothered with anything these days. dog Keep up the good work!!! terrier
    black, breeder ease, kennel piece, for sale consonant, canine cotton, dog, Good Luck,

  9. 9 Vince Delmonte

    Hey, cool tips. I’ll buy a bottle of beer to that person from that forum who told me to go to your site :)

  10. 10 Josephine

    O, super project. I speak for all those who wear the uniform of a Marshall when I say that your account made me proud breeder i sense a little sarcasm sale rock, puppies fit, kennel watch, sale, I love it :) Respect !

  11. 11 DoundDusanary

    That was formidable when good some wierd looking lady started to warble like an angel! Susan Boyle was a unaffected astonishment for millions!! WOW!

  12. 12 hnEydo

    The best scenes whith Alessandra Ambrosio (hot and sexy)!
    click here Alessandra Ambrosio nude gallary sextape or just follow the link http://digg.com/celebrity/Alessandra_Ambrosio_nude_pictures_naked_video_sextape_3
    You MUST SEE it, this girl really beautifull!!!

  13. 13 piniko

    Hey, you’ll love it. TOTALLY SHOCKING original video whith Tara Reid >>
    click here Tara Reid nude gallery sextape or just follow the link http://digg.com/celebrity/Tara_Reid_nude_pictures_naked_video_sextape
    You MUST SEE it, this chik really beautifull!!!

  14. 14 EdgegeZon

    He put his eye to the hole. He just managed to spy some people sitting in deckchairs chanting, before a finger came out of nowhere and poked him in the eye. As he staggered back, the people started chanting, “Fourteen, fourteen, fourteen…”

  15. 15 Dupttigrarp

    These teens are so tired they don’t even wake up when the cum sprays on their face!
    Too tired? Too bad!b freematuregeriesexvideos Watch as horny boyfriends get the green light from their kinky teen babes amateurmaturemilf to have their way all night long! These girls sleep soundly as their boyfriends fondle, amateurfreemature finger and fuck their way to a messy climax that leaves their sleeping eyes plastered shut with cum!
    When these teens are too sleepy to fuck they have to listen to their pussy-craving boyfriends bitch and whine. adultvideosmature
    The solution? Let the boys be boys! These kinky teens let their boyfriends fondle, fuck and cum on their perfect teen bodies however they want so long as they don’t wake them up!

  16. 16 Alessandra Ambrosio Wallpapers

    Alessandra Ambrosio is so a nice looking. What do you think about she?

  17. 17 margohelp

    had recently herpes virus found in my blood. what I haveto do??? I’m in panic…

  18. 18 valerie.beman

    my monicker is valerie

    found this forum while searching looking for grants.

    anticipation i can assist you guys also.

  19. 19 Ashlee

    Full sex tape video whith Ashlee Simpson
    click here Ashlee Simpson nude pictures naked video sextape or just follow the link http://beauty-bargains.bellasugar.com/7291126
    You MUST SEE it, this girl really HOT!!!

  20. 20 Buffalo Grove Pet Sitter

    There are so many helpful comments on this site. I just wanted to thank everyone for their insightful comments.

Leave a Reply




Friendly Sites:Who is behind Linux Screw?
Aspiring Sysadmin | GeekyBits³ | Bash Cures Cancer | TOTMS
Linux Operating System | Small Linux Deployments | My SysAd Blog
The Danesh Project | ZEPY | Linux config Wiki | Planet Sysadmin
The Sys Admin | {buhay sysad} | a non-geek's linux notes
Linux HOWTOs, Tutorials & Projects with Adam Palmer | LinuxAlt.Com
My name is Artem Nosulchik (artiomix AT gmail DOT com) and I'm Linux/Unix, Cisco systems engineer. The main idea of Linux Screw is to share relevant knowledge, skills and observations over The Web. Here you can find a lot of information related to different Linux distributions, FreeBSD, IOS as well as a other Open Source around staff. Read more ››