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 $pkey = dbdef->table($table)->primary_key
44 or die "can't (yet) search history table $table without a primary key";
47 confess 'Called sql_h_search without END_TIMESTAMP';
50 my $notcancelled = '';
51 if ( scalar(@_) && $_[0] ) {
52 $notcancelled = "AND 0 = ( SELECT COUNT(*) FROM $table as notdel
53 WHERE notdel.$pkey = maintable.$pkey
54 AND notdel.history_action = 'delete'
55 AND notdel.history_date > maintable.history_date
56 AND notdel.history_date <= $_[0]
61 "DISTINCT ON ( $pkey ) *",
63 "AND history_date <= $end
64 AND ( history_action = 'insert'
65 OR history_action = 'replace_new'
68 ORDER BY $pkey ASC, history_date DESC",
77 =item sql_h_searchs END_TIMESTAMP [ START_TIMESTAMP ]
79 Like sql_h_search, but limited to the single most recent record (before
86 my($select, $where, $cacheobj, $as) = $self->sql_h_search(@_);
88 ($select, $where, $cacheobj, $as);
97 L<FS::Record>, schema.html from the base documentation