[Bps-public-commit] r18936 - DBIx-SearchBuilder/trunk/SearchBuilder/Handle

ruz at bestpractical.com ruz at bestpractical.com
Wed Mar 25 20:09:36 EDT 2009


Author: ruz
Date: Wed Mar 25 20:09:35 2009
New Revision: 18936

Modified:
   DBIx-SearchBuilder/trunk/SearchBuilder/Handle/SQLite.pm
   DBIx-SearchBuilder/trunk/SearchBuilder/Handle/mysql.pm

Log:
* heh, generic method should be portable, but as usually it's not true,
  override for SQLite and mysql

Modified: DBIx-SearchBuilder/trunk/SearchBuilder/Handle/SQLite.pm
==============================================================================
--- DBIx-SearchBuilder/trunk/SearchBuilder/Handle/SQLite.pm	(original)
+++ DBIx-SearchBuilder/trunk/SearchBuilder/Handle/SQLite.pm	Wed Mar 25 20:09:35 2009
@@ -132,6 +132,24 @@
     $$statementref = "SELECT count(*) FROM (SELECT DISTINCT main.id FROM $$statementref )";
 }
 
+sub Fields {
+    my $self  = shift;
+    my $table = shift;
+
+    my $cache = \%DBIx::SearchBuilder::Handle::FIELDS_IN_TABLE;
+    unless ( $cache->{lc $table} ) {
+        my $info = $self->dbh->selectall_arrayref("PRAGMA table_info('$table')")
+            or return ();
+
+        foreach my $e ( @$info ) {
+            push @{ $cache->{ lc $table } ||= [] }, lc $e->[1];
+        }
+    }
+
+    return @{ $cache->{ lc $table } || [] };
+}
+
+
 1;
 
 __END__

Modified: DBIx-SearchBuilder/trunk/SearchBuilder/Handle/mysql.pm
==============================================================================
--- DBIx-SearchBuilder/trunk/SearchBuilder/Handle/mysql.pm	(original)
+++ DBIx-SearchBuilder/trunk/SearchBuilder/Handle/mysql.pm	Wed Mar 25 20:09:35 2009
@@ -121,6 +121,23 @@
     }
 }
 
+sub Fields {
+    my $self  = shift;
+    my $table = shift;
+
+    my $cache = \%DBIx::SearchBuilder::Handle::FIELDS_IN_TABLE;
+    unless ( $cache->{ lc $table } ) {
+        my $sth = $self->dbh->column_info( undef, undef, $table, '%' )
+            or return ();
+        my $info = $sth->fetchall_arrayref({});
+        foreach my $e ( sort {$a->{'ORDINAL_POSITION'} <=> $b->{'ORDINAL_POSITION'}} @$info ) {
+            push @{ $cache->{ lc $e->{'TABLE_NAME'} } ||= [] }, lc $e->{'COLUMN_NAME'};
+        }
+    }
+    return @{ $cache->{ lc $table } || [] };
+}
+
+
 1;
 
 __END__



More information about the Bps-public-commit mailing list