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,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!