[Bps-public-commit] r18935 - DBIx-SearchBuilder/trunk/SearchBuilder
ruz at bestpractical.com
ruz at bestpractical.com
Wed Mar 25 20:07:43 EDT 2009
Author: ruz
Date: Wed Mar 25 20:07:42 2009
New Revision: 18935
Modified:
DBIx-SearchBuilder/trunk/SearchBuilder/Handle.pm
Log:
* implement generic Fields method in SB::Handle
Modified: DBIx-SearchBuilder/trunk/SearchBuilder/Handle.pm
==============================================================================
--- DBIx-SearchBuilder/trunk/SearchBuilder/Handle.pm (original)
+++ DBIx-SearchBuilder/trunk/SearchBuilder/Handle.pm Wed Mar 25 20:07:42 2009
@@ -9,7 +9,7 @@
use Class::ReturnValue;
use Encode qw();
-use vars qw(@ISA %DBIHandle $PrevHandle $DEBUG %TRANSDEPTH);
+use vars qw(@ISA %DBIHandle $PrevHandle $DEBUG %TRANSDEPTH %FIELDS_IN_TABLE);
=head1 NAME
@@ -132,9 +132,10 @@
my $driver = shift;
my $class = 'DBIx::SearchBuilder::Handle::' . $driver;
+ local $@;
eval "require $class";
return if $@;
-
+
bless $self, $class;
return 1;
}
@@ -331,7 +332,10 @@
my $self=shift;
#If we are setting the database handle, set it.
- $DBIHandle{$self} = $PrevHandle = shift if (@_);
+ if ( @_ ) {
+ $DBIHandle{$self} = $PrevHandle = shift;
+ %FIELDS_IN_TABLE = ();
+ }
return($DBIHandle{$self} ||= $PrevHandle);
}
@@ -1310,6 +1314,22 @@
}
+sub Fields {
+ my $self = shift;
+ my $table = shift;
+
+ unless ( keys %FIELDS_IN_TABLE ) {
+ my $sth = $self->dbh->column_info( undef, '', '%', '%' )
+ or return ();
+ my $info = $sth->fetchall_arrayref({});
+ foreach my $e ( @$info ) {
+ push @{ $FIELDS_IN_TABLE{ lc $e->{'TABLE_NAME'} } ||= [] }, lc $e->{'COLUMN_NAME'};
+ }
+ }
+
+ return @{ $FIELDS_IN_TABLE{ lc $table } || [] };
+}
+
=head2 Log MESSAGE
More information about the Bps-public-commit
mailing list