For more information... RTFM!
NAVIGATION
ACCOUNT LOGIN

You are not logged in

Powered by Interchange version 5.7.0

next_sequential

Look up a numeric value, from a named column in a named table, and return the value plus 1.

Note

Note

If the filter's body text has a true value (not blank and not zero), then that value will be returned verbatim.

Warning

Warning

This filter does not save the new sequence number back to the table.

Example

[value name="foo" set="bar" hide=1]

[filter next_sequential.mytable.mycol.foo][/filter]

Generates and executes SQL like the following:

SELECT  mycol
FROM    mytable
WHERE   foo = 'bar'

The filter's return value will be whatever "mycol" contained, plus 1.

Source code

sub {
    my ($value, $field, $table, $col, $qualifier) = @_;

    return $value if length($value);
    $table ||= $CGI::values{mv_data_table};

    my $val;

    if(! $table) {
        return 1 if ! $field;
        return exists $CGI::values{$field}
            ? ($CGI::values{$field})
            : ($::Values->{$field});
    }

    $col ||= $field;

    eval {
        my $db = database_exists_ref($table)
            or die errmsg("next_sequential filter: no table '%s'", $table);
        my $tname = $db->name();

        my $q = "SELECT $col FROM $tname";
        if($qualifier) {
            my $qval = $CGI::values{$qualifier};
            $qval = $db->quote($qval, $qualifier);
            $q .= " WHERE $qualifier = $qval";
        }

        $q .= " ORDER BY $col desc";
        my $ary = $db->query($q)
        or die errmsg("next_sequential filter query failed: %s", $q);

        return 1 unless @$ary;
        $val = $ary->[0][0];
        $val++;
    };

    if($@) {
        logError($@);
        return undef;
    }
    return $val;
}

Category:  Filters
Last modified by: Kevin Walsh
Modification date: Thursday 1 March 2007 at 4:15 PM (EST)
Home  |  Legal nonsense  |  Privacy policy  |  Contact us