Changeset 17087 for gsdl/trunk/perllib/GDBMUtils.pm
- Timestamp:
- 2008-08-29T13:10:39+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/GDBMUtils.pm
r15890 r17087 6 6 my $debug = 0; 7 7 8 # /** Global variable to hold a string containing the last collection a gdbmGet 9 # * was performed on. 8 # /** Global variables to hold a strings containing: 9 # * the last collection, oid and value 10 # * a gdbmCachedCollectionGet() was performed on. 10 11 # */ 11 12 my $gdbmget_previous_collection = ""; 12 # /** Global variable to hold a string containing the last oid a gdbmGet was13 # * performed on.14 # */15 13 my $gdbmget_previous_oid = ""; 16 # /** Global variable to hold a string containing the resulting value of the17 # * last gdbmGet request.18 # */19 14 my $gdbmget_previous_value = ""; 15 16 17 18 sub gdbmDatabaseGet 19 { 20 my ($database, $oid) = @_; 21 22 # Are we in windows? Do we need .exe? 23 my $exe = &util::get_os_exe(); 24 25 # Retrieve the raw document content 26 print STDERR "#Get document\ncmd: gdbmget$exe \"$database\" \"$oid\"\n" if $debug; 27 my $value = `gdbmget$exe "$database" "$oid"`; 28 29 # Done 30 return $value; 31 } 32 33 sub gdbmDatabaseAppend 34 { 35 my ($database, $oid, $value) = @_; 36 37 # Are we in windows? Do we need .exe? 38 my $exe = &util::get_os_exe(); 39 40 # Escape any speech marks in the value 41 $value =~ s/\"/\\\"/g; 42 # Set the document content 43 print STDERR "#Set document\ncmd: gdbmset$exe \"$database\" \"$oid\" \"$value\" append\n" if $debug; 44 `gdbmset$exe "$database" "$oid" "$value" append`; 45 } 46 47 48 sub gdbmDatabaseSet 49 { 50 my ($database, $oid, $value) = @_; 51 52 # Are we in windows? Do we need .exe? 53 my $exe = &util::get_os_exe(); 54 55 # Escape any speech marks in the value 56 $value =~ s/\"/\\\"/g; 57 # Set the document content 58 print STDERR "#Set document\ncmd: gdbmset$exe \"$database\" \"$oid\" \"$value\"\n" if $debug; 59 `gdbmset$exe "$database" "$oid" "$value"`; 60 } 61 62 63 sub gdbmDatabaseRemove 64 { 65 my ($database, $oid) = @_; 66 67 # Are we in windows? Do we need .exe? 68 my $exe = &util::get_os_exe(); 69 70 # Remove the document from the database 71 print STDERR "#Set document\ncmd: gdbmset$exe \"$database\" \"$oid\"\n" if $debug; 72 73 # Think it would be clearer if this funcctionality was done 74 # by a separate executable, e.g. gdbmremove 75 `gdbmset$exe "$database" "$oid"`; 76 } 77 78 20 79 21 80 # /** This wraps John T's gdbmget executable to get the gdbm database entry for … … 29 88 # * @author John Thompson, DL Consulting Ltd. 30 89 # */ 31 sub gdbm Get()90 sub gdbmCachedCollectionGet 32 91 { 33 92 my ($collection, $oid) = @_; … … 42 101 return $gdbmget_previous_value; 43 102 } 103 44 104 # Where's the database? 45 my $database = &getDatabasePath($collection); 46 # Are we in windows? Do we need .exe? 47 my $exe = ""; 48 $exe = ".exe" if $ENV{'GSDLOS'} =~ /^windows$/i; 49 # Retrieve the raw document content 50 print STDERR "#Get document\ncmd: gdbmget$exe \"$database\" \"$oid\"\n" if $debug; 51 my $value = `gdbmget$exe "$database" "$oid"`; 105 my $database = _getDatabasePath($collection); 106 107 my $value = gdbmDatbaseGet($database,$oid); 108 52 109 # Tidy up the ever growing number of newlines at the end of the value 53 110 $value =~ s/(\r?\n)+/$1/g; 111 # Why do we need the above line? At the very least it would seem 112 # better that the data going in to the database through 'set' is 113 # monitored for superfluous \r\n which are then removed before being 114 # saved in GDBM 115 54 116 # Cache this result 55 117 $gdbmget_previous_collection = $collection; 56 118 $gdbmget_previous_oid = $oid; 57 119 $gdbmget_previous_value = $value; 120 58 121 # Done 59 122 return $value; 60 123 } 61 # /** gdbm Get()**/124 # /** gdbmCachedCollectionGet **/ 62 125 63 126 # /** This wraps John T's gdbmset executable to set the gdbm database entry for … … 70 133 # * @author John Rowe, DL Consulting Ltd. 71 134 # */ 72 sub gdbm Set()135 sub gdbmCachedCollectionSet 73 136 { 74 137 my ($collection, $oid, $value) = @_; 138 75 139 # Where's the database? 76 my $database = &getDatabasePath($collection);77 # Are we in windows? Do we need .exe? 78 my $exe = &util::get_os_exe(); 140 my $database = _getDatabasePath($collection); 141 142 79 143 # Check whether value is set 80 144 if (defined($value)) 81 145 { 82 # Escape any speech marks in the value 83 $value =~ s/\"/\\\"/g; 84 # Set the document content 85 print STDERR "#Set document\ncmd: gdbmset$exe \"$database\" \"$oid\" \"$value\"\n" if $debug; 86 `gdbmset$exe "$database" "$oid" "$value"`; 146 gdbmDatabaseSet($database,$oid,$value); 87 147 } 88 148 else 89 149 { 90 # Remove the document from the database 91 print STDERR "#Set document\ncmd: gdbmset$exe \"$database\" \"$oid\"\n" if $debug; 92 `gdbmset$exe "$database" "$oid"`; 150 gdbmDtabaseRemove($database,$oid); 93 151 } 152 94 153 # Empty any cached values, as they may now be invalid 154 95 155 # Cache this result 96 156 $gdbmget_previous_collection = ""; … … 98 158 $gdbmget_previous_value = 0; 99 159 } 100 # /** gdbm Set()**/160 # /** gdbmCollectionSet **/ 101 161 102 162 # /** This works out the database path and returns it to the calling … … 107 167 # * @author John Rowe, DL Consulting Ltd. 108 168 # */ 109 sub getDatabasePath() 169 170 sub _getDatabasePath 110 171 { 111 172 my $collection = shift(@_); 173 112 174 # Find out the database extension 113 my $ext = ".bdb";114 $ext = ".ldb" if &util::is_little_endian(); 175 my $ext = &util::is_little_endian() ? ".ldb" : ".bdb"; 176 115 177 # Now return the full filename of the database 178 116 179 return &util::filename_cat($ENV{'GSDLHOME'}, "collect", $collection, "index", "text", $collection.$ext); 117 180 } 118 # /** getDatabasePath ()**/181 # /** getDatabasePath **/ 119 182 120 183 1;
Note:
See TracChangeset
for help on using the changeset viewer.