Patches for DBD::CSV to use the tied f_meta access

Jens Rehsack <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.sybase.devel
Message-ID <[email protected]>
Hi Merijn,

attached the patch to allow DBD::CSV work fine with the
$dbh->{csv_tables} attribute.
It's for use with DBD::File rev. 14128. Maybe it's a good idea to set
some values into
$dbh->{csv_valid_attrs} and $dbh->{csv_readonly_attrs}, too - but you
know it better
than me.

Best regards,
Jens
DBD-CSV-csv_tables.patch (application/octet-stream, 3.4 KB)
diff --git a/lib/DBD/CSV.pm b/lib/DBD/CSV.pm
index b1fe6f7..d8c2ca0 100755
--- a/lib/DBD/CSV.pm
+++ b/lib/DBD/CSV.pm
@@ -105,20 +105,17 @@ sub set_versions
     return $this->SUPER::set_versions ();
     } # set_versions
 
-sub STORE
+sub init_valid_attributes
 {
-    my ($self, @attr) = @_;
-    @attr && $attr[0] eq "csv_tables" and $attr[0] = "f_meta";
-    $self->SUPER::STORE (@attr);
-    } # STORE
+    my $dbh = shift;
 
-sub FETCH
-{
-    my ($self, @attr) = @_;
-    use DP;
-    @attr && $attr[0] eq "csv_tables" and $attr[0] = "f_meta";
-    $self->SUPER::FETCH (@attr);
-    } # FETCH
+    # $dbh->{csv_valid_attrs} = {};
+    # $dbh->{csv_readonly_attrs} = {};
+
+    $dbh->{csv_meta} = "csv_tables";
+
+    return $dbh->SUPER::init_valid_attributes();
+    } # init_valid_attributes
 
 # --- STATEMENT ----------------------------------------------------------------
 
@@ -267,15 +264,15 @@ use Carp;
 
 @DBD::CSV::Table::ISA = qw(DBD::File::Table);
 
-sub bootstrap_table_meta
-{
-    my ($self, $dbh, $meta, $table) = @_;
-
-    my $fqfn;
-    exists $dbh->{f_meta}{$table} && ($fqfn = $dbh->{f_meta}{$table}{file}) and
-	$meta->{f_fqfn} = $fqfn;
-    $self->SUPER::bootstrap_table_meta ($dbh, $meta, $table);
-    } # bootstrap_table_meta
+#sub bootstrap_table_meta
+#{
+#    my ($self, $dbh, $meta, $table) = @_;
+#
+#    my $fqfn;
+#    exists $dbh->{f_meta}{$table} && ($fqfn = $dbh->{f_meta}{$table}{file}) and
+#	$meta->{f_fqfn} = $fqfn;
+#    $self->SUPER::bootstrap_table_meta ($dbh, $meta, $table);
+#    } # bootstrap_table_meta
 
 sub init_table_meta
 {
@@ -291,7 +288,7 @@ sub init_table_meta
 	foreach my $key (grep m/^csv_/ => keys %$dbh) {
 	    (my $attr = $key) =~ s/csv_//;
 	    $attr =~ m{^(?: eol | sep | quote | escape	# Handled below
-			  | tables | sql_parser_object	# Not for Text::CSV_XS
+			  | tables | meta		# Not for Text::CSV_XS
 			  | sponge_driver | version	# internal
 			  )$}x and next;
 	    $opts{$attr} = $dbh->{$key};
@@ -299,8 +296,8 @@ sub init_table_meta
 	delete $opts{null} and
 	    $opts{blank_is_undef} = $opts{always_quote} = 1;
 
-	my $class = $meta->{class} || $dbh->{csv_class} || "Text::CSV_XS";
-	my $eol   = $meta->{eol}   || $dbh->{csv_eol}   || "\r\n";
+	my $class = $meta->{csv_class} || $dbh->{csv_class} || "Text::CSV_XS";
+	my $eol   = $meta->{csv_eol}   || $dbh->{csv_eol}   || "\r\n";
 	$eol =~ m/^\A(?:[\r\n]|\r\n)\Z/ or $opts{eol} = $eol;
 	for ([ "sep",    ',' ],
 	     [ "quote",  '"' ],
@@ -322,6 +319,28 @@ sub init_table_meta
 	$meta->{csv_skip_first_row} = $dbh->{csv_skip_first_row};
     } # init_table_meta
 
+my %compat_map = (
+    file  => "f_file",
+    class => "csv_class",
+    eof   => "csv_eof",
+);
+
+sub get_table_meta_attr
+{
+    my ($class, $meta, $attrib) = @_;
+    defined $compat_map{$attrib} and
+        return $class->SUPER::get_table_meta_attr ($meta, $compat_map{$attrib});
+    return $class->SUPER::get_table_meta_attr ($meta, $attrib);
+    } # get_table_meta_attr
+
+sub set_table_meta_attr
+{
+    my ($class, $meta, $attrib, $value) = @_;
+    defined $compat_map{$attrib} and
+        return $class->SUPER::set_table_meta_attr ($meta, $compat_map{$attrib}, $value);
+    return $class->SUPER::set_table_meta_attr ($meta, $attrib, $value);
+    } # set_table_meta_attr
+
 $DBD::File::VERSION > 0.38 and *open_file = sub {
     my ($self, $meta, $attrs, $flags) = @_;
     $self->SUPER::open_file ($meta, $attrs, $flags);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.