File: 56_open_flags.t

package info (click to toggle)
libdbd-sqlite3-perl 1.44-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,756 kB
  • ctags: 10,154
  • sloc: ansic: 94,394; perl: 7,064; makefile: 6
file content (107 lines) | stat: -rw-r--r-- 2,472 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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 = 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;
}