Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, how do you retrieve Metadata (esp. column names and lengths) with DBIx::Recordset?

Some examples would be greatly appreciated.

Thanks,
Arunbear

Replies are listed 'Best First'.
Re: Metadata with Recordset
by princepawn (Parson) on Oct 10, 2003 at 19:45 UTC
    most that is done via DBIx::Database in the DBIx::Recordset distro... I will dig up an example and get back at ya in a skinny.

    Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality.

      The DBIx::Connect management of database connection is optional --- but hey I like it! :)
      use DBIx::Database; use DBIx::Connect; use Data::Dumper; my %mdb = DBIx::Connect->data_hash('mdb'); $db = DBIx::Database -> new ({'!DataSource' => $mdb{dsn}, '!Username' => $mdb{user}, '!Password' => $mdb{pass}, '!KeepOpen' => 1}) ; my $field = $db -> AllNames ('customer'); #die Dumper($field); print "fields in database order:\n @field"; print join("\n", @$field); @$field = sort @$field; print "\n\n"; print "fields in alphabetical order:\n ", join "\n", @$field;

      Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality.

        How does this method handle the case of the fields? The SQL standard does not specify whether field names are stored in lower, mixed, or upper case and each DBMS has its own choice. (This is how they're stored and returned from a query , not how they're used in SQL which must be case insensitive unless quoted). DBI makes this explicit with (and recommends the use of) $sth->{NAME_lc} and $sth->{NAME_uc} rather than the kind of generic query that Recordset seems to use. Also, presumbably Recordset has equivalents of DBI's table_info() and type_info(), etc. for other kinds of metadata?
Re: Metadata with Recordset
by princepawn (Parson) on Oct 12, 2003 at 02:48 UTC
    I didn't address the final question: it does not appear that Recordset exports any support similar to table_info or type_info... now internally it does make use of column type info when creating your query... that I know. But remember Recordset is a tool to make processing database records straightforward, not for any sort of database manipulation.

    Oh, and I didn't answer the other question about column lengths... I am not sure about that .

    Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality.