Re: Possible to get field names and types in a table without executing a query?
- From: psionic@xxxxxxxxx (Jordan Sissel)
- Date: Tue, 27 Jun 2006 12:49:51 -0700
On 6/27/06, brian.barto@xxxxxxxxxxxxxxxxxxx <brian.barto@xxxxxxxxxxxxxxxxxxx>
wrote:
Hi all. My goal is to get a list of all field names and data types for
those fields in any given table in a mysql database. From reading the
DBI documentation, the only way I've been able to do this is by
preparing and executing a query against a table first. Then I would use
$sth->{NAME} and $sth->{TYPE} to get the field names and their
respective data types. it looks like this:
$sth = $dbh->prepare("SELECT * FROM $table") or die "Can't prepare
statement!\n";
$sth->execute or die "Can not execute statement!\n";
@types = @{$sth->{TYPE}};
@cols = @{$sth->{NAME}};
This seams like wasted overhead since I don't use the results of the
query. Also, since my query is "SELECT * FROM $table", which dumps all
data in the table, you may understand my concern for wasted overhead
when dealing with tables of a significant size.
Is there a way to get table names and data types without executing a
query? If not, is there a query I can use that will... say... only
return the first row (without WHERE clauses), to minimize the overhead?
Thanks,
Brian
iirc, you can use $dbh->table_info() or tables() or type_info() functions to
pull that information without having to do a hack where you select 0 rows
just to poll for column names.
Right?
-Jordan
- Follow-Ups:
- Re: Possible to get field names and types in a table without executing a query?
- From: Matthew Persico
- Re: Possible to get field names and types in a table without executing a query?
- References:
- Prev by Date: Re: Possible to get field names and types in a table without executing a query?
- Next by Date: Re: In search of ParamValues in error handler after a do call fails
- Previous by thread: Re: Possible to get field names and types in a table without executing a query?
- Next by thread: Re: Possible to get field names and types in a table without executing a query?
- Index(es):
Relevant Pages
|