1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # dbutil.pm -- gateway to utilities for reading/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 |
|
---|
26 | package dbutil;
|
---|
27 |
|
---|
28 | use strict;
|
---|
29 |
|
---|
30 |
|
---|
31 | sub open_infodb_write_handle
|
---|
32 | {
|
---|
33 | my $infodb_type = shift(@_);
|
---|
34 | my $infodb_file_path = shift(@_);
|
---|
35 |
|
---|
36 | if ($infodb_type eq "sqlite")
|
---|
37 | {
|
---|
38 | require dbutil::sqlite;
|
---|
39 | return &dbutil::sqlite::open_infodb_write_handle($infodb_file_path, @_);
|
---|
40 | }
|
---|
41 | elsif ($infodb_type eq "gdbm-txtgz")
|
---|
42 | {
|
---|
43 | require dbutil::gdbmtxtgz;
|
---|
44 | return &dbutil::gdbmtxtgz::open_infodb_write_handle($infodb_file_path, @_);
|
---|
45 | }
|
---|
46 | elsif ($infodb_type eq "jdbm")
|
---|
47 | {
|
---|
48 | require dbutil::jdbm;
|
---|
49 | return &dbutil::jdbm::open_infodb_write_handle($infodb_file_path, @_);
|
---|
50 | }
|
---|
51 | elsif ($infodb_type eq "mssql")
|
---|
52 | {
|
---|
53 | require dbutil::mssql;
|
---|
54 | return &dbutil::mssql::open_infodb_write_handle($infodb_file_path, @_);
|
---|
55 | }
|
---|
56 |
|
---|
57 | # Use GDBM if the infodb type is empty or not one of the values above
|
---|
58 | require dbutil::gdbm;
|
---|
59 | return &dbutil::gdbm::open_infodb_write_handle($infodb_file_path, @_);
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 | sub close_infodb_write_handle
|
---|
64 | {
|
---|
65 | my $infodb_type = shift(@_);
|
---|
66 | my $infodb_handle = shift(@_);
|
---|
67 |
|
---|
68 | if ($infodb_type eq "sqlite")
|
---|
69 | {
|
---|
70 | require dbutil::sqlite;
|
---|
71 | return &dbutil::sqlite::close_infodb_write_handle($infodb_handle, @_);
|
---|
72 | }
|
---|
73 | elsif ($infodb_type eq "gdbm-txtgz")
|
---|
74 | {
|
---|
75 | require dbutil::gdbmtxtgz;
|
---|
76 | return &dbutil::gdbmtxtgz::close_infodb_write_handle($infodb_handle, @_);
|
---|
77 | }
|
---|
78 | elsif ($infodb_type eq "jdbm")
|
---|
79 | {
|
---|
80 | require dbutil::jdbm;
|
---|
81 | return &dbutil::jdbm::close_infodb_write_handle($infodb_handle, @_);
|
---|
82 | }
|
---|
83 | elsif ($infodb_type eq "mssql")
|
---|
84 | {
|
---|
85 | require dbutil::mssql;
|
---|
86 | return &dbutil::mssql::close_infodb_write_handle($infodb_handle, @_);
|
---|
87 | }
|
---|
88 |
|
---|
89 | # Use GDBM if the infodb type is empty or not one of the values above
|
---|
90 | require dbutil::gdbm;
|
---|
91 | return &dbutil::gdbm::close_infodb_write_handle($infodb_handle, @_);
|
---|
92 | }
|
---|
93 |
|
---|
94 |
|
---|
95 | sub get_default_infodb_type
|
---|
96 | {
|
---|
97 | # The default is GDBM so everything works the same for existing collections
|
---|
98 | # To use something else, specify the "infodbtype" in the collection's collect.cfg file
|
---|
99 | return "gdbm";
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | sub get_infodb_file_path
|
---|
104 | {
|
---|
105 | my $infodb_type = shift(@_);
|
---|
106 | my $collection_name = shift(@_);
|
---|
107 | my $infodb_directory_path = shift(@_);
|
---|
108 |
|
---|
109 | if ($infodb_type eq "sqlite")
|
---|
110 | {
|
---|
111 | require dbutil::sqlite;
|
---|
112 | return &dbutil::sqlite::get_infodb_file_path($collection_name, $infodb_directory_path, @_);
|
---|
113 | }
|
---|
114 | elsif ($infodb_type eq "gdbm-txtgz")
|
---|
115 | {
|
---|
116 | require dbutil::gdbmtxtgz;
|
---|
117 | return &dbutil::gdbmtxtgz::get_infodb_file_path($collection_name, $infodb_directory_path, @_);
|
---|
118 | }
|
---|
119 | elsif ($infodb_type eq "jdbm")
|
---|
120 | {
|
---|
121 | require dbutil::jdbm;
|
---|
122 | return &dbutil::jdbm::get_infodb_file_path($collection_name, $infodb_directory_path, @_);
|
---|
123 | }
|
---|
124 | elsif ($infodb_type eq "mssql")
|
---|
125 | {
|
---|
126 | #==================================================================================================#
|
---|
127 | # Updated by Jeffrey (2008/08/25 Monday)
|
---|
128 | # After look into the run-time code, it seems we should still create a database file.
|
---|
129 | # Since the run-time code is always try to read a database file, the easiest way here is not
|
---|
130 | # to change the whole structure, but to give whatever the system is looking for.
|
---|
131 | #==================================================================================================#
|
---|
132 | # Added by Jeffrey (2008/08/15 Friday)
|
---|
133 | # No file path required for MS SQL, it is a server-client connection.
|
---|
134 | # At the moment the information is hard coded in dbutil::mssql::open_infodb_write_handle
|
---|
135 | # the this might need some tidy up sometime.
|
---|
136 | #==================================================================================================#
|
---|
137 | require dbutil::mssql;
|
---|
138 | return &dbutil::mssql::get_infodb_file_path($collection_name, $infodb_directory_path, @_);
|
---|
139 | }
|
---|
140 |
|
---|
141 | # Use GDBM if the infodb type is empty or not one of the values above
|
---|
142 | require dbutil::gdbm;
|
---|
143 | return &dbutil::gdbm::get_infodb_file_path($collection_name, $infodb_directory_path, @_);
|
---|
144 | }
|
---|
145 |
|
---|
146 |
|
---|
147 | sub read_infodb_file
|
---|
148 | {
|
---|
149 | my $infodb_type = shift(@_);
|
---|
150 | my $infodb_file_path = shift(@_);
|
---|
151 | my $infodb_map = shift(@_);
|
---|
152 |
|
---|
153 | if ($infodb_type eq "sqlite")
|
---|
154 | {
|
---|
155 | require dbutil::sqlite;
|
---|
156 | return &dbutil::sqlite::read_infodb_file($infodb_file_path, $infodb_map, @_);
|
---|
157 | }
|
---|
158 | elsif ($infodb_type eq "gdbm-txtgz")
|
---|
159 | {
|
---|
160 | require dbutil::gdbmtxtgz;
|
---|
161 | return &dbutil::gdbmtxtgz::read_infodb_file($infodb_file_path, $infodb_map, @_);
|
---|
162 | }
|
---|
163 | elsif ($infodb_type eq "jdbm")
|
---|
164 | {
|
---|
165 | require dbutil::jdbm;
|
---|
166 | return &dbutil::jdbm::read_infodb_file($infodb_file_path, $infodb_map, @_);
|
---|
167 | }
|
---|
168 | elsif ($infodb_type eq "mssql")
|
---|
169 | {
|
---|
170 | require dbutil::mssql;
|
---|
171 | return &dbutil::mssql::read_infodb_file($infodb_file_path, $infodb_map, @_);
|
---|
172 | }
|
---|
173 |
|
---|
174 | # Use GDBM if the infodb type is empty or not one of the values above
|
---|
175 | require dbutil::gdbm;
|
---|
176 | return &dbutil::gdbm::read_infodb_file($infodb_file_path, $infodb_map, @_);
|
---|
177 | }
|
---|
178 |
|
---|
179 |
|
---|
180 | sub write_infodb_entry
|
---|
181 | {
|
---|
182 | my $infodb_type = shift(@_);
|
---|
183 | my $infodb_handle = shift(@_);
|
---|
184 | my $infodb_key = shift(@_);
|
---|
185 | my $infodb_map = shift(@_);
|
---|
186 |
|
---|
187 | if ($infodb_type eq "sqlite")
|
---|
188 | {
|
---|
189 | require dbutil::sqlite;
|
---|
190 | return &dbutil::sqlite::write_infodb_entry($infodb_handle, $infodb_key, $infodb_map, @_);
|
---|
191 | }
|
---|
192 | elsif ($infodb_type eq "gdbm-txtgz")
|
---|
193 | {
|
---|
194 | require dbutil::gdbmtxtgz;
|
---|
195 | return &dbutil::gdbmtxtgz::write_infodb_entry($infodb_handle, $infodb_key, $infodb_map, @_);
|
---|
196 | }
|
---|
197 | elsif ($infodb_type eq "jdbm")
|
---|
198 | {
|
---|
199 | require dbutil::jdbm;
|
---|
200 | return &dbutil::jdbm::write_infodb_entry($infodb_handle, $infodb_key, $infodb_map, @_);
|
---|
201 | }
|
---|
202 | elsif ($infodb_type eq "mssql")
|
---|
203 | {
|
---|
204 | require dbutil::mssql;
|
---|
205 | return &dbutil::mssql::write_infodb_entry($infodb_handle, $infodb_key, $infodb_map, @_);
|
---|
206 | }
|
---|
207 |
|
---|
208 | # Use GDBM if the infodb type is empty or not one of the values above
|
---|
209 | require dbutil::gdbm;
|
---|
210 | return &dbutil::gdbm::write_infodb_entry($infodb_handle, $infodb_key, $infodb_map, @_);
|
---|
211 | }
|
---|
212 |
|
---|
213 |
|
---|
214 | sub delete_infodb_entry
|
---|
215 | {
|
---|
216 | my $infodb_type = shift(@_);
|
---|
217 | my $infodb_handle = shift(@_);
|
---|
218 | my $infodb_key = shift(@_);
|
---|
219 |
|
---|
220 | if ($infodb_type eq "sqlite")
|
---|
221 | {
|
---|
222 | require dbutil::sqlite;
|
---|
223 | return &dbutil::sqlite::delete_infodb_entry($infodb_handle, $infodb_key, @_);
|
---|
224 | }
|
---|
225 | elsif ($infodb_type eq "gdbm-txtgz")
|
---|
226 | {
|
---|
227 | require dbutil::gdbmtxtgz;
|
---|
228 | return &dbutil::gdbmtxtgz::delete_infodb_entry($infodb_handle, $infodb_key, @_);
|
---|
229 | }
|
---|
230 | elsif ($infodb_type eq "jdbm")
|
---|
231 | {
|
---|
232 | require dbutil::jdbm;
|
---|
233 | return &dbutil::jdbm::delete_infodb_entry($infodb_handle, $infodb_key, @_);
|
---|
234 | }
|
---|
235 | elsif ($infodb_type eq "mssql")
|
---|
236 | {
|
---|
237 | require dbutil::mssql;
|
---|
238 | return &dbutil::mssql::delete_infodb_entry($infodb_handle, $infodb_key, @_);
|
---|
239 | }
|
---|
240 |
|
---|
241 | # Use GDBM if the infodb type is empty or not one of the values above
|
---|
242 | require dbutil::gdbm;
|
---|
243 | return &dbutil::gdbm::delete_infodb_entry($infodb_handle, $infodb_key, @_);
|
---|
244 | }
|
---|
245 |
|
---|
246 |
|
---|
247 | 1;
|
---|