Skip Menu |
 

This queue is for tickets about the DBD-SQLite CPAN distribution.

Report information
The Basics
Id: 13631
Status: resolved
Priority: 0/
Queue: DBD-SQLite

People
Owner: Nobody in particular
Requestors: MARKSTOS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.09
Fixed in: (no value)



Subject: wish: column_info support()
Download (untitled) / with headers
text/plain 309b
From looking at the docs and the source, it appears that the column_info() method is not supported. This is a very useful feature for accessing meta data in a database independent way, allowing simpler code in applications like Maypole which generate forms for db tables on the fly. Thanks! Mark Stosberg
From: corion [...] cpan.org
Download (untitled) / with headers
text/plain 2.3k
Hello, I was looking for this feature as well. Dave Rolsky has implemented column_info in Fey::Loader::SQLite (see below code). It can be monkeypatched in respectively dynamically installed with: BEGIN { unless ( defined &DBD::SQLite::db::column_info ) { *DBD::SQLite::db::column_info = \&_sqlite_column_info; } } If I find time (and track down the other DBD::SQLite bug that made me visit the RT queue), I'll submit a nicely packaged patch to Matt. -max sub _sqlite_column_info { my($dbh, $catalog, $schema, $table, $column) = @_; $column = undef if defined $column && $column eq '%'; my $sth_columns = $dbh->prepare( qq{PRAGMA table_info('$table')} ); $sth_columns->execute; my @names = qw( TABLE_CAT TABLE_SCHEM TABLE_NAME COLUMN_NAME DATA_TYPE TYPE_NAME COLUMN_SIZE BUFFER_LENGTH DECIMAL_DIGITS NUM_PREC_RADIX NULLABLE REMARKS COLUMN_DEF SQL_DATA_TYPE SQL_DATETIME_SUB CHAR_OCTET_LENGTH ORDINAL_POSITION IS_NULLABLE ); my @cols; while ( my $col_info = $sth_columns->fetchrow_hashref ) { next if defined $column && $column ne $col_info->{name}; my %col; $col{TABLE_NAME} = $table; $col{COLUMN_NAME} = $col_info->{name}; my $type = $col_info->{type}; if ( $type =~ s/(\w+)\((\d+)(?:,(\d+))?\)/$1/ ) { $col{COLUMN_SIZE} = $2; $col{DECIMAL_DIGITS} = $3; } $col{TYPE_NAME} = $type; $col{COLUMN_DEF} = $col_info->{dflt_value} if defined $col_info->{dflt_value}; if ( $col_info->{notnull} ) { $col{NULLABLE} = 0; $col{IS_NULLABLE} = 'NO'; } else { $col{NULLABLE} = 1; $col{IS_NULLABLE} = 'YES'; } for my $key (@names) { $col{$key} = undef unless exists $col{$key}; } push @cols, \%col; } my $sponge = DBI->connect("DBI:Sponge:", '','') or return $dbh->DBI::set_err($DBI::err, "DBI::Sponge: $DBI::errstr"); my $sth = $sponge->prepare("column_info $table", { rows => [ map { [ @{$_}{@names} ] } @cols ], NUM_OF_FIELDS => scalar @names, NAME => \@names, }) or return $dbh->DBI::set_err($sponge->err(), $sponge->errstr()); return $sth; }
Download (untitled) / with headers
text/plain 448b
On Sun Apr 06 11:53:34 2008, CORION wrote: Show quoted text
> I was looking for this feature as well. Dave Rolsky has implemented > column_info in Fey::Loader::SQLite (see below code). It can be > monkeypatched in respectively dynamically installed with:
There might be some reason I haven't submitted this as a patch, but I can't remember (doh!). It might be incomplete or something. However, even if it is, it's probably a good start for a full implementation.
Confirming resolved


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.