简体   繁体   中英

Sqlite connection string in perl

I am using below sqlite connection string in perl to connect sqlite database and getting following below error

Can't set DBI::db=HASH(0x2c34194)->{PRAGMA journal_mode}: unrecognised attribute name or invalid value

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. It shouldn't be part of the connection string, but an SQL command that is run once you have connected.

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. So you only need to set it once, and then you can drop it completely from your connection code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM