Bundle-PBib
view release on metacpan or search on metacpan
lib/Biblio/Database.pm view on Meta::CPAN
join(', ', values %bibFields));
$sql = "INSERT INTO $biblio ($fields) VALUES ($values)";
}
print "$sql\n" if( $debug_sql );
$self->do($sql) or
croak "\nDB access failed:\n\n$DBI::errstr\n\n$sql\n";
}
#
#
# shortcuts
#
#
sub replaceShortcuts {
# look in $text and replace all shortcuts
my ($self, $text) = @_;
return undef unless defined($text);
# check, if there is any {} field at all -> this is *much* faster!
return $text unless $text =~ /\{/;
my $shortcuts = $self->shortcuts();
my $pattern = join("|", map( /:$/ ? "$_.*" : $_, (keys(%{$shortcuts}))));
#print $pattern;
$text =~ s/\{($pattern)\}/ $self->expandShortcut($shortcuts, $1) /ge;
return $text;
}
sub expandShortcut {
my ($self, $shortcuts, $text) = @_;
my @pars = split(/:/, $text);
my $k = shift @pars; if( @pars ) { $k = "$k:"; }
my $v = $shortcuts->{$k};
$v =~ s/%(\d)/ $pars[$1-1] /ge;
#print "\n\n$k ---- $v\n\n";
return $v;
}
sub shortcuts_table {
my ($self) = @_;
return $self->{'shortcuts_table'};
}
sub shortcuts {
my ($self) = @_;
return $self->{'shortcuts'} if defined($self->{'shortcuts'});
my $shortcuts_table = $self->shortcuts_table();
return $self->{'shortcuts'} = {} unless $shortcuts_table;
my $sql = "SELECT * FROM $shortcuts_table";
print "$sql\n" if( $debug_sql );
my $result = $self->query($sql);
unless( $result ) {
print STDERR "$DBI::errstr\nSelect failed for $sql\n";
return {};
}
#use Data::Dumper;
# print Dumper $self;
my %scs = map(($_->[0] => $_->[1]), @{$result});
return $self->{'shortcuts'} = \%scs;
}
sub updateShortcuts {
my ($self) = @_;
delete $self->{'shortcuts'};
}
1;
#
# $Log: Database.pm,v $
# Revision 1.17 2003/06/16 09:07:41 tandler
# - support for 'mysql' dbms
# - DB design can now be configured (columns in DB)
# - field to DB column mapping can now be configured
# - the CiteType column in DB can be a text or numeric format,
# numeric format is automatically converted
# - field "BibDate" is always updated in storePaper() call
#
# Revision 1.16 2003/05/22 11:49:53 tandler
# some fixes. Custom2 is now CrossRef
#
# Revision 1.15 2003/05/19 13:03:35 tandler
# disable AutoComit, we commit explicitely.
#
# Revision 1.14 2003/04/16 15:03:23 tandler
# suppress empty fields (needed for DBD::CSV)
# the name of the shortcuts table can now be configured (no shortcuts are used, if set to empty of undef).
#
# Revision 1.13 2003/04/15 17:35:58 tandler
# some support for DBD::CSV
# - more flexibility to configure dbname, quoting of fields etc.
# --> still need improvement ...
#
# Revision 1.12 2003/04/15 13:48:34 tandler
# fixed prototypes
#
# Revision 1.11 2003/04/14 09:43:41 ptandler
# field mapping updated
#
# Revision 1.10 2003/01/27 21:10:20 ptandler
# use CiteKey as StarOffice's "Identifier" field
#
# Revision 1.9 2003/01/14 11:06:52 ptandler
# new config
#
# Revision 1.8 2002/11/05 18:27:52 peter
# PBibNote handling fix
#
# Revision 1.7 2002/11/03 22:12:06 peter
# PBibNote handling
#
# Revision 1.6 2002/09/11 10:43:44 peter
# BP::readpbib
#
# Revision 1.5 2002/08/22 10:38:04 peter
# - Field name fix
# - citeType fix (report instead of techreport, techreport is now an alias)
# - use alias fields for import of records
#
# Revision 1.4 2002/06/06 07:26:59 Diss
# renamed PaperID -> CiteKey (new canonical fields due to bp)
#
( run in 0.895 second using v1.01-cache-2.11-cpan-39bf76dae61 )