File: 20-driver-sqlite.t

package info (click to toggle)
libdata-objectdriver-perl 0.25-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 784 kB
  • sloc: perl: 3,795; sql: 64; makefile: 7
file content (68 lines) | stat: -rw-r--r-- 1,658 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
58
59
60
61
62
63
64
65
66
67
68
# $Id: 01-col-inheritance.t 989 2005-09-23 19:58:01Z btrott $

use strict;

use lib 't/lib';

$Data::ObjectDriver::DEBUG = 0;
use Test::More;
use DodTestUtil;

BEGIN { DodTestUtil->check_driver }

plan tests => 13;

setup_dbs({
    global => [ qw( wines ) ],
});

use Wine;
use Storable;

my $wine = Wine->new;
$wine->name("Saumur Champigny, Le Grand Clos 2001");
$wine->rating(4);

## generate some binary data (SQL_BLOB / MEDIUMBLOB)
my $glouglou = { tanin => "beaucoup", caudalies => "4" };
$wine->binchar("xxx\0yyy");
$wine->content(Storable::nfreeze($glouglou));
ok($wine->save, 'Object saved successfully');

my $wine_id = $wine->id;
undef $wine;
$wine = Wine->lookup($wine_id); 

ok $wine;
is_deeply Storable::thaw($wine->content), $glouglou;
SKIP: {
    skip "Please upgrade to DBD::SQLite 1.11", 1
        if $DBD::SQLite::VERSION < 1.11;
    is $wine->binchar, "xxx\0yyy";
};

## SQL_VARBINARY test (for binary CHAR)
my @results = Wine->search({ binchar => "xxx\0yyy"});
is scalar @results, 1;
is $results[0]->rating, 4;
is $results[0]->name, "Saumur Champigny, Le Grand Clos 2001";

## Test Bulk Loading
Wine->bulk_insert(['name', 'rating'], [['Caymus', 4], ['Thunderbird', 1], ['Stags Leap', 3]]);

my ($result) = Wine->search({name => 'Caymus'});
ok $result, 'Found Caymus';
is $result->rating, 4, 'Caymus is a 4';

($result) = Wine->search({name => 'Thunderbird'});
ok $result, 'Found Thunderbird';
is $result->rating, 1, 'Thunderbird is a 1';

($result) = Wine->search({name => 'Stags Leap'});
ok $result, 'Found Stags Leap';
is $result->rating, 3, 'Stags Leap is a 3';

END {
    disconnect_all(qw( Wine ));
    teardown_dbs(qw( global ));
}