mirror of
https://codeberg.org/scip/note.git
synced 2025-12-17 12:41:10 +01:00
FIXED: There were many new bugs after my last changes *grrrrr*. fixed.
Works now properly, with both backends!
FIXED: and another bug: recounting of numbers did not take care about
the existing order! If you deleted note #12, then note #13 became
not neccessarily #12! Instead it becames any other number (kind of
randomly...).
CHANGED: NOTEDB::binary set_del function changed, it does no more require
a temporary file for number recount. Instead it uses get_all and
stores all notes in RAM and then rewrites the database.
FIXED: fixed the set_new call within note. It used 0 as the first param
(number) which is not useful since we dont have support for auto-
increment from all database backends.
FIXED: fixed the function set_recountnum in NITEDB::mysql, it was also
incorrect :-((( 0.8 seemed to be a very bad early alpha...........
FIXED: there was a bug in NOTEDB::binary which caused not to recount note
numbers after deleting one :-(
This commit is contained in:
103
NOTEDB/binary.pm
103
NOTEDB/binary.pm
@@ -1,4 +1,8 @@
|
||||
#!/usr/bin/perl
|
||||
# $Id: binary.pm,v 1.3 2000/03/20 00:36:50 thomas Exp thomas $
|
||||
# Perl module for note
|
||||
# binary database backend. see docu: perldoc NOTEDB::binary
|
||||
#
|
||||
use strict;
|
||||
use Data::Dumper;
|
||||
use IO::Seekable;
|
||||
@@ -8,7 +12,7 @@ use Fcntl qw(LOCK_EX LOCK_UN);
|
||||
|
||||
# Globals:
|
||||
my ($NOTEDB, $sizeof, $typedef,$version);
|
||||
$version = "(NOTEDB::binary, 1.1)";
|
||||
$version = "(NOTEDB::binary, 1.3)";
|
||||
|
||||
|
||||
sub new
|
||||
@@ -107,7 +111,7 @@ sub get_nextnum
|
||||
while(read(NOTE, $buffer, $sizeof)) {
|
||||
($num, $te, $me) = unpack($typedef, $buffer);
|
||||
}
|
||||
$num++;
|
||||
$num += 1;
|
||||
flock NOTE, LOCK_UN;
|
||||
close NOTE;
|
||||
|
||||
@@ -142,38 +146,6 @@ sub get_search
|
||||
|
||||
|
||||
|
||||
sub set_recountnums
|
||||
{
|
||||
my $this = shift;
|
||||
my(@count, $i, $num, $setnum, $buffer, $buff, $note, $date);
|
||||
|
||||
open NOTE, "+<$NOTEDB" or die "could not open $NOTEDB\n";
|
||||
flock NOTE, LOCK_EX;
|
||||
|
||||
$setnum = 1;
|
||||
my $TEMP = "/tmp/note.$$"; # save temporarily in $TEMP
|
||||
system("/bin/touch", $TEMP);
|
||||
open TEMP, "+<$TEMP" or die "Could not open $TEMP($!)\n";
|
||||
|
||||
seek(NOTE, 0, 0); # START FROM BEGINNING
|
||||
while(read(NOTE, $buffer, $sizeof)) {
|
||||
($num, $note, $date) = unpack($typedef, $buffer);
|
||||
$buff = pack($typedef, $setnum, $note, $date);
|
||||
seek(TEMP, 0, IO::Seekable::SEEK_END); # APPEND
|
||||
print TEMP $buffer;
|
||||
$setnum++;
|
||||
}
|
||||
close(TEMP);
|
||||
|
||||
flock NOTE, LOCK_UN;
|
||||
close NOTE;
|
||||
|
||||
system("/bin/cp",$TEMP, $NOTEDB);
|
||||
|
||||
unlink $TEMP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
sub set_edit
|
||||
{
|
||||
@@ -215,40 +187,55 @@ sub set_new
|
||||
sub set_del
|
||||
{
|
||||
my($this, $num) = @_;
|
||||
my($note, $date, $T, $setnum, $buffer, $buff, $n);
|
||||
my(%orig, $note, $date, $T, $setnum, $buffer, $n, $N, $t);
|
||||
|
||||
$setnum = 1;
|
||||
my $TEMP = "/tmp/note.$$"; # save temporarily in $TEMP
|
||||
system("/bin/touch", $TEMP);
|
||||
open TEMP, "+<$TEMP" or die "Could not open $TEMP($!)\n";
|
||||
|
||||
open NOTE, "+<$NOTEDB" or die "could not open $NOTEDB\n";
|
||||
%orig = $this->get_all();
|
||||
return "ERROR" if (! exists $orig{$num});
|
||||
|
||||
delete $orig{$num};
|
||||
|
||||
# overwrite, but keep number!
|
||||
open NOTE, ">$NOTEDB" or die "could not open $NOTEDB\n";
|
||||
flock NOTE, LOCK_EX;
|
||||
|
||||
seek(NOTE, 0, 0); # START FROM BEGINNING
|
||||
while(read(NOTE, $buffer, $sizeof)) {
|
||||
($n, $note, $date) = unpack($typedef, $buffer);
|
||||
$buff = pack($typedef, $setnum, $note, $date);
|
||||
if($n != $num) {
|
||||
seek(TEMP, 0, IO::Seekable::SEEK_END); # APPEND
|
||||
print TEMP $buff;
|
||||
}
|
||||
else
|
||||
{
|
||||
$T = $date;
|
||||
}
|
||||
foreach $N (keys %orig) {
|
||||
$n = uen($orig{$N}->{'note'});
|
||||
$t = uen($orig{$N}->{'date'});
|
||||
$buffer = pack( $typedef, $N, $n, $t); # keep orig number, note have to call recount!
|
||||
print NOTE $buffer;
|
||||
seek(NOTE, 0, IO::Seekable::SEEK_END);
|
||||
$setnum++;
|
||||
}
|
||||
close(TEMP);
|
||||
|
||||
}
|
||||
flock NOTE, LOCK_UN;
|
||||
close NOTE;
|
||||
return;
|
||||
}
|
||||
|
||||
system("/bin/cp",$TEMP, $NOTEDB);
|
||||
sub set_recountnums
|
||||
{
|
||||
my($this) = @_;
|
||||
my(%orig, $note, $date, $T, $setnum, $buffer, $n, $N, $t);
|
||||
|
||||
$setnum = 1;
|
||||
%orig = $this->get_all();
|
||||
|
||||
unlink $TEMP;
|
||||
|
||||
return "ERROR" if($T eq ""); # signal success!
|
||||
open NOTE, ">$NOTEDB" or die "could not open $NOTEDB\n";
|
||||
flock NOTE, LOCK_EX;
|
||||
seek(NOTE, 0, 0); # START FROM BEGINNING
|
||||
|
||||
foreach $N (sort {$a <=> $b} keys %orig) {
|
||||
$n = uen($orig{$N}->{'note'});
|
||||
$t = uen($orig{$N}->{'date'});
|
||||
$buffer = pack( $typedef, $setnum, $n, $t);
|
||||
print NOTE $buffer;
|
||||
seek(NOTE, 0, IO::Seekable::SEEK_END);
|
||||
$setnum++;
|
||||
}
|
||||
flock NOTE, LOCK_UN;
|
||||
close NOTE;
|
||||
return;
|
||||
}
|
||||
|
||||
sub uen
|
||||
|
||||
Reference in New Issue
Block a user