Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
1. $dbh is undefined, I think you need to either change $D to $dbh or vice versa.
2. $s is undefined, I think you mean $sth

Here is your stuff working and some modifications I made to show you some oddities ( that SQLite docs claim are not bugs but features...) about SQLite that I noticed right away. I don't like this rdbms because it really doesn't care what stuff you feed it. I defined an integer, but it doesn't complain when I send it something else. And you don't get an exception raised when you try to create a table with a bogus data type, which makes debuging difficult.

I would also note that attributes like NULL and NOT NULL which are required when creating tables in most all rdbms's is ignored by SQLite. Also, a DATE datatype which would benefit from right away is absent in SQLite ( you should convert all your dates to a linear value if you want to use this tool and compare inside of SQLite? )
I personally don't think I will ever use this tool. There are too many free fully featured rdbms's out there.
#!perl -w use strict; use DBI; my $drop_tables = 1; my $create_tables = 1; my $dbh=DBI->connect("dbi:SQLite2:dbname=Store.db","","", {RaiseError= +> 1}) or die "$!"; if( $drop_tables == 1 ){ #NO SUPPORT for IF EXISTS $dbh->do("DROP TABLE ISP"); $dbh->do("DROP TABLE UnityPrimary"); $dbh->do("DROP TABLE UnitySecondary"); } if( $create_tables == 1){ $dbh->do("CREATE TABLE ISP(Store INTEGER,Date CHAR[1] NOT NULL )") or +warn "$!"; #Define my own $dbh->do("CREATE TABLE UnityPrimary(Store INTEGER,Date CHAR[9] NOT NUL +L)"); $dbh->do("CREATE TABLE UnitySecondary(Store INTEGER ,Date CHAR[9] NOT +NULL )"); } #open(CSV,"reboots.csv")||die"Can't open: $!\n"; while(<DATA>){ chomp; my($store,$isp,$pri,$sec)=split /,/; my $sta=$dbh->prepare("INSERT INTO ISP(Store,Date) VALUES(?,?)"); my $stb=$dbh->prepare("INSERT INTO UnityPrimary(Store,Date) VALUES(? +,?)"); my $stc=$dbh->prepare("INSERT INTO UnitySecondary(Store,Date) VALUES +(?,?)"); $sta->execute( $store, $isp ); $stb->execute( $store, $pri ); $stc->execute( $store, $sec ); } #close CSV; my $sth=$dbh->prepare("SELECT * FROM UnityPrimary WHERE Store > 1"); $sth->execute; while(my@row=$sth->fetchrow_array){ print "@row\n"; } $dbh->disconnect; __DATA__ 1,18-Oct-04,29-Oct-04,29-Oct-04 notanInt,18-Oct-04,26-Oct-04,26-Oct-04 3,21-Oct-04,26-Oct-04,11-Aug-04 4,20-Oct-04,11-Jun-04,27-Oct-04 5,18-Oct-04,3-Sep-04,24-May-04 6,17-Oct-04,15-Oct-04,15-Oct-04
OUTPUT: notanInt 26-Oct-04 3 26-Oct-04 4 11-Jun-04 5 3-Sep-04 6 15-Oct-04

In reply to Re: Working with DBI and DBD::SQLite2 by JamesNC
in thread Working with DBI and DBD::SQLite2 by TStanley

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the universe expands...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (9)
    As of 2018-03-24 14:33 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (299 votes). Check out past polls.