mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 14:19:10 -04:00
avoid a race condition (to resolve RT#92322)
This commit is contained in:
parent
51f8f7a7c1
commit
9dd2cb6187
3 changed files with 9 additions and 10 deletions
|
@ -11,7 +11,7 @@ use Test::More tests => 8;
|
||||||
use DBI;
|
use DBI;
|
||||||
use DBD::SQLite;
|
use DBD::SQLite;
|
||||||
|
|
||||||
my $dbfile = 'foo';
|
my $dbfile = dbfile('foo');
|
||||||
unlink $dbfile if -f $dbfile;
|
unlink $dbfile if -f $dbfile;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,12 +11,12 @@ use Test::More tests => 17;
|
||||||
use DBI;
|
use DBI;
|
||||||
use DBD::SQLite;
|
use DBD::SQLite;
|
||||||
|
|
||||||
my $dbfile = 'foo';
|
my $dbfile = dbfile('foo');
|
||||||
my %uri = (
|
my %uri = (
|
||||||
base => 'file:foo',
|
base => "file:$dbfile",
|
||||||
ro => 'file:foo?mode=ro',
|
ro => "file:$dbfile?mode=ro",
|
||||||
rw => 'file:foo?mode=rw',
|
rw => "file:$dbfile?mode=rw",
|
||||||
rwc => 'file:foo?mode=rwc',
|
rwc => "file:$dbfile?mode=rwc",
|
||||||
);
|
);
|
||||||
|
|
||||||
sub cleanup {
|
sub cleanup {
|
||||||
|
|
|
@ -25,7 +25,7 @@ BEGIN {
|
||||||
# Always load the DBI module
|
# Always load the DBI module
|
||||||
use DBI ();
|
use DBI ();
|
||||||
|
|
||||||
sub dbfile { $dbfiles{$_[0]} }
|
sub dbfile { $dbfiles{$_[0]} ||= (defined $_[0] && length $_[0] && $_[0] ne ':memory:') ? $_[0] . $$ : $_[0] }
|
||||||
|
|
||||||
# Delete temporary files
|
# Delete temporary files
|
||||||
sub clean {
|
sub clean {
|
||||||
|
@ -47,9 +47,8 @@ END { clean() }
|
||||||
# A simplified connect function for the most common case
|
# A simplified connect function for the most common case
|
||||||
sub connect_ok {
|
sub connect_ok {
|
||||||
my $attr = { @_ };
|
my $attr = { @_ };
|
||||||
my $dbfile = defined $attr->{dbfile} ? delete $attr->{dbfile} : ':memory:';
|
my $dbfile = dbfile(defined $attr->{dbfile} ? delete $attr->{dbfile} : ':memory:');
|
||||||
$dbfiles{$dbfile} = (defined $dbfile && length $dbfile && $dbfile ne ':memory:') ? $dbfile . $$ : $dbfile;
|
my @params = ( "dbi:SQLite:dbname=$dbfile", '', '' );
|
||||||
my @params = ( "dbi:SQLite:dbname=$dbfiles{$dbfile}", '', '' );
|
|
||||||
if ( %$attr ) {
|
if ( %$attr ) {
|
||||||
push @params, $attr;
|
push @params, $attr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue