1 | package LATMOS::Accounts::Bases::Sql::Onlyaddress; |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | |
---|
6 | use base qw(LATMOS::Accounts::Bases::Sql::Address); |
---|
7 | |
---|
8 | our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; |
---|
9 | |
---|
10 | sub 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 | |
---|
31 | sub 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 | |
---|
53 | sub 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 | |
---|
69 | 1; |
---|