0
我開始了數據庫的世界。我試圖讓一個Perl腳本從SQLite3中的數據庫中獲取一些數據。我想要做的第一步是刪除現有的表格,然後用新的數據創建另一個表格。我的代碼是:使用「DROP TABLE IF EXISTS」的DBI語法錯誤
#!/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的命令行,它工作正常。有任何想法嗎?
嗯,在此先感謝。
什麼是'$ dbh - > {sqlite_version}'? ...雖然我不認爲這將基於錯誤消息。 – ikegami
返回3.2.7 – user2245731
'... IF EXISTS'支持SQLite 3.3.0:請參閱http://stackoverflow.com/q/3675032/168657 – mob