[英]Sqlite connection string in perl
I am using below sqlite connection string in perl to connect sqlite database and getting following below error 我在Perl中使用下面的sqlite连接字符串来连接sqlite数据库并得到以下错误
Can't set DBI::db=HASH(0x2c34194)->{PRAGMA journal_mode}: unrecognised attribute name or invalid value
无法设置DBI :: db = HASH(0x2c34194)-> {PRAGMA journal_mode}:无法识别的属性名称或无效值
my $driver = "SQLite";
my $database = "C:\\Sample\\Sample_Sqlite\\Activities.db3;PRAGMA journal_mode=WAL;";
my $dsn = "DBI:$driver:dbname=$database";
print $dsn;
my $dbh = DBI->connect(
$dsn,
{ RaiseError => 1 },
) or die $DBI::errstr;
Reading the section on PRAGMA in the DBD::SQLite documentation , it looks like you're setting the PRAGMA at the wrong time. 阅读DBD :: SQLite文档中有关PRAGMA的部分 ,似乎您在错误的时间设置了PRAGMA。 It shouldn't be part of the connection string, but an SQL command that is run once you have connected.
它不应该是连接字符串的一部分,而应该是连接后运行的SQL命令。
my $driver = "SQLite";
my $database = "C:\\Sample\\Sample_Sqlite\\Activities.db3";
my $dsn = "DBI:$driver:dbname=$database";
print $dsn;
my $dbh = DBI->connect(
$dsn,
{ RaiseError => 1 },
) or die $DBI::errstr;
$dbh->do('PRAGMA journal_mode=WAL');
Update: It's probably also worth noting that the journal_mode
setting is persistent. 更新:可能还值得注意的是
journal_mode
设置是持久的。 So you only need to set it once, and then you can drop it completely from your connection code. 因此,您只需要设置一次,然后就可以从连接代码中完全删除它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.