4 use FS::Record qw(dbdef);
9 FS::h_Common - History table "mixin" common base class
13 package FS::h_tablename;
14 @ISA = qw( FS::h_Common FS::tablename );
16 sub table { 'h_table_name'; }
18 sub insert { return "can't insert history records manually"; }
19 sub delete { return "can't delete history records"; }
20 sub replace { return "can't modify history records"; }
24 FS::h_Common is intended as a "mixin" base class for history table classes to
31 =item sql_h_search END_TIMESTAMP [ START_TIMESTAMP ]
33 Returns an a list consisting of the "SELECT" and "EXTRA_SQL" SQL fragments to
34 search for the appropriate history records created before END_TIMESTAMP
35 and (optionally) not cancelled before START_TIMESTAMP.
40 my( $self, $end ) = ( shift, shift );
42 my $table = $self->table;
43 my $real_table = ($table =~ /^h_(.*)$/) ? $1 : $table;
44 my $pkey = dbdef->table($real_table)->primary_key
45 or die "can't (yet) search history table $real_table without a primary key";
48 confess 'Called sql_h_search without END_TIMESTAMP';
51 my $notcancelled = '';
52 if ( scalar(@_) && $_[0] ) {
53 $notcancelled = "AND 0 = ( SELECT COUNT(*) FROM $table as notdel
54 WHERE notdel.$pkey = maintable.$pkey
55 AND notdel.history_action = 'delete'
56 AND notdel.history_date > maintable.history_date
57 AND notdel.history_date <= $_[0]
62 "DISTINCT ON ( $pkey ) *",
64 "AND history_date <= $end
65 AND ( history_action = 'insert'
66 OR history_action = 'replace_new'
69 ORDER BY $pkey ASC, history_date DESC",
78 =item sql_h_searchs END_TIMESTAMP [ START_TIMESTAMP ]
80 Like sql_h_search, but limited to the single most recent record (before
87 my($select, $where, $cacheobj, $as) = $self->sql_h_search(@_);
89 ($select, $where, $cacheobj, $as);
98 L<FS::Record>, schema.html from the base documentation