Vance M. Allen wrote:
Sorry if the cross-posting wasn't appropriate, but I need help with this and
am not sure if it's more appropriate to post under CGI or DBI since it
involves both...I want to be sure that I can get help from the best source.
My question is probably a simple answer, but I am not sure what I have to do
and the books I have here are either not answering the question, or I'm not
finding the answer.
I need to know how to retrieve through Perl DBI a listing of possible ENUM
elements from a field for processing under a CGI script. If all I need for
this is some form of SELECT statement, please provide a code snippet of this
so I can do it.
I want to make my code so I'm not having to edit hard-coded Perl CGI scripts
if/when I add new elements to the ENUM field. Any help you can provide
would be greatly appreciated.
Thanks!
Vance
I did this exact same thing at some point in the past.. I should be able to dig
it up.. half a moment...
ahh here it is (I think). Let me know if this doesn't work for you. SET and ENUM
should be similar enough in this regard
# obtain values of SET columns live, rather than hard-code them into the script
# existing dbhandle object (not a further reference to one), table, and col name
sub get_column_values ($$$) {
my ($dbh1, $table, $column, @vals) = @_;
my $sth = $dbh1->column_info( undef, undef, $table, '%');
$sth->execute() or safe_error($dbh1->errstr); # errorsub defined elsewhere
while ( my $ref = $sth->fetchrow_hashref() )
{
#skip unless this is the column we want info for
next unless $ref->{COLUMN_NAME} eq $column;
@vals = @{$ref->{mysql_values}}; #save the column data
last; #there can be only one
}
$sth->finish();
return undef unless @vals;
# return either the data or a count of how much data
return wantarray ? @vals : scalar(@vals);
}
Also, Tim, you have my permission to fuse this or a cleaned up version of it
into the DBI docs somewhere if you feel it might be useful therein.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>