Changeset 21856


Ignore:
Timestamp:
2010-03-31T23:08:43+13:00 (11 years ago)
Author:
davidb
Message:

read_infodb_entry() implemented for sqlite. new write_infodb_rawentry() added for main dbutil.dm class

Location:
main/trunk/greenstone2/perllib
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/dbutil.pm

    r21550 r21856  
    226226
    227227
     228sub write_infodb_rawentry
     229{
     230  my $infodb_type = shift(@_);
     231  my $infodb_handle = shift(@_);
     232  my $infodb_key = shift(@_);
     233  my $infodb_val = shift(@_);
     234
     235  if ($infodb_type eq "sqlite")
     236  {
     237    require dbutil::sqlite;
     238    return &dbutil::sqlite::write_infodb_rawentry($infodb_handle, $infodb_key, $infodb_val, @_);
     239  }
     240  elsif ($infodb_type eq "gdbm-txtgz")
     241  {
     242    require dbutil::gdbmtxtgz;
     243    return &dbutil::gdbmtxtgz::write_infodb_rawentry($infodb_handle, $infodb_key, $infodb_val, @_);
     244  }
     245  elsif ($infodb_type eq "jdbm")
     246  {
     247    require dbutil::jdbm;
     248    return &dbutil::jdbm::write_infodb_rawentry($infodb_handle, $infodb_key, $infodb_val, @_);
     249  }
     250  elsif ($infodb_type eq "mssql")
     251  {
     252    require dbutil::mssql;
     253    return &dbutil::mssql::write_infodb_rawentry($infodb_handle, $infodb_key, $infodb_val, @_);
     254  }
     255
     256  # Use GDBM if the infodb type is empty or not one of the values above
     257  require dbutil::gdbm;
     258  return &dbutil::gdbm::write_infodb_rawentry($infodb_handle, $infodb_key, $infodb_val, @_);
     259}
     260
     261
     262
    228263sub delete_infodb_entry
    229264{
  • main/trunk/greenstone2/perllib/dbutil/gdbm.pm

    r21545 r21856  
    132132}
    133133
     134sub write_infodb_rawentry
     135{
     136  # With infodb_handle already set up, works the same as _gdbm_txtgz version
     137  &dbutil::gdbmtxtgz::write_infodb_rawentry(@_);
     138}
     139
     140
    134141sub delete_infodb_entry
    135142{
  • main/trunk/greenstone2/perllib/dbutil/gdbmtxtgz.pm

    r21411 r21856  
    138138
    139139
     140   
     141sub write_infodb_rawentry
     142{
     143
     144  my $infodb_handle = shift(@_);
     145  my $infodb_key = shift(@_);
     146  my $infodb_val = shift(@_);
     147 
     148  print $infodb_handle "[$infodb_key]\n";
     149  print $infodb_handle "$infodb_val\n";
     150  print $infodb_handle '-' x 70, "\n";
     151}
     152
     153
     154
    140155sub delete_infodb_entry
    141156{
  • main/trunk/greenstone2/perllib/dbutil/jdbm.pm

    r21411 r21856  
    181181
    182182
     183sub write_infodb_rawentry
     184{
     185
     186  my $infodb_handle = shift(@_);
     187  my $infodb_key = shift(@_);
     188  my $infodb_val = shift(@_);
     189 
     190  print $infodb_handle "[$infodb_key]\n";
     191  print $infodb_handle "$infodb_val\n";
     192  print $infodb_handle '-' x 70, "\n";
     193}
     194
     195
    183196sub delete_infodb_entry
    184197{
  • main/trunk/greenstone2/perllib/dbutil/mssql.pm

    r21411 r21856  
    140140  my $infodb_map = shift(@_);
    141141
    142   # !! TO IMPLEMENT
     142  print STDERR "******* mssql::read_infodb_file() TO BE IMPLEMENTED!\n";
     143  print STDERR "******* See sqlite.pm for comparable implementation that has been coded up!\n";
    143144}
    144145
     
    199200}
    200201
     202
     203sub write_infodb_rawentry
     204{
     205  my $infodb_handle = shift(@_);
     206  my $infodb_key = shift(@_);
     207  my $infodb_val = shift(@_);
     208 
     209  # Prepare the query
     210  my $safe_infodb_key = &mssql_safe($infodb_key);
     211  my $query = "INSERT INTO " . $mssql_data_table_name . " (one_key, one_value) VALUES (N'" . $safe_infodb_key . "', N'" . &mssql_safe($infodb_val) . "')";
     212  dbquery($infodb_handle, $query);
     213}
     214
    201215sub delete_infodb_entry
    202216{
  • main/trunk/greenstone2/perllib/dbutil/sqlite.pm

    r21411 r21856  
    7272
    7373
     74sub read_infodb_cmd
     75{
     76  my $infodb_file_path = shift(@_);
     77  my $sqlcmd = shift(@_);
     78
     79  my $result = "";
     80
     81  my $sqlite3_exe = &util::filename_cat($ENV{'GSDLHOME'},"bin",$ENV{'GSDLOS'}, "sqlite3" . &util::get_os_exe());
     82  my $infodb_handle = undef;
     83  my $cmd = "echo \"$sqlcmd\" | \"$sqlite3_exe\" \"$infodb_file_path\"";
     84
     85  if (!-e "$sqlite3_exe" || !open($infodb_handle, "$cmd |"))
     86  {
     87      print STDERR "Unable to execute: $cmd\n";
     88      print STDERR "$!\n";
     89  }
     90  else {
     91
     92      my $line;
     93      while (defined($line=<$infodb_handle>)) {
     94      $result .= $line;
     95      }
     96
     97      close($infodb_handle);
     98  }
     99
     100  return $result;
     101}
     102
    74103sub get_infodb_file_path
    75104{
     
    88117  my $infodb_map = shift(@_);
    89118
    90   # !! TO IMPLEMENT
     119
     120  my $keys_str = read_infodb_cmd($infodb_file_path,"SELECT key FROM data;");
     121
     122  my @keys = split(/\n/,$keys_str);
     123
     124  foreach my $k (@keys) {
     125     
     126      my $k_safe = &sqlite_safe($k);
     127      my $select_val_cmd = "SELECT value FROM data WHERE key='$k_safe';";
     128
     129      my $val_str = read_infodb_cmd($infodb_file_path,$select_val_cmd);
     130
     131      $infodb_map->{$k} = $val_str;
     132  }
     133
    91134}
    92135
     
    146189
    147190
     191sub write_infodb_rawentry
     192{
     193  my $infodb_handle = shift(@_);
     194  my $infodb_key = shift(@_);
     195  my $infodb_val = shift(@_);
     196
     197  my $safe_infodb_key = &sqlite_safe($infodb_key);
     198  print $infodb_handle "INSERT OR REPLACE INTO data (key, value) VALUES ('" . $safe_infodb_key . "', '" . &sqlite_safe($infodb_val) . "');\n";
     199}
     200
     201
     202
    148203sub delete_infodb_entry
    149204{
Note: See TracChangeset for help on using the changeset viewer.