Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-26 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found