| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Class::DBI::ViewLoader::Pg; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
84793
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
78
|
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
96
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Class::DBI::ViewLoader::Pg - Class::DBI::Viewloader implementation for Postgresql. |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Class::DBI::ViewLoader; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$loader = Class::DBI::ViewLoader dsn => 'dbi:Pg:dbname=mydb'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# load views from mydb |
|
19
|
|
|
|
|
|
|
@classes = $loader->load_views |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This is the postgresql driver for L, |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 METHODS |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
|
28
|
|
|
|
|
|
|
|
|
29
|
2
|
|
|
2
|
|
880
|
use Class::DBI::Pg; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use base qw( Class::DBI::ViewLoader ); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 base_class |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Returns 'Class::DBI::Pg'. This class will be used as the main base class for all |
|
36
|
|
|
|
|
|
|
classes generated using this driver. |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub base_class { 'Class::DBI::Pg' }; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 get_views |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
@views = $obj->get_views |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Returns a list of the names of the views in the current database. |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub get_views { |
|
51
|
|
|
|
|
|
|
my $self = shift; |
|
52
|
|
|
|
|
|
|
my $dbh = $self->_get_dbi_handle; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
return $dbh->tables( |
|
55
|
|
|
|
|
|
|
undef, # catalog |
|
56
|
|
|
|
|
|
|
"public", # schema |
|
57
|
|
|
|
|
|
|
"", # name |
|
58
|
|
|
|
|
|
|
"view", # type |
|
59
|
|
|
|
|
|
|
{ noprefix => 1, pg_noprefix => 1 } |
|
60
|
|
|
|
|
|
|
); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 get_view_cols |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
@cols = $obj->get_view_cols($view) |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Returns the columns contained in the given view. |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub get_view_cols { |
|
72
|
|
|
|
|
|
|
my($self, $view) = @_; |
|
73
|
|
|
|
|
|
|
my $sth = $self->_get_cols_sth; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$sth->execute($view); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my @columns = map {$_->[0]} @{$sth->fetchall_arrayref}; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$sth->finish; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
return grep { !/^\.+pg\.dropped\.\d+\.+$/ } @columns; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# SQL to get columns cribbed from Class::DBI::Pg->set_up_table |
|
85
|
|
|
|
|
|
|
my $col_sql = <
|
|
86
|
|
|
|
|
|
|
SELECT a.attname |
|
87
|
|
|
|
|
|
|
FROM pg_catalog.pg_class c |
|
88
|
|
|
|
|
|
|
JOIN pg_catalog.pg_attribute a on a.attrelid = c.oid |
|
89
|
|
|
|
|
|
|
WHERE c.relname = ? |
|
90
|
|
|
|
|
|
|
AND a.attnum > 0 |
|
91
|
|
|
|
|
|
|
ORDER BY a.attnum |
|
92
|
|
|
|
|
|
|
END_SQL |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# cache the statement handle |
|
95
|
|
|
|
|
|
|
sub _get_cols_sth { |
|
96
|
|
|
|
|
|
|
my $self = shift; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
if (defined $self->{__col_sth}) { |
|
99
|
|
|
|
|
|
|
return $self->{__col_sth}; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
else { |
|
102
|
|
|
|
|
|
|
my $dbh = $self->_get_dbi_handle; |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
return $self->{__col_sth} = $dbh->prepare($col_sql); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# make sure the cache is cleared when the dbi handle is cleaned up |
|
109
|
|
|
|
|
|
|
sub _clear_dbi_handle { |
|
110
|
|
|
|
|
|
|
my $self = shift; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Should be no need to explicitly finish this.. |
|
113
|
|
|
|
|
|
|
delete $self->{__col_sth}; |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$self->SUPER::_clear_dbi_handle(@_); |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |