line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
253755
|
use 5.008003; |
|
2
|
|
|
|
|
16
|
|
2
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
42
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
110
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
7
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Class::Tiny qw( dbh ); |
10
|
2
|
|
|
2
|
|
1031
|
use Scalar::Util (); |
|
2
|
|
|
|
|
3729
|
|
|
2
|
|
|
|
|
24
|
|
11
|
2
|
|
|
2
|
|
447
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
633
|
|
12
|
|
|
|
|
|
|
my ( $self ) = ( shift ); |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
0
|
442
|
if ( @_ == 1 and Scalar::Util::blessed( $_[0] ) ) { |
15
|
|
|
|
|
|
|
return { dbh => $_[0] }; |
16
|
2
|
50
|
33
|
|
|
15
|
} |
17
|
0
|
|
|
|
|
0
|
else { |
18
|
|
|
|
|
|
|
require DBI; |
19
|
|
|
|
|
|
|
return { dbh => 'DBI'->connect( @_ ) }; |
20
|
2
|
|
|
|
|
3262
|
} |
21
|
2
|
|
|
|
|
35932
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my ( $self ) = ( shift ); |
24
|
|
|
|
|
|
|
my %args; |
25
|
|
|
|
|
|
|
if ( @_ == 1 and ref($_[0]) eq 'HASH' ) { |
26
|
8
|
|
|
8
|
0
|
36901
|
%args = %{ $_[0] }; |
27
|
8
|
|
|
|
|
16
|
} |
28
|
8
|
50
|
33
|
|
|
66
|
elsif ( @_ % 2 == 1 ) { |
|
|
50
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
%args = ( name => @_ ); |
|
0
|
|
|
|
|
0
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else { |
32
|
8
|
|
|
|
|
25
|
%args = @_; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
require LINQ::Database::Table; |
36
|
|
|
|
|
|
|
'LINQ::Database::Table'->new( { database => $self, %args } ); |
37
|
|
|
|
|
|
|
} |
38
|
8
|
|
|
|
|
1012
|
|
39
|
8
|
|
|
|
|
53
|
my ( $self, $sql ) = ( shift, @_ ); |
40
|
|
|
|
|
|
|
$self->{last_sql} = $sql; |
41
|
|
|
|
|
|
|
$self->dbh->prepare( $sql ); |
42
|
|
|
|
|
|
|
} |
43
|
7
|
|
|
7
|
0
|
165
|
|
44
|
7
|
|
|
|
|
16
|
my ( $self ) = ( shift ); |
45
|
7
|
|
|
|
|
109
|
$self->dbh->quote( @_ ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my ( $self ) = ( shift ); |
49
|
2
|
|
|
2
|
0
|
11
|
$self->dbh->quote_identifier( @_ ); |
50
|
2
|
|
|
|
|
30
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
9
|
|
|
9
|
0
|
1887
|
|
55
|
9
|
|
|
|
|
135
|
=pod |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=encoding utf-8 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 NAME |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
LINQ::Database - LINQ extension for working with databases |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 SYNOPSIS |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
use LINQ; |
66
|
|
|
|
|
|
|
use LINQ::Util -all; |
67
|
|
|
|
|
|
|
use LINQ::Database; |
68
|
|
|
|
|
|
|
use DBI; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $db = 'LINQ::Database'->new( 'DBI'->connect( ... ) ); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$db |
73
|
|
|
|
|
|
|
->table( 'pet' ) |
74
|
|
|
|
|
|
|
->where( check_fields 'name', -like => 'P%', -nocase ) |
75
|
|
|
|
|
|
|
->select( fields 'name', 'species' ) |
76
|
|
|
|
|
|
|
->foreach( sub { |
77
|
|
|
|
|
|
|
printf( "%s is a %s\n", $_->name, $_->species ); |
78
|
|
|
|
|
|
|
} ); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Or: |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
use LINQ::DSL ':default_safe'; |
83
|
|
|
|
|
|
|
use LINQ::Database; |
84
|
|
|
|
|
|
|
use DBI; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $db = 'LINQ::Database'->new( 'DBI'->connect( ... ) ); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $collection = Linq { |
89
|
|
|
|
|
|
|
From $db->table( 'pet' ); |
90
|
|
|
|
|
|
|
WhereX 'name', -like => 'P%', -nocase; |
91
|
|
|
|
|
|
|
SelectX 'name', 'species'; |
92
|
|
|
|
|
|
|
}; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
printf "Found %d results.\n", $collection->count; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
$collection->foreach( sub { |
97
|
|
|
|
|
|
|
printf( "%s is a %s\n", $_->name, $_->species ); |
98
|
|
|
|
|
|
|
} ); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 DESCRIPTION |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
L<LINQ::Database> provides a L<LINQ::Collection>-compatible interface for |
103
|
|
|
|
|
|
|
accessing SQL databases. It's basically B<< DLinq for Perl >>. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 BUGS |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Please report any bugs to |
108
|
|
|
|
|
|
|
L<http://rt.cpan.org/Dist/Display.html?Queue=LINQ-Database>. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 SEE ALSO |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
L<LINQ>. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHOR |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Toby Inkster E<lt>tobyink@cpan.orgE<gt>. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This software is copyright (c) 2021-2022 by Toby Inkster. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
123
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTIES |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
128
|
|
|
|
|
|
|
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
129
|
|
|
|
|
|
|
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
130
|
|
|
|
|
|
|
|