[英]Why do I get a syntax error with DBD::SQLite even though my version of SQLite supports `CREATE TABLE IF NOT EXISTS`?
I am using SQLite v3 to write a Perl script. 我正在使用SQLite v3编写Perl脚本。 The sqlite version is 3.3.6.
sqlite版本是3.3.6。
When I run sqlite on the command line it works. 当我在命令行上运行sqlite时,它可以工作。 But when I do the same thing in Perl it raises this error
但是当我在Perl中执行相同的操作时,会引发此错误
DBD::SQLite::db do failed: near "NOT": syntax error(1) at dbdimp.c line 268 at file line 2675.
DBD :: SQLite :: db失败:在“ NOT”附近:dbdimp.c 268行在文件行2675处语法错误(1)。
This is what I do on the console: 这是我在控制台上所做的:
$ sqlite3 test.db
SQLite version 3.3.6
sqlite> create table if not exists DATA_STATUS_VALUE (TYPE TEXT PRIMARY KEY, Seq INTEGER);
sqlite> .tables AllJobs LOCKSTAT_VALUE test_run12_data
DATA_STATUS_VALUE STATUS_VALUE test_run12_lock
The version of SQLite I'm using supports IF NOT EXISTS
, so why am I getting an error? 我使用的SQLite版本支持
IF NOT EXISTS
,为什么会出现错误?
This is my Perl code: 这是我的Perl代码:
#!/usr/bin/perl
use DBI;
my $driver = "SQLite";
$database = "test.db";
$dsn = "DBI:$driver:dbname=$database";
$dbh = DBI->connect( $dsn, undef, undef, { RaiseError => 1 } );
$dbh->do("CREATE TABLE IF NOT EXISTS DATA_STATUS_VALUE (TYPE TEXT PRIMARY KEY, Seq INTEGER);");
The version of SQLite I'm using supports IF NOT EXISTS, so why am I getting an error?
我使用的SQLite版本支持IF NOT EXISTS,那么为什么会出现错误?
Because DBD::SQLite isn't using the version of SQLite you already had installed. 因为DBD :: SQLite没有使用您已经安装的SQLite版本。 DBD::SQLite comes bundled with its own version of SQLite ;
DBD :: SQLite捆绑了自己的SQLite版本 ; it will use the bundled version unless you tell it to use another version when you compile it.
除非您在编译时告诉它使用另一个版本,否则它将使用捆绑版本。
You can find out the version of SQLite that DBD::SQLite is using by running: 您可以通过运行以下命令找出DBD :: SQLite使用的SQLite版本:
perl -MDBD::SQLite -le'print $DBD::SQLite::sqlite_version'
Support for CREATE TABLE ... IF NOT EXISTS
was added to SQLite in v3.3.0 . 对v3.3.0中的SQLite添加了对
CREATE TABLE ... IF NOT EXISTS
的支持 。 You should upgrade DBD::SQLite, since the newest version (1.50) comes bundled with SQLite 3.10.2. 您应该升级DBD :: SQLite,因为最新版本(1.50)与SQLite 3.10.2捆绑在一起。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.