简体   繁体   English

为什么即使我的SQLite版本支持`CREATE TABLE IF NOT EXISTS`,我仍会收到DBD :: SQLite语法错误?

[英]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.

相关问题 当我尝试创建具有外键约束的SQLite表时,为什么会出现“ DBD :: SQLite :: db失败:靠近“事务”:语法错误”的问题? - Why do I get 'DBD::SQLite::db do failed: near “transaction”: syntax error' when I try to create a SQLite table with a foreign key constraint? 如何使用DBD :: SQLite创建表触发器? - How do I create a table trigger with DBD::SQLite? Perl DBD :: SQLite :: db失败:语法错误 - Perl DBD::SQLite::db do failed: syntax error 为什么我在反引号中会出现语法错误,即使它在终端中有效? - Why do I get a syntax error in backticks, even though it works in terminal? 如何解决“ DBD :: Pg :: st执行失败:错误:准备好的语句已存在”错误 - How do I get around “DBD::Pg::st execute failed: ERROR: prepared statement already exists ” error 设置DBD :: SQLite以支持sqlite3的自定义版本 - Setting up DBD::SQLite to support a custom version of sqlite3 DBD::SQLite::db 准备失败:没有这样的表 Perl - DBD::SQLite::db prepare failed: no such table Perl 为什么即使在我的代码中没有出现“ tr”,我仍会收到错误“音译运算符中的无效范围“ B->””? - Why do I get the error 'Invalid range “ B->” in transliteration operator' even though `tr` doesn't appear in my code? 即使cpan告诉我已安装DBD :: mysql,为什么我的Perl脚本也找不到DBD / mysql.pm? - Why can't my Perl script locate DBD/mysql.pm even though cpan tells me DBD::mysql is installed? 为什么当我尝试使用 Perl 的 DBD::mysql 时出现错误? - Why do I get an error when I try to use Perl's DBD::mysql?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM