mirror of
https://codeberg.org/scip/note.git
synced 2025-12-17 20:51:02 +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
|
||||
|
||||
@@ -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!
|
||||
|
||||
|
||||
Reference in New Issue
Block a user