我从数据库世界开始。我正在尝试制作一个 Perl 脚本来从 SQLite3 中的数据库中获取一些数据。我要做的第一步是删除现有表,然后使用新数据创建另一个表。我的代码是:
#!/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();
但我收到以下错误:
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.
在 sqlite3 命令行中它工作正常。有任何想法吗?
嗯,提前谢谢。