source: LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Onlyaddress.pm @ 565

Last change on this file since 565 was 565, checked in by nanardon, 14 years ago
  • Onlyaddress object detection
  • Property svn:keywords set to Id Rev
File size: 2.2 KB
Line 
1package LATMOS::Accounts::Bases::Sql::Onlyaddress;
2
3use strict;
4use warnings;
5
6use base qw(LATMOS::Accounts::Bases::Sql::Address);
7
8our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0];
9
10sub list {
11    my ($class, $base) = @_;
12
13    my $sth = $base->db->prepare_cached(
14        sprintf(
15            q{select %s as k from %s where ikey not in (select okey from %s where attr = 'isMainAddress') %s order by %s},
16            $base->db->quote_identifier($class->key_field),
17            $base->db->quote_identifier($class->object_table),
18            $base->db->quote_identifier($class->object_table. '_attributes'), # attr
19            ($base->{wexported} ? '' : 'and exported = true'),
20            $base->db->quote_identifier($class->key_field),
21        )
22    );
23    $sth->execute;
24    my @keys;
25    while(my $res = $sth->fetchrow_hashref) {
26        push(@keys, $res->{k});
27    }
28    @keys
29}
30
31sub list_from_rev {
32    my ($class, $base, $rev) = @_;
33
34    my $sth = $base->db->prepare_cached(
35        sprintf(
36            q{select %s as k from %s where ikey not in (select okey from %s
37            where attr = 'isMainAddress') and rev > ? %s order by %s},
38            $base->db->quote_identifier($class->key_field),
39            $base->db->quote_identifier($class->object_table),
40            $base->db->quote_identifier($class->object_table. '_attributes'), # attr
41            ($base->{wexported} ? '' : 'and exported = true'),
42            $base->db->quote_identifier($class->key_field),
43        )
44    );
45    $sth->execute($rev);
46    my @keys;
47    while(my $res = $sth->fetchrow_hashref) {
48        push(@keys, $res->{k});
49    }
50    @keys
51}
52
53sub new {
54    my ($class, $base, $id) = @_;
55    my $sth = $base->db->prepare_cached(
56        sprintf(q{select 1 from %s where %s = ? %s and ikey not in (select okey from %s where attr = 'isMainAddress')},
57            $base->db->quote_identifier($class->object_table),
58            $base->db->quote_identifier($class->key_field),
59            ($base->{wexported} ? '' : 'and exported = true'),
60            $base->db->quote_identifier($class->object_table. '_attributes'),
61        ),
62    );
63    my $count = $sth->execute($id);
64    $sth->finish;
65    $count == 1 or return;
66    $class->SUPER::new($base, $id);
67}
68
691;
Note: See TracBrowser for help on using the repository browser.