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:
TLINDEN
2012-02-10 20:13:09 +01:00
parent f54d187c47
commit c38665373c
7 changed files with 154 additions and 103 deletions

View File

@@ -1,5 +1,26 @@
==================================================================================
0.9:
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 :-(
==================================================================================
0.8:
ADDED: NOTEDB::binary. so now 0.8 is ready for shipping !
FIXED: regexp bug fixed. It was only possible to delete 2 items together

View File

@@ -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

View File

@@ -1,4 +1,9 @@
#!/usr/bin/perl
# $Id: mysql.pm,v 1.2 2000/03/20 00:36:55 thomas Exp thomas $
# Perl module for note
# mysql database backend. see docu: perldoc NOTEDB::binary
#
use DBI;
use strict;
use Data::Dumper;
@@ -11,7 +16,7 @@ $table = "note";
$fnum = "number";
$fnote = "note";
$fdate = "date";
$version = "(NOTEDB::mysql, 1.0)";
$version = "(NOTEDB::mysql, 1.2)";
# prepare some std statements... #####################################################################
my $sql_getsingle = "SELECT $fnote,$fdate FROM $table WHERE $fnum = ?";
@@ -124,24 +129,6 @@ sub get_search
sub set_recountnums
{
my $this = shift;
my(@count, $i, $num, $setnum);
$setnum = 1;
my $statement = $DB->prepare($sql_incrnum) || die $DB->errstr();
my $sub_statement = $DB->prepare($sql_setnum) || die $DB->errstr();
$statement->execute || die $DB->errstr();
$statement->bind_columns(undef, \($num)) || die $DB->errstr();
while($statement->fetch) {
$sub_statement->execute($setnum,$num) || die $DB->errstr();
$setnum++;
}
}
sub set_edit
{
@@ -171,24 +158,41 @@ sub set_del
{
my($this, $num) = @_;
my($note, $date, $T);
my $stat = $DB->prepare($sql_getsingle) || die $DB->errstr();
$stat->execute($num) || die $DB->errstr();
$stat->bind_columns(undef, \($note, $date)) || die $DB->errstr();
while($stat->fetch) {
$T = $date;
}
($note, $date) = $this->get_single($num);
my $statement = $DB->prepare($sql_del) || die $DB->errstr();
return "ERROR" if ($date !~ /^\d/);
$statement->execute($num) || die $DB->errstr();
$this->set_recountnums();
return "ERROR" if($T eq ""); # signal success!
# delete record!
my $statement = $DB->prepare($sql_del) || die $DB->errstr();
$statement->execute($num) || die $DB->errstr();
return;
}
sub set_recountnums
{
my $this = shift;
my(@count, $i, $num, $setnum, $pos);
$setnum = 1;
$pos=0; $i=0; @count = ();
my $statement = $DB->prepare($sql_incrnum) || die $DB->errstr();
$statement->execute || die $DB->errstr();
$statement->bind_columns(undef, \($num)) || die $DB->errstr();
# store real id's in an array!
while($statement->fetch) {
$count[$i] = $num;
$i++;
}
# now recount them!
my $sub_statement = $DB->prepare($sql_setnum) || die $DB->errstr();
for($pos=0;$pos<$i;$pos++) {
$setnum = $pos +1;
$sub_statement->execute($setnum,$count[$pos]) || die $DB->errstr();
}
}
1; # keep this!

2
README
View File

@@ -1,4 +1,4 @@
note 0.8 by Thomas Linden, 19/03/2000
note 0.9 by Thomas Linden, 20/03/2000
Introduction

32
UPGRADE
View File

@@ -1,3 +1,29 @@
if you are upgrading an existing note installation,
you need to reedit your configfile, since there are now
some new required options!
In any case: BACKUP your existing note database!!!!!!!
The format has not changed, but some default values
(see the new config file-sample). Use this command
to save your note database with your *old* version
of note:
"note -D"
This works with both the mysql and the binary version.
You need to reedit your configfile, since there are now
some new required options! The most important: $dbdriver.
If you used previously a binary db without a config, then
you will get trouble with your existing notedb because the
default values for field sizes has been changed (it was too
small)! You have two choices:
1. make a database dump ("note -D") with your old note-version.
2. remove your existing .notedb (and/or back it up!)
3. install the new note version
4. import the previously created dump ("note -I note.dump.23112")
or
Edit the config to reflect your field size settings. Set the
fields MAX_TIME=64 and MAX_NOTE=1024 (which was the default of
previous versions of note).
AGAIN: YOU HAVE BEEN WARNED! DO NOT UPGRADE WITHOUT MADE A
BACKUP OF YOUR DATABASE! I AM NOT RESPONSIBLE IF YOU
LOOSE DATA!

View File

@@ -1 +1 @@
0.8
0.9

View File

@@ -1,7 +1,15 @@
#!/usr/bin/perl
# $Author: thomas $ $Id: note,v 1.13 2000/03/19 11:53:32 thomas Exp thomas $ $Revision: 1.13 $
# $Author: thomas $ $Id: note,v 1.15 2000/03/19 23:41:04 thomas Exp thomas $ $Revision: 1.15 $
#
# $Log: note,v $
# Revision 1.15 2000/03/19 23:41:04 thomas
# changed set_del, now no extra TEMP file is required!
# instead I get it from $this->get_all() !
#
# Revision 1.14 2000/03/19 22:51:49 thomas
# Bug in NOTEDB::binary fixed, recount of nubers was
# incorrect.
#
# Revision 1.13 2000/03/19 11:53:32 thomas
# edit bug fixed (ude => uen)
#
@@ -115,7 +123,7 @@ $TIME_COLOR = "black";
$TOPIC_COLOR = "BLACK";
$TOPIC = 1;
$TopicSep = '/';
$version = "0.8 r1.12";
$version = "0.9 r1.15";
if($TOPIC)
{
$CurDepth = 1; # the current depth inside the topic "directory" structure...
@@ -586,7 +594,7 @@ sub new
############################### DELETE ##################################
sub del
{
my($i,@count, $setnum, $pos, $ERR);
my($i,@count, $setnum, $pos, $ERR);
# delete a note
&num_bereich; # get @NumBlock from $number
foreach $_ (@NumBlock)
@@ -602,6 +610,8 @@ sub del
}
}
# recount the notenumbers:
$db->set_recountnums();
@NumBlock = ();
}
@@ -683,7 +693,7 @@ sub dump
sub import
{
my($num, $start, $complete, $dummi, $note, $date, $time);
my($num, $start, $complete, $dummi, $note, $date, $time, $number);
# open $dump_file and import it into the notedb
open (DUMP, "<$dump_file") or die "could not open $dump_file\n";
$complete=0;
@@ -702,7 +712,8 @@ sub import
else
{
# we got a complete record, save it!
$db->set_new(0,$note, $date);
$number = $db->get_nextnum();
$db->set_new($number,$note, $date);
print "note number $number from $dump_file inserted into notedb.\n";
$complete = 0;
$note = "";
@@ -724,7 +735,8 @@ sub import
if($note ne "" && $date ne "")
{
# the last record, if existent
$db->set_new(0,$note, $date);
$number = $db->get_nextnum();
$db->set_new($number,$note, $date);
print "note number $number from $dump_file inserted into notedb.\n";
}
}
@@ -1122,9 +1134,10 @@ sub ude
sub num_bereich
{
my($m,@LR,@Sorted_LR,$i);
# $number is the one we want to delete!
# $number is the one we want to delete!
# But does it contain kommas?
$m = 0;
@NumBlock = (); #reset
$m = 0;
if($number =~ /\,/)
{
# accept -d 3,4,7