1 # Copyright 2002-2007 Interchange Development Group and others
2 # Copyright 1996-2002 Red Hat, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version. See the LICENSE file for details.
9 # $Id: next_sequential.filter,v 1.6 2007-03-30 23:40:45 pajamian Exp $
11 CodeDef next_sequential Filter
12 CodeDef next_sequential Description Next sequential
13 CodeDef next_sequential Visibility private
14 CodeDef next_sequential Routine <<EOR
16 my ($value, $field, $table, $col, $qualifier) = @_;
17 #::logDebug("called next_sequential filter value='$value' table=$table col=$col qual=$qualifier");
18 return $value if length($value);
19 $table ||= $CGI::values{mv_data_table};
25 return exists $CGI::values{$field}
26 ? ($CGI::values{$field})
27 : ($::Values->{$field});
33 my $db = database_exists_ref($table)
34 or die errmsg("next_sequential filter: no table '%s'", $table);
35 my $tname = $db->name();
36 my $q = "SELECT $col FROM $tname";
38 my $qval = $CGI::values{$qualifier};
39 $qval = $db->quote($qval, $qualifier);
40 $q .= " WHERE $qualifier = $qval";
42 $q .= " ORDER BY $col desc";
43 #::logDebug("constructed query $q for next_sequential");
44 my $ary = $db->query($q)
45 or die errmsg("next_sequential filter query failed: %s", $q);
46 return 1 unless @$ary;