The problem you are having is that, while your sqlite_connect() code assumes it is fine to just create a database file if it doesn't exist (which is what SQLite does automatically), your other code always assumes that the database file did exist before.

Your other code is trying to update or insert into a table without first checking that the table exists. And the table won't exist if the database didn't exist; newly created databases have no tables in them.

You need to issue a "create table trapdlog ..." statement if the database was newly created just now, and the table doesn't exist yet, prior to doing any inserts or updates.

-- Darren Duncan

At 1:02 PM -0500 10/8/04, Freeman, Michael wrote:
I am still having problems with a script trying to use SQLite2. My 4
line test script works fine, but my other code keeps giving me DBI
errors saying it can't find the table. Here is what I get in the DBI
trace.

    !! ERROR: 1 'no such table: trapdlog(1) at dbdimp.c line 412'
(err#0)

    <- execute('1094662322' '3' ...)= undef at logwiz.pl line 377

DBD::SQLite2::st execute failed: no such table: trapdlog(1) at dbdimp.c
line 412 at ./logwiz.pl line 377.

no such table: trapdlog(1) at dbdimp.c line 412 at ./logwiz.pl line 377.

The code I'm using:

my $lite_dbh = &sqlite_connect();

# prepare the update statement

my $lite_sth_update = $lite_dbh->prepare( q{ UPDATE trapdlog SET status
= ? WHERE node = ? } )


sub sqlite_connect {

    # need to add code in here to check that the database exists. if it
does not we

    # will create it. *thought*.

        my $sqlite_dbh =
DBI->connect("dbi:SQLite2:dbname=trapdlog.db","","")

            or die $DBI::errstr;

    return $sqlite_dbh;

}

Reply via email to