mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 14:19:10 -04:00
fixed RT-99583
- avoid shortening a database filename with Win32::GetShortPathName, because it makes corresponding journal files (-journal, .wal etc) with the shortened filename, and those journal files will not be recognized by other sqlite3 clients (which may lead to inconsistensy/database corruption). - need to keep using Win32::GetShortPathName to make a parent directory canonical (so that sqlite3 can recognize a path with unicode characters correctly.)
This commit is contained in:
parent
c931e7c01d
commit
12509a7855
2 changed files with 39 additions and 10 deletions
|
@ -112,17 +112,13 @@ sub connect {
|
|||
|
||||
# To avoid unicode and long file name problems on Windows,
|
||||
# convert to the shortname if the file (or parent directory) exists.
|
||||
if ( $^O =~ /MSWin32/ and $real ne ':memory:' and $real ne '' and $real !~ /^file:/) {
|
||||
require Win32;
|
||||
if ( $^O =~ /MSWin32/ and $real ne ':memory:' and $real ne '' and $real !~ /^file:/ and !-f $real ) {
|
||||
require File::Basename;
|
||||
my ($file, $dir, $suffix) = File::Basename::fileparse($real);
|
||||
my $short = Win32::GetShortPathName($real);
|
||||
if ( $short && -f $short ) {
|
||||
# Existing files will work directly.
|
||||
$real = $short;
|
||||
} elsif ( -d $dir ) {
|
||||
# We are creating a new file.
|
||||
# Does the directory it's in at least exist?
|
||||
# We are creating a new file.
|
||||
# Does the directory it's in at least exist?
|
||||
if ( -d $dir ) {
|
||||
require Win32;
|
||||
$real = join '', grep { defined } Win32::GetShortPathName($dir), $file, $suffix;
|
||||
} else {
|
||||
# SQLite can't do mkpath anyway.
|
||||
|
|
|
@ -13,7 +13,7 @@ use t::lib::Test;
|
|||
use Test::More;
|
||||
BEGIN {
|
||||
if ( $] >= 5.008005 ) {
|
||||
plan( tests => (($^O eq 'cygwin') ? 14 : 26) );
|
||||
plan( tests => 2 + 12 * (($^O eq 'cygwin') ? 2 : 4) );
|
||||
} else {
|
||||
plan( skip_all => 'Unicode is not supported before 5.8.5' );
|
||||
}
|
||||
|
@ -45,6 +45,18 @@ foreach my $subdir ( 'longascii', 'adatb
|
|||
};
|
||||
is( $@, '', "Could connect to database in $subdir" );
|
||||
diag( $@ ) if $@;
|
||||
|
||||
# Reopen the database
|
||||
eval {
|
||||
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", undef, undef, {
|
||||
RaiseError => 1,
|
||||
PrintError => 0,
|
||||
} );
|
||||
isa_ok( $dbh, 'DBI::db' );
|
||||
};
|
||||
is( $@, '', "Could connect to database in $subdir" );
|
||||
diag( $@ ) if $@;
|
||||
|
||||
unlink(_path($dbfile)) if -e _path($dbfile);
|
||||
|
||||
# Repeat with the unicode flag on
|
||||
|
@ -59,6 +71,19 @@ foreach my $subdir ( 'longascii', 'adatb
|
|||
};
|
||||
is( $@, '', "Could connect to database in $subdir" );
|
||||
diag( $@ ) if $@;
|
||||
|
||||
# Reopen the database
|
||||
eval {
|
||||
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", undef, undef, {
|
||||
RaiseError => 1,
|
||||
PrintError => 0,
|
||||
sqlite_unicode => 1,
|
||||
} );
|
||||
isa_ok( $dbh, 'DBI::db' );
|
||||
};
|
||||
is( $@, '', "Could connect to database in $subdir" );
|
||||
diag( $@ ) if $@;
|
||||
|
||||
unlink(_path($ufile)) if -e _path($ufile);
|
||||
|
||||
# when the name of the database file has non-latin characters
|
||||
|
@ -67,6 +92,14 @@ foreach my $subdir ( 'longascii', 'adatb
|
|||
DBI->connect("dbi:SQLite:dbname=$dbfilex", "", "", {RaiseError => 1, PrintError => 0});
|
||||
};
|
||||
ok(!$@, "Could connect to database in $dbfilex") or diag $@;
|
||||
ok -f _path($dbfilex), "file exists: "._path($dbfilex)." ($dbfilex)";
|
||||
|
||||
# Reopen the database
|
||||
eval {
|
||||
DBI->connect("dbi:SQLite:dbname=$dbfilex", "", "", {RaiseError => 1, PrintError => 0});
|
||||
};
|
||||
ok(!$@, "Could connect to database in $dbfilex") or diag $@;
|
||||
|
||||
unlink(_path($dbfilex)) if -e _path($dbfilex);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue