Changeset 23399 for main/trunk/greenstone2/perllib/dbutil/sqlite.pm
- Timestamp:
- 2010-12-07T16:55:10+13:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.