File: 04sqlite.t

package info (click to toggle)
libtest-databaserow-perl 2.04-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 296 kB
  • ctags: 177
  • sloc: perl: 3,062; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,196 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl -w

########################################################################
# this tests with a "real" database if we have the DBD::SQLite
# module installed
########################################################################

use strict;

# check if we can use DBD::SQLite
BEGIN {
  unless (eval "use DBD::SQLite; 1") {
    print "1..0 # Skipped: no DBD::SQLite\n";
    exit;
  }
}

use Test::More tests => 1;

use Test::DatabaseRow;
use DBI;
use File::Temp qw(tempdir);

my $dir = tempdir( CLEANUP => 1 );
chdir($dir)
  or die "Can't change directory to temp dir";
END {
  chdir('..');  # needed so deleting temp dir works on Windows
}
my $dbh = DBI->connect("dbi:SQLite:dbname=dbfile","","");

$dbh->do(<<'SQL');
CREATE TABLE perlmongers (
  first_name STRING,
  nick STRING
);
SQL

my %data = (
  "Andrew"  => "Zefram",
  "Dagfinn" => "Ilmari",
  "Mark"    => "Trelane",
  "Leon"    => "acme",
);

$dbh->do(<<'SQL', {}, $_, $data{$_}) foreach keys %data;
INSERT INTO perlmongers (first_name, nick) VALUES (?, ?)
SQL

row_ok(
  dbh => $dbh,
  tests => [ nick => "Trelane" ],
  sql => [ <<'SQL', "Mark"]);
    SELECT *
      FROM perlmongers
     WHERE first_name = ?
SQL