package DB_functions;

use strict;
use DBI;

sub get_max_id {
    my ($dbh,$table,$col,$where_clause) = @_;
    my ($last_id, $sth, @row);

    if ($where_clause) {
    	$sth = $dbh->prepare("SELECT MAX($col) FROM $table $where_clause");
    } else {
    	$sth = $dbh->prepare("SELECT MAX($col) FROM $table");
    }
    if (!$sth->execute()) {
        return -1;
    }
    @row=$sth->fetchrow_array;
    $sth->finish;
    $last_id=pop @row;
    warn "lastid=",$last_id,"\n";
    $last_id++;
    return $last_id?$last_id:1;
}

1;
