| 1 | 10 | ▶ | use Test::More; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package # Hide from PAUSE | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | Test::DBO; | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use sigtrap qw(die normal-signals); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use Scalar::Util qw(blessed reftype); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use Test::More; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 10 | ▶ | use DBIx::DBO; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 10 | ▶ | require Carp::Heavy if eval "$Carp::VERSION < 1.12"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=8 SCAR=27.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # If we are using a version of Test::More older than 0.82 ... | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 10 | ▶ | unless (exists $Test::More::{note}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | eval q# | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | sub Test::More::note { | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | local $Test::Builder::{_print_diag} = $Test::Builder::{_print}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | Test::More->builder->diag(@_); | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | *note = \&Test::More::note; | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | *{caller(2).'::note'} = \¬e; | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | #; | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | die $@ if $@; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # Set up DebugSQL if requested | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 10 | ▶ | if ($ENV{DBO_DEBUG_SQL}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | diag "DBO_DEBUG_SQL=$ENV{DBO_DEBUG_SQL}"; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | DBIx::DBO->config(DebugSQL => $ENV{DBO_DEBUG_SQL}); | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # Set up $Carp::Verbose if requested | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 10 | ▶ | if ($ENV{DBO_CARP_VERBOSE}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | diag "DBO_CARP_VERBOSE=$ENV{DBO_CARP_VERBOSE}"; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $Carp::Verbose = $ENV{DBO_CARP_VERBOSE}; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | } elsif ($ENV{AUTOMATED_TESTING}) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 10 | $Carp::Verbose = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # Store the last SQL executed, and show debug info | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | DBIx::DBO->config(HookSQL => sub { | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 87 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=21.7
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 87 | my $loc = Carp::short_error_loc(); | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 87 | my %i = Carp::caller_info($loc); | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 87 | $me->config(LastSQL => [$i{'sub'}, @_]); | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 87 | ▶ | my $dbg = $ENV{DBO_DEBUG_SQL} or return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $trace; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($dbg > 1) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $trace = "\t$i{sub_name} called at $i{file} line $i{line}\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | $trace .= "\t$i{sub_name} called at $i{file} line $i{line}\n" while %i = Carp::caller_info(++$loc); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $trace = "\t$i{sub} called at $i{file} line $i{line}\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $sql = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | Test::More::diag "DEBUG_SQL: $sql\nDEBUG_SQL: (".join(', ', map $me->rdbh->quote($_), @_).")\n".$trace; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 10 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 10 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # Remove CARP_NOT during tests | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | package # Hide from PAUSE | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | DBIx::DBO; | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | *DBIx::DBO::croak = | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | *DBIx::DBO::Query::croak = | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | *DBIx::DBO::Table::croak = | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | *DBIx::DBO::Row::croak = sub { | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 38 | ▶ | local @DBIx::DBO::DBD::CARP_NOT = () if $Carp::Verbose; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.7
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 38 | ▶ | local $Carp::CarpLevel = $Carp::CarpLevel + 1 if $Carp::Verbose; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 38 | &Carp::croak; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | # Fix SvREFCNT with Devel::Cover | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | package # Hide from PAUSE | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | DBIx::DBO::Query; | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | *DBIx::DBO::Query::SvREFCNT = sub { | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 48 | ▶ | return Devel::Peek::SvREFCNT($_[0]) - 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 10 | ▶ | } if exists $INC{'Devel/Cover.pm'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 10 | our $dbd; | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | 10 | our $dbd_name; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 10 | (our $test_db = "DBO_${DBIx::DBO::VERSION}_test_db") =~ s/\W/_/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 10 | (our $test_sch = "DBO_${DBIx::DBO::VERSION}_test_sch") =~ s/\W/_/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 10 | (our $test_tbl = "DBO_${DBIx::DBO::VERSION}_test_tbl") =~ s/\W/_/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | 10 | our @_cleanup_sql; | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 10 | our $case_sensitivity_sql = 'SELECT ? LIKE ?'; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 10 | our %can; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 11 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=19 SCAR=32.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 11 | ▶ | $dbd = shift or return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 11 | $dbd_name = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 11 | my %opt = splice @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 11 | ▶ | grep $_ eq $dbd, DBI->available_drivers | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | or plan skip_all => "No $dbd driver available!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # Catch install_driver errors | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 8 | eval { DBI->install_driver($dbd) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | 8 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | die $@ if $@ !~ /\binstall_driver\b/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | plan skip_all => $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # Skip tests with missing module requirements | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 8 | ▶ | unless (eval { DBIx::DBO::DBD->_require_dbd_class($dbd) }) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | ▶ | if ($@ =~ /^Can't locate ([\w\/]+)\.pm in \@INC /m) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # Module is not installed | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ($_ = "$1 is required") =~ s'/'::'g; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | } elsif ($@ =~ /^([\w:]+ version [\d\.]+ required.*?) at /m) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # Module is not correct version | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ($_ = $1); | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | } elsif ($@ =~ /^(\Q$dbd_name\E is not yet supported)/m) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # DBM is not yet supported | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | ($_ = $1); | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | die $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | plan skip_all => "Can't load $dbd driver: $_"; | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 10 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 7 | *{caller().'::sql_err'} = \&sql_err; | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 7 | ▶ | if (exists $opt{tempdir}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | require File::Temp; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | my $dir = File::Temp::tempdir('tmp_XXXX', CLEANUP => 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | if (ref $opt{tempdir}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ${$opt{tempdir}} = $dir; | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | ▶ | chdir $dir or die "Can't cd to $dir: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | ▶ | eval "END { chdir '..' }"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
END: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # Query tests must produce the same result regardless of caching | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 7 | ▶ | DBIx::DBO->config(CacheQuery => defined $ENV{DBO_CACHE_QUERY} ? $ENV{DBO_CACHE_QUERY} : int rand 2); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 7 | ▶ | if (exists $opt{try_connect}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | try_to_connect($opt{try_connect}); | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 7 | ▶ | note "DBD::$dbd ".${ $::DBD::{$dbd.'::'}{VERSION} } if exists $opt{try_connect} or exists $opt{connect_ok}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $opt{"try_connect"} or exists $opt{"connect_ok"}
MC/DC50%1/2
exists $opt{"try_connect"} or exists $opt{"connect_ok"}
exists $opt{"try_connect"}
exists $opt{"connect_ok"}
Truth table66%2/3
A or B
A= exists $opt{"try_connect"}B= exists $opt{"connect_ok"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 7 | ▶ | return unless exists $opt{tests}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 6 | ▶ | if (exists $opt{connect_ok}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | ▶ | my $dbo = connect_ok(@{$opt{connect_ok}}) or plan skip_all => "Can't connect: $DBI::errstr"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | plan tests => $opt{tests}; | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | pass "Connect to $dbd_name"; | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | isa_ok $dbo, 'DBIx::DBO', '$dbo'; | |||||||||||||||||||||||||||||||||||||||||||||
| 160 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 4 | plan tests => $opt{tests}; | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | sub sql_err { | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sql_err: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my($cmd, $sql, @bind) = @{$me->config('LastSQL')}; | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $sql =~ s/^/ /mg; | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | my @err = ($DBI::errstr || $me->rdbh->errstr || '???'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$DBI::errstr || $me->rdbh->errstr || '???'
$DBI::errstr or $me->rdbh->errstr
MC/DC0%0/2
$DBI::errstr || $me->rdbh->errstr || '???'
$DBI::errstr
$me->rdbh->errstr
Truth table0%0/3
A or B
A= $DBI::errstrB= $me->rdbh->errstr
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | unshift @err, 'Bind Values: ('.join(', ', map $me->rdbh->quote($_), @bind).')' if @bind; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | unshift @err, "SQL command failed: $cmd", $sql.';'; | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $err[-1] =~ s/ at line \d+$//; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | join "\n", @err; | |||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | sub connect_dbo { | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | ▶ | my($dsn, $user, $pass) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect_dbo: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 2 | ▶ | defined $dsn or $dsn = ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 2 | DBIx::DBO->connect("DBI:$dbd:$dsn", $user, $pass, {RaiseError => 0}); | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | sub try_to_connect { | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 2 | ▶ | my $dbo_ref = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
try_to_connect: called CC=3 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 2 | my @env = map $ENV{"DBO_TEST_\U$dbd\E_$_"}, qw(DSN USER PASS); | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | 2 | ▶ | if (grep defined, @env) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | return $$dbo_ref if $$dbo_ref = connect_dbo(@env); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | plan skip_all => "Can't connect: $DBI::errstr"; | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | sub connect_ok { | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 2 | ▶ | my $dbo_ref = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect_ok: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 2 | ▶ | return try_to_connect($dbo_ref) || ($$dbo_ref = connect_dbo(@_)); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
try_to_connect($dbo_ref) || ($$dbo_ref = connect_dbo(@_))
MC/DC0%0/2
try_to_connect($dbo_ref) || ($$dbo_ref = connect_dbo(@_))
try_to_connect($dbo_ref)
($$dbo_ref = connect_dbo(@_))
Truth table33%1/3
A || B
A= try_to_connect($dbo_ref)B= ($$dbo_ref = connect_dbo(@_))
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | sub basic_methods { | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | my $dbo = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
basic_methods: called CC=35 SCAR=44.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | note 'Testing with: CacheQuery => '.DBIx::DBO->config('CacheQuery'); | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # Create a DBO from DBI handles | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | isa_ok(DBIx::DBO->new($dbo->{dbh}, $dbo->{rdbh}), 'DBIx::DBO', 'Method DBIx::DBO->new, $dbo'); | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 1 | my $quoted_table = $dbo->{dbd_class}->_qi($dbo, $test_sch, $test_tbl); | |||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | my @quoted_cols = map $dbo->{dbd_class}->_qi($dbo, $_), qw(type id name); | |||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1 | my $t; | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | my $create_table = "CREATE TABLE $quoted_table ($quoted_cols[1] ". | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | ($can{auto_increment_id} || 'INT NOT NULL').", $quoted_cols[2] VARCHAR(20)". | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | ▶ | ($can{auto_increment_id} ? '' : ", PRIMARY KEY ($quoted_cols[1])").')'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$Test::DBO::can{'auto_increment_id'} || 'INT NOT NULL'
MC/DC0%0/1
$Test::DBO::can{'auto_increment_id'} || 'INT NOT NULL'
$Test::DBO::can{'auto_increment_id'}
Truth table50%1/2
A
A= $Test::DBO::can{'auto_increment_id'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # Create a test table with a multi-column primary key | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | ▶ | if ($dbo->do("CREATE TABLE $quoted_table ($quoted_cols[2] VARCHAR(20), $quoted_cols[1] INT, $quoted_cols[0] VARCHAR(8), PRIMARY KEY ($quoted_cols[0], $quoted_cols[1]))")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 1 | pass 'Create the test table: '.$quoted_table; | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # Create a table object | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | $t = $dbo->table([undef, $test_tbl]); | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | isa_ok $t, 'DBIx::DBO::Table', '$t'; | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # Check the Primary Keys | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | ▶ | is_deeply $t->{PrimaryKeys}, ['type', 'id'], 'Check PrimaryKeys' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | or diag Test::DBO::Dump($t); | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # Recreate our test table | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | ▶ | $dbo->do("DROP TABLE $quoted_table") && $dbo->do($create_table) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$dbo->do("DROP TABLE $quoted_table") and $dbo->do($create_table) or diag(sql_err($dbo))
$dbo->do("DROP TABLE $quoted_table") and $dbo->do($create_table)
MC/DC0%0/3
$dbo->do("DROP TABLE $quoted_table") and $dbo->do($create_table) or diag(sql_err($dbo))
$dbo->do("DROP TABLE $quoted_table")
$dbo->do($create_table)
diag(sql_err($dbo))
Truth table20%1/5
A and B or C
A= $dbo->do("DROP TABLE $quoted_table")B= $dbo->do($create_table)C= diag(sql_err($dbo))
| |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | or diag sql_err($dbo) or die "Can't recreate the test table!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # Remove the created table during cleanup | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 1 | todo_cleanup("DROP TABLE $quoted_table"); | |||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | $dbo->{dbd_class}->_get_table_info($dbo, $t->{Schema}, $t->{Name}); | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | $t = $t->new($dbo, [$test_sch, $test_tbl]); | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | diag sql_err($dbo); | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | SKIP: { | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | skip "Can't create a multi-column primary key", 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # Create the test table | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | ok $dbo->do($create_table), 'Create the test table' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
&ok(scalar $dbo->do($create_table), "Create the test table") or diag(sql_err($dbo))
MC/DC0%0/2
&ok(scalar $dbo->do($create_table), "Create the test table") or diag(sql_err($dbo))
&ok(scalar $dbo->do($create_table), "Create the test table")
diag(sql_err($dbo))
Truth table0%0/3
A or B
A= &ok(scalar $dbo->do($create_table), "Create the test table")B= diag(sql_err($dbo))
| |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | or diag sql_err($dbo) or die "Can't create the test table!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # Remove the created table during cleanup | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | todo_cleanup("DROP TABLE $quoted_table"); | |||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # Create a table object | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | $t = $dbo->table([$test_sch, $test_tbl]); | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | isa_ok $t, 'DBIx::DBO::Table', '$t'; | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 1 | ▶ | die "Couldn't create the DBIx::DBO::Table object!" unless $t; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1 | is $t->dbo, $dbo, 'Method DBIx::DBO::Table->dbo'; | |||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | pass 'Method DBIx::DBO->do'; | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1 | ok my $table_info = $dbo->table_info([$test_sch, $test_tbl]), 'Method DBIx::DBO->table_info'; | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | is $table_info, $dbo->table_info($quoted_table), 'Method DBIx::DBO->table_info (quoted)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | ▶ | is $table_info, $dbo->table_info(defined $test_sch ? "$test_sch.$test_tbl" : $test_tbl), | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 'Method DBIx::DBO->table_info (unquoted)'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # Insert data | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | ▶ | $dbo->do("INSERT INTO $quoted_table VALUES (1, 'John Doe')") or diag sql_err($dbo); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | ▶ | $dbo->do("INSERT INTO $quoted_table VALUES (?, ?)", undef, 2, 'Jane Smith') or diag sql_err($dbo); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # Check the DBO select* methods | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | my $rv = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | ▶ | @$rv = $dbo->selectrow_array("SELECT * FROM $quoted_table") or diag sql_err($dbo); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | is_deeply $rv, [1,'John Doe'], 'Method DBIx::DBO->selectrow_array'; | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | ▶ | $rv = $dbo->selectrow_arrayref("SELECT * FROM $quoted_table") or diag sql_err($dbo); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | is_deeply $rv, [1,'John Doe'], 'Method DBIx::DBO->selectrow_arrayref'; | |||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 1 | ▶ | $rv = $dbo->selectall_arrayref("SELECT * FROM $quoted_table") or diag sql_err($dbo); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 1 | is_deeply $rv, [[1,'John Doe'],[2,'Jane Smith']], 'Method DBIx::DBO->selectall_arrayref'; | |||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # Insert via table object | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | ▶ | $rv = $t->insert(id => 3, name => 'Uncle Arnie') or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | ok $rv, 'Method DBIx::DBO::Table->insert'; | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 1 | is_deeply [$t->columns], [qw(id name)], 'Method DBIx::DBO::Table->columns'; | |||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # Create a column object | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 1 | my $c = $t->column('id'); | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | 1 | isa_ok $c, 'DBIx::DBO::Column', '$c'; | |||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # Fetch one value from the Table | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | is $t->fetch_value($t ** 'name', id => 3), 'Uncle Arnie', 'Method DBIx::DBO::Table->fetch_value'; | |||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # Fetch one value from the Table | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | is_deeply $t->fetch_hash(id => \3), {id=>3,name=>'Uncle Arnie'}, 'Method DBIx::DBO::Table->fetch_hash'; | |||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # Fetch one value from the Table | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 1 | my $r = $t->fetch_row(id => 3, name => \'NOT NULL'); | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | is $r->{name}, 'Uncle Arnie', 'Method DBIx::DBO::Table->fetch_row'; | |||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # Fetch a column arrayref from the Table | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 1 | is_deeply $t->fetch_column($t ** 'name', id => 3), ['Uncle Arnie'], 'Method DBIx::DBO::Table->fetch_column'; | |||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # Advanced insert using a column object | ||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | ▶ | $rv = $t->insert($c => {FUNC => '4'}, name => 'NotUsed', name => \"'James Bond'") or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | ok $rv, 'Method DBIx::DBO::Table->insert (complex values)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 303 | 1 | is $t->fetch_value('name', id => 4), 'James Bond', 'Method DBIx::DBO::Table->insert (remove duplicate cols)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # Delete via table object | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 1 | ▶ | $rv = $t->delete(id => 3) or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | is $rv, 1, 'Method DBIx::DBO::Table->delete'; | |||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 1 | ▶ | if ($can{auto_increment_id}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 1 | ▶ | $t->insert(name => 'Vernon Lyon') or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | $t->insert(id => 5, name => 'Vernon Lyon') or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||
| 315 | SKIP: { | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | ▶ | skip "No auto-increment $quoted_cols[1] column", 1 unless $can{auto_increment_id}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | ▶ | is $t->last_insert_id, 5, 'Method DBIx::DBO::Table->last_insert_id' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | or $t->delete(name => 'Vernon Lyon'), $t->insert(id => 5, name => 'Vernon Lyon'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 1 | my $bulk_data = $dbo->query($t)->arrayref({ Slice => {} }); | |||||||||||||||||||||||||||||||||||||||||||||
| 322 | SKIP: { | ||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 1 | ▶ | unless ($can{truncate}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 1 | ▶ | $t->delete or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | skip 'TRUNCATE TABLE is not supported', 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | $t->truncate or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | is $t->fetch_value('id'), undef, 'Method DBIx::DBO::Table->truncate'; | |||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # Bulk insert | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 1 | ▶ | $rv = $t->bulk_insert(rows => [map [@$_{qw(id name)}], @$bulk_data]) or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 1 | is $rv, 4, 'Method DBIx::DBO::Table->bulk_insert (ARRAY)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 334 | 1 | ▶ | $t->delete or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 1 | ▶ | $rv = $t->bulk_insert(rows => \@$bulk_data) or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 1 | is $rv, 4, 'Method DBIx::DBO::Table->bulk_insert (HASH)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 338 | 1 | ▶ | $t->delete or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 1 | ▶ | $rv = $t->bulk_insert(columns => [qw(name id)], rows => [map [@$_{qw(name id)}], @$bulk_data]) or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 1 | is $rv, 4, 'Method DBIx::DBO::Table->bulk_insert (ARRAY)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 342 | 1 | ▶ | $t->delete or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 1 | ▶ | $rv = $t->bulk_insert(columns => [qw(name id)], rows => \@$bulk_data) or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 1 | is $rv, 4, 'Method DBIx::DBO::Table->bulk_insert (HASH)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 1 | return $t; | |||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | sub advanced_table_methods { | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 1 | ▶ | my $dbo = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
advanced_table_methods: called CC=6 SCAR=18.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 1 | my $t = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | SKIP: { | ||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | ▶ | skip "No test table for advanced table tests", 2 unless $t; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # Advanced insert | ||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 1 | ▶ | my $rv = $t->insert(id => { FUNC => '? + 3', VAL => 3 }, name => \"'Harry Harrelson'") or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 1 | ok $rv, 'Method DBIx::DBO::Table->insert (advanced)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | ▶ | $t->insert(id => 7, name => 'Amanda Huggenkiss') or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 1 | ▶ | $t->insert(id => 8, name => undef) or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | # Advanced delete | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 1 | ▶ | $rv = $t->delete(id => \'NOT NULL', name => undef) or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 1 | ok $rv, 'Method DBIx::DBO::Table->delete (advanced)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||
| 370 | sub skip_advanced_table_methods { | ||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | my $dbo = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
skip_advanced_table_methods: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my $t = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | note "No advanced table tests for $dbd_name"; | |||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | $t->insert(id => 6, name => 'Harry Harrelson') or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | $t->insert(id => 7, name => 'Amanda Huggenkiss') or diag sql_err($t); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||
| 379 | sub row_methods { | ||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 1 | ▶ | my $dbo = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
row_methods: called CC=12 SCAR=26.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 1 | my $t = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 1 | my $r = DBIx::DBO::Row->new($dbo, $t->_from); | |||||||||||||||||||||||||||||||||||||||||||||
| 384 | 1 | isa_ok $r, 'DBIx::DBO::Row', '$r (using quoted table name)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 1 | $r = $dbo->row([ @$t{qw(Schema Name)} ]); | |||||||||||||||||||||||||||||||||||||||||||||
| 387 | 1 | isa_ok $r, 'DBIx::DBO::Row', '$r (using table name array)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | $r = $dbo->row($t); | |||||||||||||||||||||||||||||||||||||||||||||
| 390 | 1 | isa_ok $r, 'DBIx::DBO::Row', '$r (using Table object)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 1 | is $r->dbo, $dbo, 'Method DBIx::DBO::Row->dbo'; | |||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 1 | ok $r->is_empty, 'Method DBIx::DBO::Row->is_empty'; | |||||||||||||||||||||||||||||||||||||||||||||
| 395 | 1 | is_deeply [$r->columns], [qw(id name)], 'Method DBIx::DBO::Row->columns'; | |||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 1 | ▶ | ok $r->load(id => [2, 3], name => 'Jane Smith'), 'Method DBIx::DBO::Row->load' or diag sql_err($r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 1 | is_deeply $$r->{array}, [ 2, 'Jane Smith' ], 'Row loaded correctly'; | |||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | # Access methods | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 1 | is $r->[1], 'Jane Smith', 'Access row as an arrayref'; | |||||||||||||||||||||||||||||||||||||||||||||
| 402 | 1 | is $r->{name}, 'Jane Smith', 'Access row as a hashref'; | |||||||||||||||||||||||||||||||||||||||||||||
| 403 | 1 | is $r->value('name'), 'Jane Smith', 'Method DBIx::DBO::Row->value'; | |||||||||||||||||||||||||||||||||||||||||||||
| 404 | 1 | is $r->value($t->column('name')), 'Jane Smith', 'Method DBIx::DBO::Row->value (using Table->column)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 1 | ▶ | is $r->update(name => 'Someone Else'), 1, 'Method DBIx::DBO::Row->update' or diag sql_err($r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 1 | ▶ | is_deeply \@$r, [ 2, 'Someone Else' ], 'Row updated correctly (internal)' or diag Test::DBO::Dump($r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 1 | ▶ | $r->load(id => 2) or diag sql_err($r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 1 | ▶ | is_deeply \@$r, [ 2, 'Someone Else' ], 'Row updated correctly (external)' or diag Test::DBO::Dump($r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | ▶ | $r->update(name => 'Nobody', $t ** 'name' => 'Anybody') or diag sql_err($r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 1 | ▶ | is_deeply \@{$r->load(id => 2)}, [ 2, 'Anybody' ], 'Row update removes duplicates' or diag sql_err($r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # UPDATE the primary key and a complex expression, requiring a reload | ||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 1 | $r->config(OnRowUpdate => 'reload'); | |||||||||||||||||||||||||||||||||||||||||||||
| 416 | 1 | ▶ | $r->update(id => 3, name => \"'Uncle Arnie'") or diag sql_err($r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 1 | ▶ | ok !$r->is_empty, 'Row reloaded on update' or $r->load(id => [2, 3]) or diag sql_err($r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
&ok(!$r->is_empty, "Row reloaded on update") or $r->load("id", [2, 3])
MC/DC0%0/2
&ok(!$r->is_empty, "Row reloaded on update") or $r->load("id", [2, 3])
&ok(!$r->is_empty, "Row reloaded on update")
$r->load("id", [2, 3])
Truth table33%1/3
A or B
A= &ok(!$r->is_empty, "Row reloaded on update")B= $r->load("id", [2, 3])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 1 | ▶ | ok $r->delete, 'Method DBIx::DBO::Row->delete' or diag sql_err($r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | $t->insert(id => 2, name => 'Jane Smith'); | |||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 1 | is $r->load(name => 'non-existent'), undef, 'Load non-existent row'; | |||||||||||||||||||||||||||||||||||||||||||||
| 423 | 1 | is_deeply $$r->{array}, undef, 'Row is empty again'; | |||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||
| 426 | sub query_methods { | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 1 | ▶ | my $dbo = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_methods: called CC=12 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 1 | my $t = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 429 | 1 | my $quoted_table = $t->_from; | |||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # Create a query object | ||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 1 | my $q = $dbo->query($t); | |||||||||||||||||||||||||||||||||||||||||||||
| 433 | 1 | isa_ok $q, 'DBIx::DBO::Query', '$q'; | |||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 1 | is $q->dbo, $dbo, 'Method DBIx::DBO::Query->dbo'; | |||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # Default sql = select everything | ||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 1 | is_deeply [$q->columns], [qw(id name)], 'Method DBIx::DBO::Query->columns'; | |||||||||||||||||||||||||||||||||||||||||||||
| 439 | 1 | my $sql = $q->sql; | |||||||||||||||||||||||||||||||||||||||||||||
| 440 | 1 | is $sql, "SELECT * FROM $quoted_table", 'Method DBIx::DBO::Query->sql'; | |||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # Sort the result | ||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 1 | $q->order_by('id'); | |||||||||||||||||||||||||||||||||||||||||||||
| 444 | 1 | pass 'Method DBIx::DBO::Query->order_by'; | |||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||
| 446 | # Get a valid sth | ||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 1 | ▶ | isa_ok $q->_sth, 'DBI::st', '$q->_sth' or diag "SQL command failed: _sth\n $q->{sql}\n".$q->rdbh->errstr; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||
| 449 | # Get a Row object | ||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 1 | my $r = $q->row; | |||||||||||||||||||||||||||||||||||||||||||||
| 451 | 1 | isa_ok $r, 'DBIx::DBO::Row', '$q->row'; | |||||||||||||||||||||||||||||||||||||||||||||
| 452 | 1 | my $r_str = "$r"; | |||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 1 | $q->config(Testing => 123); | |||||||||||||||||||||||||||||||||||||||||||||
| 455 | 1 | is $r->config('Testing'), 123, 'Row gets config from parent Query'; | |||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||
| 457 | # Alter the SQL to ensure the row is detached and rebuilt | ||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 1 | $q->order_by('id'); | |||||||||||||||||||||||||||||||||||||||||||||
| 459 | 1 | $r = $q->row; | |||||||||||||||||||||||||||||||||||||||||||||
| 460 | 1 | isnt $r_str, "$r", 'Row rebuilds SQL and detaches when a ref still exists'; | |||||||||||||||||||||||||||||||||||||||||||||
| 461 | 1 | $r_str = "$r"; | |||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # Remove the reference so that the row wont detach | ||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 1 | undef $r; | |||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # Fetch the first row | ||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 1 | $r = $q->fetch; | |||||||||||||||||||||||||||||||||||||||||||||
| 468 | 1 | ok $r->isa('DBIx::DBO::Row'), 'Method DBIx::DBO::Query->fetch'; | |||||||||||||||||||||||||||||||||||||||||||||
| 469 | 1 | is $r_str, "$r", 'Re-use the same row object'; | |||||||||||||||||||||||||||||||||||||||||||||
| 470 | 1 | is_deeply [$q->columns], [qw(id name)], 'Method DBIx::DBO::Query->columns (after fetch)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||
| 472 | # Fetch another row | ||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 1 | $r_str = "$r"; | |||||||||||||||||||||||||||||||||||||||||||||
| 474 | 1 | $r = $q->fetch; | |||||||||||||||||||||||||||||||||||||||||||||
| 475 | 1 | isnt $r_str, "$r", 'Row detaches during fetch when a ref still exists'; | |||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||
| 477 | # Re-run the query | ||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 1 | ▶ | $q->run or diag sql_err($q); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 1 | is $q->fetch->{name}, 'John Doe', 'Method DBIx::DBO::Query->run'; | |||||||||||||||||||||||||||||||||||||||||||||
| 480 | 1 | $q->finish; | |||||||||||||||||||||||||||||||||||||||||||||
| 481 | 1 | is $q->fetch->{name}, 'John Doe', 'Method DBIx::DBO::Query->finish'; | |||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||
| 483 | # Count the number of rows | ||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 1 | ▶ | 1 while $q->fetch; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 1 | is $q->rows, 6, 'Row count is 6'; | |||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||
| 487 | # WHERE clause | ||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 1 | ▶ | ok $q->where('name', 'LIKE', \"'%o%'"), 'Method DBIx::DBO::Query->where' or diag sql_err($q); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||
| 490 | # Parentheses | ||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 1 | $q->open_bracket('OR'); | |||||||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | $q->where('name', 'LIKE', \"'%a%'"); | |||||||||||||||||||||||||||||||||||||||||||||
| 493 | 1 | $q->where('id', '!=', \1); | |||||||||||||||||||||||||||||||||||||||||||||
| 494 | 1 | $q->where('id', '=', undef); | |||||||||||||||||||||||||||||||||||||||||||||
| 495 | 1 | $q->open_bracket('AND'); | |||||||||||||||||||||||||||||||||||||||||||||
| 496 | 1 | $q->where('id', '<>', 12345); | |||||||||||||||||||||||||||||||||||||||||||||
| 497 | 1 | $q->where('id', '!=', undef); | |||||||||||||||||||||||||||||||||||||||||||||
| 498 | 1 | $q->where('id', 'NOT IN', [1,22,333]); | |||||||||||||||||||||||||||||||||||||||||||||
| 499 | 1 | $q->where('id', 'NOT BETWEEN', [123,456]); | |||||||||||||||||||||||||||||||||||||||||||||
| 500 | 1 | my $got = $q->col_arrayref({ Columns => [1] }); | |||||||||||||||||||||||||||||||||||||||||||||
| 501 | 1 | ▶ | is_deeply $got, [4,5,6], 'Method DBIx::DBO::Query->open_bracket' or diag sql_err($q); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 1 | $q->where('id', 'NOT IN', 4444); | |||||||||||||||||||||||||||||||||||||||||||||
| 504 | 1 | ok scalar(() = $q->sql =~ / NOT IN /g) == 1, 'Group multiple IN & NOT IN clauses together'; | |||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 1 | $q->order_by; | |||||||||||||||||||||||||||||||||||||||||||||
| 507 | 1 | ▶ | is $q->update(id => { FUNC => '? + 10', COL => 'id' }), 3, 'Method DBIx::DBO::Query->update' or diag sql_err($q); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 1 | $q->order_by('id'); | |||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 1 | my $old_sql = $q->sql; | |||||||||||||||||||||||||||||||||||||||||||||
| 511 | 1 | $q->unwhere('name'); | |||||||||||||||||||||||||||||||||||||||||||||
| 512 | 1 | is $q->sql, $old_sql, 'Method DBIx::DBO::Query->unwhere (before close_bracket)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 1 | $q->close_bracket; | |||||||||||||||||||||||||||||||||||||||||||||
| 515 | 1 | $q->close_bracket; | |||||||||||||||||||||||||||||||||||||||||||||
| 516 | 1 | $q->unwhere('name'); | |||||||||||||||||||||||||||||||||||||||||||||
| 517 | 1 | isnt $q->sql, $old_sql, 'Method DBIx::DBO::Query->close_bracket'; | |||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 1 | $got = $q->col_arrayref({ Columns => [1] }); | |||||||||||||||||||||||||||||||||||||||||||||
| 520 | 1 | is_deeply $got, [2,7,14,15,16], 'Method DBIx::DBO::Query->unwhere'; | |||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||
| 522 | # Reset the Query | ||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 1 | $q->reset; | |||||||||||||||||||||||||||||||||||||||||||||
| 524 | 1 | is $q->sql, $dbo->query($t)->sql, 'Method DBIx::DBO::Query->reset'; | |||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||
| 526 | # Group by the first initial | ||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 1 | $q->show(\'COUNT(*)'); | |||||||||||||||||||||||||||||||||||||||||||||
| 528 | 1 | ▶ | ok(($q->group_by({FUNC => 'SUBSTR(?, 1, 1)', COL => 'name'}), $q->run), | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 'Method DBIx::DBO::Query->group_by') or diag sql_err($q); | ||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||
| 531 | # Update & Load a Row with aliased columns | ||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 1 | $q->show($t, {COL => 'id', AS => 'key'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 533 | 1 | $q->group_by; | |||||||||||||||||||||||||||||||||||||||||||||
| 534 | 1 | is_deeply [$q->columns], [qw(id name key)], 'Method DBIx::DBO::Query->columns (with aliases)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 535 | 1 | $r = $q->fetch; | |||||||||||||||||||||||||||||||||||||||||||||
| 536 | 1 | is_deeply [$q->columns], [qw(id name key)], 'Method DBIx::DBO::Query->columns (after fetch)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 537 | 1 | ▶ | ok $r->update(id => $r->{key}), 'Can update a Row despite using aliases' or diag sql_err($r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 1 | ▶ | ok $r->load(id => 15), 'Can load a Row despite using aliases' or diag sql_err($r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 1 | isa_ok $q ** 'key', 'DBIx::DBO::Column', q{$q ** $alias}; | |||||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||||||
| 542 | # Limit & limit with Offset | ||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 1 | $q->show('id'); | |||||||||||||||||||||||||||||||||||||||||||||
| 544 | 1 | $q->order_by('id'); | |||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 1 | $q->limit(3); | |||||||||||||||||||||||||||||||||||||||||||||
| 547 | 1 | $got = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 548 | 1 | ▶ | for (my $row; $row = $q->fetch; push @$got, $row->[0]) {} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 1 | is_deeply $got, [1,2,7], 'Method DBIx::DBO::Query->limit'; | |||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 1 | $q->limit(3, 2); | |||||||||||||||||||||||||||||||||||||||||||||
| 552 | 1 | $got = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 553 | 1 | ▶ | for (my $row; $row = $q->fetch; push @$got, $row->[0]) {} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 1 | is_deeply $got, [7,14,15], 'Method DBIx::DBO::Query->limit (with offset)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 1 | $q->finish; | |||||||||||||||||||||||||||||||||||||||||||||
| 557 | 1 | return $q; | |||||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||
| 560 | sub advanced_query_methods { | ||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 1 | ▶ | my $dbo = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
advanced_query_methods: called CC=12 SCAR=25.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 1 | my $t = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 563 | 1 | my $q = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 564 | 1 | $q->reset; | |||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||
| 566 | # Show specific columns only | ||||||||||||||||||||||||||||||||||||||||||||||
| 567 | SKIP: { | ||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 1 | ▶ | skip 'COLLATE is not supported', 1 unless $can{collate}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 1 | $q->order_by({ COL => 'name', COLLATE => $can{collate} }); | |||||||||||||||||||||||||||||||||||||||||||||
| 570 | 1 | ▶ | ok $q->run, 'Method DBIx::DBO::Query->order_by COLLATE' or diag sql_err($q); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 1 | $q->order_by('id'); | |||||||||||||||||||||||||||||||||||||||||||||
| 573 | 1 | $q->show({ FUNC => 'UPPER(?)', COL => 'name', AS => 'name' }, 'id', 'name'); | |||||||||||||||||||||||||||||||||||||||||||||
| 574 | 1 | ▶ | ok $q->run && $q->fetch->{name} eq 'JOHN DOE', 'Method DBIx::DBO::Query->show' or diag sql_err($q); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$q->run && $q->fetch->{'name'} eq 'JOHN DOE'
MC/DC0%0/2
$q->run && $q->fetch->{'name'} eq 'JOHN DOE'
$q->run
$q->fetch->{'name'} eq 'JOHN DOE'
Truth table33%1/3
A && B
A= $q->runB= $q->fetch->{'name'} eq 'JOHN DOE'
| |||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 1 | is $q->row->value($t ** 'name'), 'John Doe', 'Access specific column'; | |||||||||||||||||||||||||||||||||||||||||||||
| 577 | 1 | is_deeply [$q->row->columns], [qw(name id name)], 'Method DBIx::DBO::Row->columns (aliased)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 578 | 1 | is_deeply [$q->columns], [qw(name id name)], 'Method DBIx::DBO::Query->columns (aliased)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||
| 580 | # Show whole tables | ||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 1 | $q->show({ FUNC => "'who?'", AS => 'name' }, $t); | |||||||||||||||||||||||||||||||||||||||||||||
| 582 | 1 | is $q->fetch->value($t ** 'name'), 'John Doe', 'Access specific column from a shown table'; | |||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||
| 584 | # Check case sensitivity of LIKE | ||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 1 | ▶ | my $case_sensitive = $dbo->selectrow_arrayref($case_sensitivity_sql, undef, 'a', 'A') or diag sql_err($dbo); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 1 | $case_sensitive = not $case_sensitive->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 587 | 1 | ▶ | note "$dbd_name 'LIKE' is".($case_sensitive ? '' : ' NOT').' case sensitive'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||||||
| 589 | # WHERE clause | ||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 1 | $q->show('id'); | |||||||||||||||||||||||||||||||||||||||||||||
| 591 | 1 | ok $q->where('name', 'LIKE', '%a%'), 'Method DBIx::DBO::Query->where LIKE'; | |||||||||||||||||||||||||||||||||||||||||||||
| 592 | 1 | ▶ | my $a = $q->col_arrayref or diag sql_err($q); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 1 | is_deeply $a, [2,7,14,16], 'Method DBIx::DBO::Query->col_arrayref'; | |||||||||||||||||||||||||||||||||||||||||||||
| 594 | 1 | ok $q->where('id', 'BETWEEN', [6, \16]), 'Method DBIx::DBO::Query->where BETWEEN'; | |||||||||||||||||||||||||||||||||||||||||||||
| 595 | 1 | ▶ | $a = $q->arrayref or diag sql_err($q); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 1 | is_deeply $a, [[7],[14],[16]], 'Method DBIx::DBO::Query->arrayref'; | |||||||||||||||||||||||||||||||||||||||||||||
| 597 | 1 | ok $q->where('name', 'IN', ['Harry Harrelson', 'James Bond']), 'Method DBIx::DBO::Query->where IN'; | |||||||||||||||||||||||||||||||||||||||||||||
| 598 | 1 | ▶ | $a = $q->hashref('id') or diag sql_err($q); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 1 | is_deeply $a, {14 => {id => 14},16 => {id => 16}}, 'Method DBIx::DBO::Query->hashref'; | |||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||
| 601 | # HAVING clause | ||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 1 | ▶ | my $concat = $dbd eq 'SQLite' ? '? || ?' : 'CONCAT(?, ?)'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 1 | my %concat_col = (FUNC => $concat, COL => [qw(id name)]); | |||||||||||||||||||||||||||||||||||||||||||||
| 604 | 1 | ▶ | my $having_col = $dbo->{dbd_class}->_alias_preference($q, 'having') ? 'combo' : \%concat_col; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 1 | $q->show('id', 'name', { %concat_col, AS => 'combo'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 606 | 1 | $q->group_by('id', 'name'); | |||||||||||||||||||||||||||||||||||||||||||||
| 607 | 1 | $q->having($having_col, '=', '14James Bond'); | |||||||||||||||||||||||||||||||||||||||||||||
| 608 | 1 | $q->having($having_col, '=', 'ABC-XYZ'); | |||||||||||||||||||||||||||||||||||||||||||||
| 609 | 1 | $q->having($having_col, '=', 'XYZ-ABC'); | |||||||||||||||||||||||||||||||||||||||||||||
| 610 | 1 | is_deeply [@{$q->fetch}], [14, 'James Bond', '14James Bond'], 'Method DBIx::DBO::Query->having'; | |||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 1 | $q->unhaving($having_col, '=', '14James Bond'); | |||||||||||||||||||||||||||||||||||||||||||||
| 613 | 1 | is $q->fetch, undef, 'Method DBIx::DBO::Query->unhaving'; | |||||||||||||||||||||||||||||||||||||||||||||
| 614 | 1 | $q->unhaving($having_col); | |||||||||||||||||||||||||||||||||||||||||||||
| 615 | 1 | is_deeply [@{$q->fetch}], [14, 'James Bond', '14James Bond'], 'Method DBIx::DBO::Query->unhaving (whole column)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 1 | $q->finish; | |||||||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||||||
| 620 | sub skip_advanced_query_methods { | ||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | ▶ | note "No advanced query tests for $dbd_name"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
skip_advanced_query_methods: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||||||
| 624 | sub join_methods { | ||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 1 | ▶ | my $dbo = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
join_methods: called CC=17 SCAR=31.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 1 | my $table = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 1 | my($q, $t1, $t2) = $dbo->query($table, $table); | |||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||
| 630 | # DISTINCT clause | ||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 1 | $q->order_by('id'); | |||||||||||||||||||||||||||||||||||||||||||||
| 632 | 1 | $q->show('id'); | |||||||||||||||||||||||||||||||||||||||||||||
| 633 | 1 | $q->distinct(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 634 | 1 | is_deeply $q->arrayref, [[1],[2],[7],[14],[15],[16]], 'Method DBIx::DBO::Query->distinct'; | |||||||||||||||||||||||||||||||||||||||||||||
| 635 | 1 | $q->distinct(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 636 | 1 | $q->show($t1, $t2); | |||||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||||||
| 638 | # Counting rows | ||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 1 | $q->limit(3); | |||||||||||||||||||||||||||||||||||||||||||||
| 640 | 1 | $q->config(CalcFoundRows => 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 641 | 1 | ok $q, 'Comma JOIN'; | |||||||||||||||||||||||||||||||||||||||||||||
| 642 | 1 | ▶ | is $q->count_rows, 3, 'Method DBIx::DBO::Query->count_rows' or diag sql_err($q); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 1 | ▶ | is $q->found_rows, 36, 'Method DBIx::DBO::Query->found_rows' or diag sql_err($q); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||
| 645 | # JOIN | ||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 1 | $q->join_on($t2, $t1 ** 'id', '=', { FUNC => '?/7.0', VAL => $t2 ** 'id' }); | |||||||||||||||||||||||||||||||||||||||||||||
| 647 | 1 | $q->order_by({ COL => $t1 ** 'name', ORDER => 'DESC' }); | |||||||||||||||||||||||||||||||||||||||||||||
| 648 | 1 | $q->where($t1 ** 'name', '<', $t2 ** 'name', FORCE => 'OR'); | |||||||||||||||||||||||||||||||||||||||||||||
| 649 | 1 | $q->where($t1 ** 'name', '>', $t2 ** 'name', FORCE => 'OR'); | |||||||||||||||||||||||||||||||||||||||||||||
| 650 | 1 | $q->where($t1 ** 'name', 'LIKE', '%'); | |||||||||||||||||||||||||||||||||||||||||||||
| 651 | 1 | my $r; | |||||||||||||||||||||||||||||||||||||||||||||
| 652 | # Oracle Can't do a SELECT * from a subquery that has "ambiguous" columns (two columns with the same name) | ||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 1 | ▶ | $q->show() if $dbd eq 'Oracle'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 654 | SKIP: { | ||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 1 | ▶ | $q->run or fail 'JOIN ON' or diag sql_err($q) or skip 'No Left Join', 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$q->run or &fail("JOIN ON") or diag(sql_err($q))
$q->run or &fail("JOIN ON")
MC/DC0%0/3
$q->run or &fail("JOIN ON") or diag(sql_err($q))
$q->run
&fail("JOIN ON")
diag(sql_err($q))
Truth table25%1/4
A or B or C
A= $q->runB= &fail("JOIN ON")C= diag(sql_err($q))
| |||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 1 | ▶ | $r = $q->fetch or fail 'JOIN ON' or skip 'No Left Join', 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$r = $q->fetch or &fail("JOIN ON")
MC/DC0%0/2
$r = $q->fetch or &fail("JOIN ON")
$r = $q->fetch
&fail("JOIN ON")
Truth table33%1/3
A or B
A= $r = $q->fetchB= &fail("JOIN ON")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 1 | is_deeply \@$r, [ 1, 'John Doe', 7, 'Amanda Huggenkiss' ], 'JOIN ON'; | |||||||||||||||||||||||||||||||||||||||||||||
| 659 | 1 | ▶ | $r->load($t1 ** id => 2) or diag sql_err($r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 1 | is_deeply \@$r, [ 2, 'Jane Smith', 14, 'James Bond' ], 'Method DBIx::DBO::Row->load'; | |||||||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||||||
| 663 | # LEFT JOIN | ||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 1 | ($q, $t1) = $dbo->query($table); | |||||||||||||||||||||||||||||||||||||||||||||
| 665 | # ... "t1" LEFT JOIN ... "t2" | ||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 1 | $t2 = $q->join_table($table, 'left'); | |||||||||||||||||||||||||||||||||||||||||||||
| 667 | # ... "t1" LEFT JOIN ... "t2" ON "t1"."id" = "t2"."id"/2.0 | ||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 1 | $q->join_on($t2, $t1 ** 'id', '=', { FUNC => '?/2.0', COL => $t2 ** 'id' }); | |||||||||||||||||||||||||||||||||||||||||||||
| 669 | 1 | ok $q->open_join_on_bracket($t2, 'OR'), 'Method DBIx::DBO::Query->open_join_on_bracket'; | |||||||||||||||||||||||||||||||||||||||||||||
| 670 | # ... "t1" LEFT JOIN ... "t2" ON "t1"."id" = "t2"."id"/2.0 AND 1 = 2 | ||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 1 | $q->join_on($t2, \1, '=', \2); | |||||||||||||||||||||||||||||||||||||||||||||
| 672 | # ... "t1" LEFT JOIN ... "t2" ON "t1"."id" = "t2"."id"/2.0 AND (1 = 2 OR 3 = 3) | ||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 1 | $q->join_on($t2, \3, '=', \3); | |||||||||||||||||||||||||||||||||||||||||||||
| 674 | 1 | ok $q->close_join_on_bracket($t2), 'Method DBIx::DBO::Query->close_join_on_bracket'; | |||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 1 | $q->order_by({ COL => $t1 ** 'name', ORDER => 'DESC' }); | |||||||||||||||||||||||||||||||||||||||||||||
| 677 | 1 | $q->limit(1, 3); | |||||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||||||
| 679 | SKIP: { | ||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 1 | ▶ | $q->_sth or diag sql_err($q) or fail 'LEFT JOIN' or skip 'No Left Join', 3; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$q->_sth or diag(sql_err($q)) or &fail("LEFT JOIN")
$q->_sth or diag(sql_err($q))
MC/DC0%0/3
$q->_sth or diag(sql_err($q)) or &fail("LEFT JOIN")
$q->_sth
diag(sql_err($q))
&fail("LEFT JOIN")
Truth table25%1/4
A or B or C
A= $q->_sthB= diag(sql_err($q))C= &fail("LEFT JOIN")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 1 | ▶ | $r = $q->fetch or fail 'LEFT JOIN' or skip 'No Left Join', 3; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$r = $q->fetch or &fail("LEFT JOIN")
MC/DC0%0/2
$r = $q->fetch or &fail("LEFT JOIN")
$r = $q->fetch
&fail("LEFT JOIN")
Truth table33%1/3
A or B
A= $r = $q->fetchB= &fail("LEFT JOIN")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 1 | is_deeply [@$r[0..3]], [14, 'James Bond', undef, undef], 'LEFT JOIN'; | |||||||||||||||||||||||||||||||||||||||||||||
| 684 | 1 | is $r->_column_idx($t2 ** 'id'), 2, 'Method DBIx::DBO::Row->_column_idx'; | |||||||||||||||||||||||||||||||||||||||||||||
| 685 | 1 | is $r->value($t2 ** 'id'), undef, 'Method DBIx::DBO::Row->value'; | |||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||
| 687 | # Update the LEFT JOINed row | ||||||||||||||||||||||||||||||||||||||||||||||
| 688 | SKIP: { | ||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 1 | ▶ | skip "Multi-table UPDATE is not supported by $dbd_name", 1 unless $can{multi_table_update}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | ▶ | ok $r->update($t1 ** 'name' => 'Vernon Wayne Lyon'), 'Method DBIx::DBO::Row->update' or diag sql_err($r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 1 | $q->finish; | |||||||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||||||
| 697 | sub todo_cleanup { | ||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 1 | ▶ | my $sql = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
todo_cleanup: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 1 | unshift @_cleanup_sql, $sql; | |||||||||||||||||||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||||||
| 702 | sub cleanup { | ||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 1 | ▶ | my $dbo = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cleanup: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 1 | note 'Doing cleanup'; | |||||||||||||||||||||||||||||||||||||||||||||
| 706 | 1 | for my $sql (@_cleanup_sql) { | |||||||||||||||||||||||||||||||||||||||||||||
| 707 | 1 | ▶ | $dbo->do($sql) or diag sql_err($dbo); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 1 | $dbo->disconnect; | |||||||||||||||||||||||||||||||||||||||||||||
| 711 | 1 | ▶ | ok !defined $dbo->{dbh} && !defined $dbo->{rdbh}, 'Method DBIx::DBO->disconnect'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $dbo->{'dbh'} || defined $dbo->{'rdbh'}
MC/DC0%0/2
defined $dbo->{'dbh'} || defined $dbo->{'rdbh'}
defined $dbo->{'dbh'}
defined $dbo->{'rdbh'}
Truth table33%1/3
A || B
A= defined $dbo->{'dbh'}B= defined $dbo->{'rdbh'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||||||
| 714 | sub Dump { | ||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | ▶ | my($val, $var) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Dump: not called CC=15 SCAR=54.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | ▶ | if (blessed $val and !defined $var) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($val) and not defined $var
MC/DC0%0/2
builtin::blessed($val) and not defined $var
builtin::blessed($val)
not defined $var
Truth table0%0/3
A and not(B)
A= builtin::blessed($val)B= not defined $var
| |||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | ▶ | if ($val->isa('DBIx::DBO')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | $var = 'dbo'; | |||||||||||||||||||||||||||||||||||||||||||||
| 719 | } elsif ($val->isa('DBIx::DBO::Table')) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | $var = 't'; | |||||||||||||||||||||||||||||||||||||||||||||
| 721 | } elsif ($val->isa('DBIx::DBO::Query')) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | $var = 'q'; | |||||||||||||||||||||||||||||||||||||||||||||
| 723 | } elsif ($val->isa('DBIx::DBO::Row')) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | $var = 'r'; | |||||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | ▶ | $var = 'dump' unless defined $var; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | local $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | local $Data::Dumper::Quotekeys = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | my $d = Data::Dumper->new([$val], [$var]); | |||||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | ▶ | if (ref $val) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | my @_no_recursion = ($val); | |||||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | ▶ | if (reftype $val eq 'ARRAY') { _Find_Seen(\%seen, \@_no_recursion, $_) for @$val } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | elsif (reftype $val eq 'HASH') { _Find_Seen(\%seen, \@_no_recursion, $_) for values %$val } | |||||||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | elsif (reftype $val eq 'REF') { _Find_Seen(\%seen, \@_no_recursion, $$val) } | |||||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | $d->Seen(\%seen); | |||||||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | ▶ | defined wantarray ? return $d->Dump : print $d->Dump; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||||||
| 743 | sub _Find_Seen { | ||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | ▶ | my($seen, $_no_recursion, $val) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_Find_Seen: not called CC=17 SCAR=57.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | ▶ | return unless ref $val; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | for (@$_no_recursion) { | |||||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | ▶ | return if $val == $_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | push @$_no_recursion, $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 0 | ▶ | if (blessed $val) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | ▶ | if ($val->isa('DBIx::DBO')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | $seen->{dbo} = $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 754 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 755 | } elsif ($val->isa('DBIx::DBO::Table')) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | my $t = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | ▶ | while (my($k, $v) = each %$seen) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | ▶ | next if $k !~ /^t\d+$/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | ▶ | return if $val == $v; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | $t++; | |||||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | $seen->{"t$t"} = $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 764 | } elsif ($val->isa('DBIx::DBO::Query')) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | $seen->{q} = $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 767 | } elsif ($val->isa('DBIx::DBO::Row')) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | $seen->{r} = $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | ▶ | if (reftype $val eq 'ARRAY') { _Find_Seen($seen, $_no_recursion, $_) for @$val } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | elsif (reftype $val eq 'HASH') { _Find_Seen($seen, $_no_recursion, $_) for values %$val } | |||||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | elsif (reftype $val eq 'REF') { _Find_Seen($seen, $_no_recursion, $$val) } | |||||||||||||||||||||||||||||||||||||||||||||
| 775 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||||||
| 777 | # When testing via Sponge, use fake tables | ||||||||||||||||||||||||||||||||||||||||||||||
| 778 | package # Hide from PAUSE | ||||||||||||||||||||||||||||||||||||||||||||||
| 779 | DBIx::DBO::DBD::Sponge; | ||||||||||||||||||||||||||||||||||||||||||||||
| 780 | sub _get_table_schema { | ||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 11 | ▶ | return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_table_schema: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 10 | my $fake_table_info = { | |||||||||||||||||||||||||||||||||||||||||||||
| 784 | PrimaryKeys => [], | ||||||||||||||||||||||||||||||||||||||||||||||
| 785 | Columns => [ 'id', 'name', 'age' ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 786 | Column_Idx => { id => 1, name => 2, age => 3 }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 787 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 788 | sub _get_table_info { | ||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 5 | ▶ | my($class, $me, $schema, $table) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_table_info: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 5 | ▶ | return $class->SUPER::_get_table_info($me, $schema, $table) if $table ne $Test::DBO::test_tbl; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 791 | # Fake table info | ||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 4 | ▶ | return $me->{TableInfo}{''}{$table} ||= $fake_table_info; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$me->{"TableInfo"}{""}{$table} ||= $fake_table_info
MC/DC0%0/2
$me->{"TableInfo"}{""}{$table} ||= $fake_table_info
$me->{"TableInfo"}{""}{$table}
$fake_table_info
Truth table33%1/3
A ||= B
A= $me->{"TableInfo"}{""}{$table}B= $fake_table_info
| |||||||||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||||||
| 795 | # When testing via MySponge, fake table contents | ||||||||||||||||||||||||||||||||||||||||||||||
| 796 | package # Hide from PAUSE | ||||||||||||||||||||||||||||||||||||||||||||||
| 797 | MySponge::db; | ||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 10 | @MySponge::ISA = ('DBI'); | |||||||||||||||||||||||||||||||||||||||||||||
| 799 | 10 | @MySponge::db::ISA = ('DBI::db'); | |||||||||||||||||||||||||||||||||||||||||||||
| 800 | 10 | @MySponge::st::ISA = ('DBI::st'); | |||||||||||||||||||||||||||||||||||||||||||||
| 801 | 10 | my @cols; | |||||||||||||||||||||||||||||||||||||||||||||
| 802 | my @rows; | ||||||||||||||||||||||||||||||||||||||||||||||
| 803 | sub setup { | ||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 3 | ▶ | @cols = @{shift()}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 3 | @rows = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 806 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 807 | sub prepare { | ||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 6 | ▶ | my($dbh, $sql, $attr) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 6 | ▶ | $attr ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$attr ||= {}
MC/DC0%0/1
$attr ||= {}
$attr
Truth table50%1/2
A
A= $attr
| |||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 6 | ▶ | $attr->{NAME} ||= \@cols; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$attr->{"NAME"} ||= \@cols
MC/DC0%0/1
$attr->{"NAME"} ||= \@cols
$attr->{"NAME"}
Truth table50%1/2
A
A= $attr->{"NAME"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 6 | ▶ | $attr->{rows} ||= \@rows; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$attr->{"rows"} ||= \@rows
MC/DC0%0/1
$attr->{"rows"} ||= \@rows
$attr->{"rows"}
Truth table50%1/2
A
A= $attr->{"rows"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 6 | $dbh->SUPER::prepare($sql, $attr); | |||||||||||||||||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||||