If you are into small scale,rapid application development then SQLite is definately the thing for you.
So what all do you need to get started with an SQLite driven application?
1. Install the DBI (1.39 was the latest last i checked)
2. Install DBD::SQLite (0.29)
3. Install the dbish (11.93)
As jeffa has shown in his examples above ,you can use a script to create a table .
The other way to do this is too run /opt/perl5/bin/dbish
This gives you a shell interface to your database.
Make a file to hold your records e.g touch /record.db
After running the dbish choose the option to connect to the sqlite database (option 3).
Then provide the dsn e.g. dbi:SQLite:/record.db
Once you are connected to the db you can run your create,insert,delete,update commands.
However,if you want to shift records from a flat file into a database it is advisable to write a script . An example of this is below:
Flat file example
10.50.0.0 255.255.0.0 164.130.4.0 255.255.252.0 164.130.8.0 255.255.248.0 164.130.16.0 255.255.240.0 164.130.32.0 255.255.248.0 164.130.40.0 255.255.252.0

And the script to read it and insert records into a table
use DBI; my $dir='/ipmap'; my $id=0; opendir(DIR,$dir); my @files = grep { $_ ne "." and $_ ne ".." } readdir DIR; closedir(DIR); my %attrib = ( PrintError => 0, RaiseError => 1 ); my $dbh = DBI->connect('dbi:SQLite:ipadd.db',"","",\%attrib); my $query = $dbh->prepare("insert into siteip (tla,ip,range) values (? +,?,?)"); print "@files\n"; foreach my $file (@files) { chomp($file); my @ins=''; my($tla,undef)=split(/\./,$file); print "Processing for $tla\n"; open(FI,"$dir\/$file")|| die $!; while(<FI>) { $id=+1; next if m/^\s*$/ or m/^\s*#/; my $line=$_; @ins = split(/\s+/,$line); # print "Inserting $tla $ins[0] $ins[1]"; $query->execute("$tla","$ins[0]","$ins[1]"); } } $dbh->disconnect;

Hope this helps in your first attemp at using SLite.
cheers
chimni

In reply to Re: Can SQL be used without a database? by chimni
in thread Can SQL be used without a database? by thegoaltender

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.