mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 14:19:10 -04:00
added tests for open_flags/uri_filename
This commit is contained in:
parent
b1ac23d02e
commit
42b4281dcc
2 changed files with 329 additions and 0 deletions
107
t/56_open_flags.t
Normal file
107
t/56_open_flags.t
Normal file
|
@ -0,0 +1,107 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
BEGIN {
|
||||
$| = 1;
|
||||
$^W = 1;
|
||||
}
|
||||
|
||||
use t::lib::Test;
|
||||
use Test::More tests => 8;
|
||||
use DBI;
|
||||
use DBD::SQLite;
|
||||
|
||||
my $dbfile = 'foo';
|
||||
unlink $dbfile if -f $dbfile;
|
||||
|
||||
{
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:$dbfile", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
sqlite_open_flags => DBD::SQLite::OPEN_READONLY,
|
||||
});
|
||||
};
|
||||
ok $@ && !$dbh && !-f $dbfile, "failed to open a nonexistent dbfile for readonly";
|
||||
unlink $dbfile if -f $dbfile;
|
||||
}
|
||||
|
||||
{
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:$dbfile", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
sqlite_open_flags => DBD::SQLite::OPEN_READWRITE,
|
||||
});
|
||||
};
|
||||
ok $@ && !$dbh && !-f $dbfile, "failed to open a nonexistent dbfile for readwrite (without create)";
|
||||
unlink $dbfile if -f $dbfile;
|
||||
}
|
||||
|
||||
{
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:$dbfile", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
sqlite_open_flags => DBD::SQLite::OPEN_READWRITE|DBD::SQLite::OPEN_CREATE,
|
||||
});
|
||||
};
|
||||
ok !$@ && $dbh && -f $dbfile, "created a dbfile for readwrite";
|
||||
$dbh->disconnect;
|
||||
unlink $dbfile if -f $dbfile;
|
||||
}
|
||||
|
||||
{
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:$dbfile", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
sqlite_open_flags => DBD::SQLite::OPEN_URI,
|
||||
});
|
||||
};
|
||||
ok !$@ && $dbh && -f $dbfile, "readwrite/create flags are turned on if no readonly/readwrite/create flags are set";
|
||||
$dbh->disconnect;
|
||||
unlink $dbfile if -f $dbfile;
|
||||
}
|
||||
|
||||
{
|
||||
eval {
|
||||
DBI->connect("dbi:SQLite:$dbfile", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
});
|
||||
};
|
||||
ok !$@ && -f $dbfile, "created a dbfile";
|
||||
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:$dbfile", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
sqlite_open_flags => DBD::SQLite::OPEN_READONLY,
|
||||
});
|
||||
};
|
||||
ok !$@ && $dbh, "opened an existing dbfile for readonly";
|
||||
$dbh->disconnect;
|
||||
unlink $dbfile if -f $dbfile;
|
||||
}
|
||||
|
||||
{
|
||||
eval {
|
||||
DBI->connect("dbi:SQLite:$dbfile", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
});
|
||||
};
|
||||
ok !$@ && -f $dbfile, "created a dbfile";
|
||||
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:$dbfile", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
sqlite_open_flags => DBD::SQLite::OPEN_READWRITE,
|
||||
});
|
||||
};
|
||||
ok !$@ && $dbh, "opened an existing dbfile for readwrite";
|
||||
$dbh->disconnect;
|
||||
unlink $dbfile if -f $dbfile;
|
||||
}
|
222
t/57_uri_filename.t
Normal file
222
t/57_uri_filename.t
Normal file
|
@ -0,0 +1,222 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
BEGIN {
|
||||
$| = 1;
|
||||
$^W = 1;
|
||||
}
|
||||
|
||||
use t::lib::Test;
|
||||
use Test::More tests => 17;
|
||||
use DBI;
|
||||
use DBD::SQLite;
|
||||
|
||||
my $dbfile = 'foo';
|
||||
my %uri = (
|
||||
base => 'file:foo',
|
||||
ro => 'file:foo?mode=ro',
|
||||
rw => 'file:foo?mode=rw',
|
||||
rwc => 'file:foo?mode=rwc',
|
||||
);
|
||||
|
||||
sub cleanup {
|
||||
unlink $dbfile if -f $dbfile;
|
||||
unlink "file" if -f "file"; # for Win32
|
||||
for (keys %uri) {
|
||||
unlink $uri{$_} if -f $uri{$_};
|
||||
}
|
||||
}
|
||||
|
||||
cleanup();
|
||||
|
||||
{
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:$uri{base}", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
});
|
||||
};
|
||||
ok !$@ && $dbh && !-f $dbfile, "correct database is not created for uri";
|
||||
$dbh->disconnect;
|
||||
cleanup();
|
||||
}
|
||||
|
||||
# uri=(uri)
|
||||
{
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:uri=$uri{base}", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
});
|
||||
};
|
||||
ok !$@ && $dbh && -f $dbfile && !-f $uri{base}, "correct database is created for uri";
|
||||
$dbh->disconnect;
|
||||
cleanup();
|
||||
}
|
||||
|
||||
{
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:uri=$uri{ro}", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
});
|
||||
};
|
||||
ok $@ && !$dbh && !-f $dbfile && !-f $uri{base} && !-f $uri{ro}, "failed to open a nonexistent readonly database for uri";
|
||||
cleanup();
|
||||
}
|
||||
|
||||
{
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:uri=$uri{rw}", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
});
|
||||
};
|
||||
ok $@ && !$dbh && !-f $dbfile && !-f $uri{base} && !-f $uri{rw}, "failed to open a nonexistent readwrite database for uri";
|
||||
cleanup();
|
||||
}
|
||||
|
||||
{
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:uri=$uri{rwc}", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
});
|
||||
};
|
||||
ok !$@ && $dbh && -f $dbfile && !-f $uri{base} && !-f $uri{rwc}, "correct database is created for uri";
|
||||
$dbh->disconnect;
|
||||
cleanup();
|
||||
}
|
||||
|
||||
{
|
||||
eval {
|
||||
DBI->connect("dbi:SQLite:$dbfile", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
});
|
||||
};
|
||||
ok !$@ && -f $dbfile, "created a dbfile";
|
||||
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:uri=$uri{ro}", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
});
|
||||
};
|
||||
ok !$@ && $dbh && -f $dbfile && !-f $uri{base} && !-f $uri{ro}, "opened a correct readonly database for uri";
|
||||
$dbh->disconnect;
|
||||
cleanup();
|
||||
}
|
||||
|
||||
{
|
||||
eval {
|
||||
DBI->connect("dbi:SQLite:$dbfile", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
});
|
||||
};
|
||||
ok !$@ && -f $dbfile, "created a dbfile";
|
||||
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:uri=$uri{rw}", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
});
|
||||
};
|
||||
ok !$@ && $dbh && -f $dbfile && !-f $uri{base} && !-f $uri{rw}, "opened a correct readwrite database for uri";
|
||||
$dbh->disconnect;
|
||||
cleanup();
|
||||
}
|
||||
|
||||
# OPEN_URI flag
|
||||
{
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:$uri{base}", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
sqlite_open_flags => DBD::SQLite::OPEN_URI,
|
||||
});
|
||||
};
|
||||
ok !$@ && $dbh && -f $dbfile && !-f $uri{base}, "correct database is created for uri";
|
||||
$dbh->disconnect;
|
||||
cleanup();
|
||||
}
|
||||
|
||||
{
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:$uri{ro}", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
sqlite_open_flags => DBD::SQLite::OPEN_URI,
|
||||
});
|
||||
};
|
||||
ok $@ && !$dbh && !-f $dbfile && !-f $uri{base} && !-f $uri{ro}, "failed to open a nonexistent readonly database for uri";
|
||||
cleanup();
|
||||
}
|
||||
|
||||
{
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:$uri{rw}", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
sqlite_open_flags => DBD::SQLite::OPEN_URI,
|
||||
});
|
||||
};
|
||||
ok $@ && !$dbh && !-f $dbfile && !-f $uri{base} && !-f $uri{rw}, "failed to open a nonexistent readwrite database for uri";
|
||||
cleanup();
|
||||
}
|
||||
|
||||
{
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:$uri{rwc}", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
sqlite_open_flags => DBD::SQLite::OPEN_URI,
|
||||
});
|
||||
};
|
||||
ok !$@ && $dbh && -f $dbfile && !-f $uri{base} && !-f $uri{rwc}, "correct database is created for uri";
|
||||
$dbh->disconnect;
|
||||
cleanup();
|
||||
}
|
||||
|
||||
{
|
||||
eval {
|
||||
DBI->connect("dbi:SQLite:$dbfile", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
});
|
||||
};
|
||||
ok !$@ && -f $dbfile, "created a dbfile";
|
||||
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:$uri{ro}", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
sqlite_open_flags => DBD::SQLite::OPEN_URI,
|
||||
});
|
||||
};
|
||||
ok !$@ && $dbh && -f $dbfile && !-f $uri{base} && !-f $uri{ro}, "opened a correct readonly database for uri";
|
||||
$dbh->disconnect;
|
||||
cleanup();
|
||||
}
|
||||
|
||||
{
|
||||
eval {
|
||||
DBI->connect("dbi:SQLite:$dbfile", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
});
|
||||
};
|
||||
ok !$@ && -f $dbfile, "created a dbfile";
|
||||
|
||||
my $dbh = eval {
|
||||
DBI->connect("dbi:SQLite:$uri{rw}", undef, undef, {
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
sqlite_open_flags => DBD::SQLite::OPEN_URI,
|
||||
});
|
||||
};
|
||||
ok !$@ && $dbh && -f $dbfile && !-f $uri{base} && !-f $uri{rw}, "opened a correct readwrite database for uri";
|
||||
$dbh->disconnect;
|
||||
cleanup();
|
||||
}
|
Loading…
Add table
Reference in a new issue