Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Re: (Ovid) Re(3): How do you get Perl::DBI to do a desc table_name?

by rob_au (Abbot)
on Mar 27, 2002 at 22:43 UTC ( [id://154840]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: (Ovid) Re(3): How do you get Perl::DBI to do a desc table_name?
in thread How do you get Perl::DBI to do a desc table_name?

You're right, this is fairly system dependent - However, basic database metadata can be determined through the metadata attributes of DBI, specifically the NAME, TYPE, PRECISION and NULLABLE field attributes. The standard values for common SQL data field types returned by the TYPE attribute are as follows:

SQL_CHAR 1 SQL_NUMERIC 2 SQL_DECIMAL 3 SQL_INTEGER 4 SQL_SMALLINT 5 SQL_FLOAT 6 SQL_REAL 7 SQL_DOUBLE 8 SQL_DATE 9 SQL_TIME 10 SQL_TIMESTAMP 11 SQL_VARCHAR 12 SQL_LONGVARCHAR -1 SQL_BINARY -2 SQL_VARBINARY -3 SQL_LONGVARBINARY -4 SQL_BIGINT -5 SQL_TINYINT -6 SQL_BIT -7 SQL_WCHAR -8 SQL_WVARCHAR -9 SQL_WLONGVARCHAR -10

This information can be retrieved from a DBI database handle similar that shown in one of my first SOPW questions to the monastery back here.

While these attributes allow information about the most standard of SQL field types to be determined, there may be some non-standard field types returned by databases with extended field types. From my own experience I find its usually better for just this reason to gleam an understanding of the database structure directly and incorporate this understanding into my code, rather than trying to have the code determine this information by itself.

 

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://154840]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-03-28 14:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found