4 use FS::Record qw(dbdef);
8 FS::h_Common - History table "mixin" common base class
12 package FS::h_tablename;
13 @ISA = qw( FS::h_Common FS::tablename );
15 sub table { 'h_table_name'; }
17 sub insert { return "can't insert history records manually"; }
18 sub delete { return "can't delete history records"; }
19 sub replace { return "can't modify history records"; }
23 FS::h_Common is intended as a "mixin" base class for history table classes to
30 =item sql_h_search END_TIMESTAMP [ START_TIMESTAMP ]
32 Returns an a list consisting of the "SELECT" and "EXTRA_SQL" SQL fragments to
33 search for the appropriate history records created before END_TIMESTAMP
34 and (optionally) not cancelled before START_TIMESTAMP.
39 my( $self, $end ) = ( shift, shift );
41 my $table = $self->table;
42 my $pkey = dbdef->table($table)->primary_key
43 or die "can't (yet) search history table $table without a primary key";
45 my $notcancelled = '';
46 if ( scalar(@_) && $_[0] ) {
47 $notcancelled = "AND 0 = ( SELECT COUNT(*) FROM $table as notdel
48 WHERE notdel.$pkey = maintable.$pkey
49 AND notdel.history_action = 'delete'
50 AND notdel.history_date > maintable.history_date
51 AND notdel.history_date <= $_[0]
56 "DISTINCT ON ( $pkey ) *",
58 "AND history_date <= $end
59 AND ( history_action = 'insert'
60 OR history_action = 'replace_new'
63 ORDER BY $pkey ASC, history_date DESC",
72 =item sql_h_searchs END_TIMESTAMP [ START_TIMESTAMP ]
74 Like sql_h_search, but limited to the single most recent record (before
81 my($select, $where, $cacheobj, $as) = $self->sql_h_search(@_);
83 ($select, $where, $cacheobj, $as);
92 L<FS::Record>, schema.html from the base documentation