0

I'm starting in the world of databases. I'm trying to make a Perl script to get some data from a database in SQLite3. The first step I want to do is remove a existing table and then create another with new data. My code is:

#!/usr/bin/perl

use DBI;
use strict;

my $driver   = "SQLite"; 
my $database = "/media/My\ Passport/Sources/M5nr_db";
my $dsn = "DBI:$driver:dbname=$database";
my $userid = "";
my $password = "";
my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) 
                      or die $DBI::errstr;

print "Opened database successfully\n";
my $stmt = qq(DROP TABLE IF EXISTS matching_prot );
my $rv = $dbh->do($stmt);
my $stmt = qq(CREATE TABLE matching_prot
    (Seq_ID TEXT,
     M5 TEXT,
     Identity REAL
     Evalue REAL
     Bit_score INT););
my $rv = $dbh->do($stmt);

$dbh->disconnect();

But I get the following error:

Opened database successfully
DBD::SQLite::db do failed: near "EXISTS": syntax error(1) at dbdimp.c line 269 at use_database.pl line 16.
DBD::SQLite::db do failed: near "EXISTS": syntax error(1) at dbdimp.c line 269 at use_database.pl line 16.

In the sqlite3 command-line it works fine. Any ideas?

Well, thanks in advance.

ysth
  • 96,171
  • 6
  • 121
  • 214
user2245731
  • 449
  • 3
  • 7
  • 16
  • What's `$dbh->{sqlite_version}`? ...though I don't think this will matter based on the error message. – ikegami Jul 08 '13 at 14:52
  • 2
    `... IF EXISTS` supported in SQLite 3.3.0: see http://stackoverflow.com/q/3675032/168657 – mob Jul 08 '13 at 14:59
  • Solved! Update using CPAN and works! Now I'm embarrassed, it was just a version problem. Anyway, thanks! – user2245731 Jul 08 '13 at 15:17

0 Answers0