2
# $Id: dbm.pm,v 1.3 2000/08/11 00:05:58 zarahg Exp $
4
# DBM database backend. see docu: perldoc NOTEDB::dbm
9
$NOTEDB::dbm::VERSION = "1.40";
15
use vars qw(@ISA @EXPORT %note %date);
16
@ISA = qw(NOTEDB Exporter);
25
my($this, %param) = @_;
26
my $class = ref($this) || $this;
30
my $notefile = "note.dbm";
31
my $timefile = "date.dbm";
32
my $dbm_dir = $param{directory} || File::Spec->catfile($ENV{HOME}, ".note_dbm");
36
mkdir $dbm_dir || die "Could not create $dbm_dir: $!\n";
39
tie %note, "DB_File", "$dbm_dir/$notefile" || die "Could not tie $dbm_dir/$notefile: $!\n";
40
tie %date, "DB_File", "$dbm_dir/$timefile" || die "Could not tie $dbm_dir/$timefile: $!\n";
42
$self->{LOCKFILE} = $param{dbname} . "~LOCK";
56
return $this->{version};
64
return $this->ude ($note{$num}), $this->ude($date{$num});
71
my($num, $note, $date, %res, $real);
72
foreach $num (sort {$a <=> $b} keys %date) {
73
$res{$num}->{'note'} = $this->ude($note{$num});
74
$res{$num}->{'date'} = $this->ude($date{$num});
80
my ($this, $data) = @_;
81
foreach my $num (keys %{$data}) {
82
my $pos = $this->get_nextnum();
83
$note{$pos} = $this->ude($note{$num}->{note});
84
$date{$pos} = $this->ude($date{$num}->{date});
91
foreach (sort {$a <=> $b} keys %date) {
100
my($this, $searchstring) = @_;
101
my($num, $note, $date, %res, $match);
103
my $regex = $this->generate_search($searchstring);
106
print "invalid expression: \"$searchstring\"!\n";
110
foreach $num (sort {$a <=> $b} keys %date) {
111
$_ = $this->ude($note{$num});
114
$res{$num}->{'note'} = $this->ude($note{$num});
115
$res{$num}->{'date'} = $this->ude($date{$num});
128
my(%Note, %Date, $num, $setnum);
130
foreach $num (sort {$a <=> $b} keys %note) {
131
$Note{$setnum} = $note{$num};
132
$Date{$setnum} = $date{$num};
143
my($this, $num, $note, $date) = @_;
144
$note{$num} = $this->uen($note);
145
$date{$num} = $this->uen($date);
151
my($this, $num, $note, $date) = @_;
152
$this->set_edit($num, $note, $date); # just the same thing
158
my($this, $num) = @_;
159
my($note, $date, $T);
160
($note, $date) = $this->get_single($num);
161
return "ERROR" if ($date !~ /^\d/);
178
if($NOTEDB::crypt_supported == 1) {
180
$T = pack("u", $this->{cipher}->encrypt($_[0]));
194
if($NOTEDB::crypt_supported == 1) {
196
$T = $this->{cipher}->decrypt(unpack("u",$_[0]))
213
NOTEDB::dbm - module lib for accessing a notedb from perl
220
# create a new NOTEDB object (the last 4 params are db table/field names)
221
$db = new NOTEDB("mysql","note","/home/user/.notedb/");
224
($note, $date) = $db->get_single(1);
226
# search for a certain note
227
%matching_notes = $db->get_search("somewhat");
228
# format of returned hash:
229
#$matching_notes{$numberofnote}->{'note' => 'something', 'date' => '23.12.2000 10:33:02'}
231
# get all existing notes
232
%all_notes = $db->get_all();
233
# format of returnes hash like the one from get_search above
235
# get the next noteid available
236
$next_num = $db->get_nextnum();
238
# recount all noteids starting by 1 (usefull after deleting one!)
239
$db->set_recountnums();
241
# modify a certain note
242
$db->set_edit(1, "any text", "23.12.2000 10:33:02");
245
$db->set_new(5, "any new text", "23.12.2000 10:33:02");
247
# delete a certain note
252
You can use this module for accessing a note database. This is the dbm module.
253
It uses the DB_FILE module to store it's data and it uses DBM files for tis purpose.
255
Currently, NOTEDB module is only used by note itself. But feel free to use it
256
within your own project! Perhaps someone want to implement a webinterface to
261
please see the section SYNOPSIS, it says it all.
265
Thomas Linden <tom@daemon.de>.