sub selectAll {
my ($what,$table,@clauses);
my $where = "";
if (@clauses) {
$where = " WHERE " . join(" and ",@clauses);
};
my $statement = "SELECT $what FROM $table $where";
my $sth = $dbh->prepare($statement);
$sth->execute() or die "SQL: selectAll: '$statement' failed.";
return $sth->fetchall_arrayref();
};
####
my $sthGetFile = $dbh->prepare("select VISUAL,LINK from FILES where (ID=?)");
sub getFile {
my ($file) = @_;
$sthGetFile->execute($file);
return $sthGetFile->fetchrow_arrayref();
};
# Assuming $id exists in the table
print getFile($id)->[1];
##
##
my @id = (1,2,3,4,6,7,8);
my $clause = "";
if (@id) {
$clause = "where ID in (" . join(",",@id) . ")";
};
my $statement = "select ID,COLOR from TABLE $clause";
...