Changeset 23399 for main/trunk
- Timestamp:
- 2010-12-07T16:55:10+13:00 (13 years ago)
- Location:
- main/trunk/greenstone2/perllib
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/dbutil.pm
r22485 r23399 221 221 my $infodb_key = shift(@_); 222 222 223 224 if ($infodb_type eq "sqlite") 225 { 226 require dbutil::sqlite; 227 return &dbutil::sqlite::read_infodb_entry($infodb_file_path, $infodb_key, @_); 228 } 229 # elsif ($infodb_type eq "gdbm-txtgz") 230 # { 231 # require dbutil::gdbmtxtgz; 232 # return &dbutil::gdbmtxtgz::read_infodb_entry($infodb_file_path, $infodb_key, @_); 233 # } 234 # elsif ($infodb_type eq "jdbm") 235 # { 236 # require dbutil::jdbm; 237 # return &dbutil::jdbm::read_infodb_entry($infodb_file_path, $infodb_key, @_); 238 # } 239 # elsif ($infodb_type eq "mssql") 240 # { 241 # require dbutil::mssql; 242 # return &dbutil::mssql::read_infodb_entry($infodb_file_path, $infodb_key, @_); 243 # } 244 245 # # Use GDBM if the infodb type is empty or not one of the values above 246 # require dbutil::gdbm; 247 # return &dbutil::gdbm::read_infodb_entry($infodb_file_path, $infodb_key, @_); 248 249 250 223 251 # !! TEMPORARY: Slow and naive implementation that just reads the entire file and picks out the one value 224 252 # !! This will soon be replaced with database-specific versions that will use dbget etc. … … 294 322 require dbutil::gdbm; 295 323 return &dbutil::gdbm::write_infodb_rawentry($infodb_handle, $infodb_key, $infodb_val, @_); 324 } 325 326 327 sub set_infodb_entry 328 { 329 my $infodb_type = shift(@_); 330 my $infodb_file_path = shift(@_); 331 my $infodb_key = shift(@_); 332 my $infodb_map = shift(@_); 333 334 if ($infodb_type eq "sqlite") 335 { 336 require dbutil::sqlite; 337 return &dbutil::sqlite::set_infodb_entry($infodb_file_path, $infodb_key, $infodb_map, @_); 338 } 339 elsif ($infodb_type eq "gdbm-txtgz") 340 { 341 require dbutil::gdbmtxtgz; 342 return &dbutil::gdbmtxtgz::set_infodb_entry($infodb_file_path, $infodb_key, $infodb_map, @_); 343 } 344 elsif ($infodb_type eq "jdbm") 345 { 346 require dbutil::jdbm; 347 return &dbutil::jdbm::set_infodb_entry($infodb_file_path, $infodb_key, $infodb_map, @_); 348 } 349 elsif ($infodb_type eq "mssql") 350 { 351 require dbutil::mssql; 352 return &dbutil::mssql::set_infodb_entry($infodb_file_path, $infodb_key, $infodb_map, @_); 353 } 354 355 # Use GDBM if the infodb type is empty or not one of the values above 356 require dbutil::gdbm; 357 return &dbutil::gdbm::set_infodb_entry($infodb_file_path, $infodb_key, $infodb_map, @_); 296 358 } 297 359 -
main/trunk/greenstone2/perllib/dbutil/gdbm.pm
r23102 r23399 158 158 159 159 160 sub set_infodb_entry 161 { 162 my $infodb_file_path = shift(@_); 163 my $infodb_key = shift(@_); 164 my $infodb_map = shift(@_); 165 166 # Protect metadtaa values that go inside quotes for gdbmset 167 foreach my $k (keys %$infodb_map) { 168 my @escaped_v = (); 169 foreach my $v (@{$infodb_map->{$k}}) { 170 if ($k eq "contains") { 171 # protect quotes in ".2;".3 etc 172 $v =~ s/\"/\\\"/g; 173 push(@escaped_v, $v); 174 } 175 else { 176 my $ev = &ghtml::unescape_html($v); 177 $ev =~ s/\"/\\\"/g; 178 push(@escaped_v, $ev); 179 } 180 } 181 $infodb_map->{$k} = \@escaped_v; 182 } 183 184 # Generate the record string 185 my $serialized_infodb_map = &dbutil::convert_infodb_hash_to_string($infodb_map); 186 ## print STDERR "**** ser dr\n$serialized_infodb_map\n\n\n"; 187 188 # Store it into GDBM 189 my $cmd = "gdbmset \"$infodb_file_path\" \"$infodb_key\" \"$serialized_infodb_map\""; 190 my $status = system($cmd); 191 192 return $status; 193 194 } 195 196 160 197 sub delete_infodb_entry 161 198 { -
main/trunk/greenstone2/perllib/dbutil/gdbmtxtgz.pm
r23169 r23399 184 184 } 185 185 186 sub set_infodb_entry 187 { 188 my $infodb_file_path = shift(@_); 189 my $infodb_key = shift(@_); 190 my $infodb_map = shift(@_); 191 192 print STDERR "***** gdbmtxtgz::set_infodb_entry() not implemented yet!\n"; 193 } 194 186 195 187 196 -
main/trunk/greenstone2/perllib/dbutil/jdbm.pm
r23166 r23399 199 199 200 200 201 sub set_infodb_entry 202 { 203 my $infodb_file_path = shift(@_); 204 my $infodb_key = shift(@_); 205 my $infodb_map = shift(@_); 206 207 print STDERR "***** jdbm::set_infodb_entry() not implemented yet!\n"; 208 } 209 210 201 211 sub delete_infodb_entry 202 212 { -
main/trunk/greenstone2/perllib/dbutil/mssql.pm
r22485 r23399 222 222 } 223 223 224 225 sub set_infodb_entry 226 { 227 my $infodb_file_path = shift(@_); 228 my $infodb_key = shift(@_); 229 my $infodb_map = shift(@_); 230 231 print STDERR "***** mssql::set_infodb_entry() not implemented yet!\n"; 232 } 233 224 234 sub delete_infodb_entry 225 235 { -
main/trunk/greenstone2/perllib/dbutil/sqlite.pm
r23166 r23399 37 37 { 38 38 my $infodb_file_path = shift(@_); 39 39 my $opt_append = shift(@_); 40 40 41 my $sqlite3_exe = &util::filename_cat($ENV{'GSDLHOME'},"bin",$ENV{'GSDLOS'}, "sqlite3" . &util::get_os_exe()); 41 42 my $infodb_handle = undef; … … 56 57 binmode($infodb_handle,":utf8"); 57 58 59 if (!(defined $opt_append) || ($opt_append ne "append")) { 60 print $infodb_handle "DROP TABLE IF EXISTS data;\n"; 61 print $infodb_handle "DROP TABLE IF EXISTS document_metadata;\n"; 62 } 63 58 64 print $infodb_handle "CREATE TABLE IF NOT EXISTS data (key TEXT PRIMARY KEY, value TEXT);\n"; 59 65 print $infodb_handle "CREATE TABLE IF NOT EXISTS document_metadata (id INTEGER PRIMARY KEY, docOID TEXT, element TEXT, value TEXT);\n"; … … 161 167 $infodb_map->{$key} = 1; 162 168 } 169 } 170 171 sub read_infodb_rawentry 172 { 173 my $infodb_file_path = shift(@_); 174 my $infodb_key = shift(@_); 175 176 177 my $key_safe = &sqlite_safe($infodb_key); 178 my $select_val_cmd = "SELECT value FROM data WHERE key='$key_safe';"; 179 180 my $val_str = read_infodb_cmd($infodb_file_path,$select_val_cmd); 181 182 return $val_str 183 } 184 185 sub read_infodb_entry 186 { 187 my $infodb_file_path = shift(@_); 188 my $infodb_key = shift(@_); 189 190 my $val_str = read_infodb_rawentry($infodb_file_path,$infodb_key); 191 192 my $rec_hash = &dbutil::convert_infodb_string_to_hash($val_str); 193 194 return $rec_hash; 163 195 } 164 196 … … 216 248 } 217 249 218 219 220 250 sub write_infodb_rawentry 221 251 { … … 227 257 print $infodb_handle "INSERT OR REPLACE INTO data (key, value) VALUES ('" . $safe_infodb_key . "', '" . &sqlite_safe($infodb_val) . "');\n"; 228 258 } 259 260 261 sub set_infodb_entry 262 { 263 my $infodb_file_path = shift(@_); 264 my $infodb_key = shift(@_); 265 my $infodb_map = shift(@_); 266 267 my $sqlite3_exe = &util::filename_cat($ENV{'GSDLHOME'},"bin",$ENV{'GSDLOS'}, "sqlite3" . &util::get_os_exe()); 268 my $infodb_handle = undef; 269 my $cmd = "\"$sqlite3_exe\" \"$infodb_file_path\""; 270 271 if (!-e "$sqlite3_exe" || !open($infodb_handle, "|$cmd")) 272 { 273 print STDERR "Unable to execute: $cmd\n"; 274 print STDERR "$!\n"; 275 return -1; 276 } 277 else { 278 279 binmode($infodb_handle, ":utf8"); 280 write_infodb_entry($infodb_handle,$infodb_key,$infodb_map); 281 close($infodb_handle); 282 } 283 284 # Not currently checking for errors on write to DB 285 return 0; 286 287 288 } 289 229 290 230 291
Note:
See TracChangeset
for help on using the changeset viewer.