source: gsdl/trunk/perllib/dbutil.pm@ 15699

Last change on this file since 15699 was 15699, checked in by mdewsnip, 16 years ago

(Adding new DB support) Moving the write_infodb_entry() functions from basebuildproc.pm into a new dbutil.pm file, since we need to use these from basebuilder.pm and classify.pm too.

File size: 1.9 KB
RevLine 
[15699]1###########################################################################
2#
3# dbutil.pm -- utility functions for writing to different databases
4# Copyright (C) 2008 DL Consulting Ltd
5#
6# A component of the Greenstone digital library software
7# from the New Zealand Digital Library Project at the
8# University of Waikato, New Zealand.
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24###########################################################################
25
26package dbutil;
27
28use strict;
29
30
31sub write_infodb_entry
32{
33 my $infodb_handle = shift(@_);
34 my $infodb_key = shift(@_);
35 my $infodb_map = shift(@_);
36
37 &write_infodb_entry_gdbm($infodb_handle, $infodb_key, $infodb_map);
38}
39
40
41sub write_infodb_entry_gdbm
42{
43 my $infodb_handle = shift(@_);
44 my $infodb_key = shift(@_);
45 my $infodb_map = shift(@_);
46
47 print $infodb_handle "[$infodb_key]\n";
48 foreach my $infodb_value_key (keys(%$infodb_map))
49 {
50 foreach my $infodb_value (@{$infodb_map->{$infodb_value_key}})
51 {
52 if ($infodb_value =~ /-{70,}/)
53 {
54 # if value contains 70 or more hyphens in a row we need to escape them
55 # to prevent txt2db from treating them as a separator
56 $infodb_value =~ s/-/&\#045;/gi;
57 }
58 print $infodb_handle "<$infodb_value_key>" . $infodb_value . "\n";
59 }
60 }
61 print $infodb_handle '-' x 70, "\n";
62}
63
64
651;
Note: See TracBrowser for help on using the repository browser.