- Timestamp:
- 2008-05-27T14:17:24+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/dbutil.pm
r15717 r15722 151 151 152 152 153 154 # ---------------------------------------------------------------------------------------- 155 # SQLITE FUNCTIONS 156 # ---------------------------------------------------------------------------------------- 157 158 sub get_infodb_file_path_sqlite 159 { 160 my $collection_name = shift(@_); 161 my $infodb_directory_path = shift(@_); 162 163 my $infodb_file_extension = ".db"; 164 my $infodb_file_name = &util::get_dirsep_tail($collection_name) . $infodb_file_extension; 165 return &util::filename_cat($infodb_directory_path, $infodb_file_name); 166 } 167 168 169 sub open_infodb_write_handle_sqlite 170 { 171 my $infodb_file_path = shift(@_); 172 173 my $sqlite3_exe = &util::filename_cat("$ENV{'GSDLHOME'}/bin/$ENV{'GSDLOS'}", "sqlite3" . &util::get_os_exe()); 174 my $infodb_file_handle = undef; 175 if (!-e "$sqlite3_exe" || !open($infodb_file_handle, "| $sqlite3_exe \"$infodb_file_path\"")) 176 { 177 return undef; 178 } 179 180 print $infodb_file_handle "CREATE TABLE data (key TEXT, value TEXT, PRIMARY KEY(key));\n"; 181 182 return $infodb_file_handle; 183 } 184 185 186 sub write_infodb_entry_sqlite 187 { 188 my $infodb_handle = shift(@_); 189 my $infodb_key = shift(@_); 190 my $infodb_map = shift(@_); 191 192 my $infodb_entry_value = ""; 193 foreach my $infodb_value_key (keys(%$infodb_map)) 194 { 195 foreach my $infodb_value (@{$infodb_map->{$infodb_value_key}}) 196 { 197 $infodb_entry_value .= "<$infodb_value_key>" . $infodb_value . "\n"; 198 } 199 } 200 201 # Escape any single quotes in the value 202 $infodb_entry_value =~ s/\'/\'\'/g; 203 204 print $infodb_handle "DELETE FROM data WHERE key='" . $infodb_key . "';\n"; 205 print $infodb_handle "INSERT INTO data (key, value) VALUES ('" . $infodb_key . "', '" . $infodb_entry_value . "');\n"; 206 } 207 208 153 209 1;
Note:
See TracChangeset
for help on using the changeset viewer.