RE: Possible to get field names and types in a table without executing a query?
- From: brian.barto@xxxxxxxxxxxxxxxxxxx (Brian Barto)
- Date: Tue, 27 Jun 2006 11:03:50 -0400
brian.barto@xxxxxxxxxxxxxxxxxxx wrote:
data types for
Hi all. My goal is to get a list of all field names and
those fields in any given table in a mysql database. Fromreading the
DBI documentation, the only way I've been able to do this is byresults of the
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
query. Also, since my query is "SELECT * FROM $table",which dumps all
data in the table, you may understand my concern for wastedoverhead
when dealing with tables of a significant size.executing a
Is there a way to get table names and data types without
query? If not, is there a query I can use that will... say... onlythe overhead?
return the first row (without WHERE clauses), to minimize
I'm not sure what your objection to WHERE clauses is... You
could do something like SELECT * FROM $table WHERE 0=1.
Tried it and it works just fine. I guess I specified no where clause
because I thought a value of a known field would have to be greater,
lesser, or equal to something and I wouldn't be able to depend on the
value of the fields, let alone even knowing their names. Didn't know you
could do THAT, though.
So what does "WHERE 0=1" actually mean? Just curious. :)
- Brian
.
- Follow-Ups:
- Re: Possible to get field names and types in a table without executing a query?
- From: Alexander Foken
- RE: Possible to get field names and types in a table without executing a query?
- From: Ronald J Kimball
- Re: Possible to get field names and types in a table without executing a query?
- Prev by Date: Re: Possible to get field names and types in a table without executing a query?
- Next by Date: RE: Possible to get field names and types in a table without executing a query?
- 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
|