package Textbook::Record;

require Exporter;
@ISA       = qw(Exporter);
# Symbols to be exported by default
#@EXPORT    = qw(
#    opl_
#);
# Symbols to be exported on request
@EXPORT_OK = qw(
    tbkrec_rectify
);
# Version number
$VERSION   = 0.01;      

use strict;

sub tbkrec_rectify {
    my ($marc) = @_;

    # Remove subfields with empty codes
    foreach my $f ($marc->fields()) {
        if ($f->is_control_field()) {
            next;
        }

        foreach my $sf ($f->subfields()) {
            my $sfc = $sf->[0];
            if ($sfc =~ m/[\W]/) {
                $f->delete_subfield(code => "$sfc");
            }
        }

        if (scalar($f->subfields()) == 0) {
            $marc->delete_field($f);
        }
    }

    return $marc;
}
############################################################


sub tbkrec_importRecordSth {
    my ($dbh) = @_;

    my @col = qw(title title_sort callNumMin callNumMax author pubPlace pubName
        pubDate ISBN xml);

    my $sql = 'insert into tbk_marcRecord set ';
    foreach my $c (@col) {
        $sql .= "$c = ?, ";
    }
    $sql =~ s/, $//;

    my $sth = $dbh->prepare($sql);

    return ($sth, \@col);
}
############################################################


sub tbkrec_recordData {
    my ($marc, $col) = @_;

    # Fri, Jul 25, 2008 @ 16:33:51 EDT
    #Note: Should I create a map between SQL column name and field/sub-field?
    # OR
    # Simply extract data column by column.
    my @data;

    return @data;
}
############################################################


sub tbkrec_importRecord {
    my ($marc, $sth, $col) = @_;
}

=item
############################################################


sub tbkrec_ {
    my () = @_;
}
=cut


1;
