Bug 6981 - barcode not incrementing
Summary: barcode not incrementing
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Cataloging (show other bugs)
Version: master
Hardware: All All
: P5 - low normal (vote)
Target Milestone: ---
Assignee: Galen Charlton
QA Contact: Bugs List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-06 12:35 UTC by Nicole C. Engard
Modified: 2015-12-03 22:00 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Bot Control: ---
When did the bot last check this:
Who signed the patch off:
Text to go in the release notes:
Version(s) released in:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nicole C. Engard 2011-10-06 12:35:27 UTC
I have autobarcode on to just increment by 1 and in recent releases of master I have noticed that it stopped incrementing at 2345678765345431
Comment 1 Magnus Enger 2011-10-06 12:46:46 UTC
Could this be similar to the problem described in bug 6944?
Comment 2 Nicole C. Engard 2011-10-06 12:56:47 UTC
that's why i included the barcode in question .. in case it is the same problem, but i don't know how to find out.
Comment 3 Magnus Enger 2011-10-06 13:09:41 UTC
Try something like "update <table> set <column> = 2345678765345432 where <column> = 2345678765345431;" and see what happens, maybe?
Comment 4 Nicole C. Engard 2011-10-06 13:22:42 UTC
mysql> update items set barcode = 2345678765345432 where barcode = 2345678765345431;
Query OK, 0 rows affected (0.01 sec)
Rows matched: 0  Changed: 0  Warnings: 0
Comment 5 Marc Véron 2012-04-15 13:35:39 UTC
It seems that it is an issue of representation of numbers in Perl.
Up to a certain value they are repersented as integers, then as float, and that leads to a loss of precision.

I did the following test:

Using MySQL, set the highest value in the table to 2345678765345430

Adding an item, the form displays 2345678765345431 (as expected)
Following item sticks with 2345678765345431 (as described in the bug report)

However:
I you set the value to 2345678765345435 the form will show a value of 2345678765345441  (!)

This is the code snippet in barcode.pl (around line 90):
----snip----
	elsif ($autoBarcodeType eq 'incremental') {
		# not the best, two catalogers could add the same barcode easily this way :/
		$query = "select max(abs(barcode)) from items";
        my $sth = $dbh->prepare($query);
		$sth->execute();
		while (my ($count)= $sth->fetchrow_array) {
			$nextnum = $count;
		}
		$nextnum++;
    }
----end snip----

About numbers in Perl:
http://perldoc.perl.org/perlnumber.html

Maybe the issue could be solved with 
http://perldoc.perl.org/Math/BigInt.html

Following questions should be considered:
- Side effects with BigInt?
- If the correct new number can be transferred into the java script code, what happens when writing back the number into the database?
- What about the comment in the code snippet: # not the best, two catalogers could add the same barcode easily this way :/ ?
Comment 6 Marc Véron 2012-06-09 07:10:12 UTC
Could be resolved together with Bug 7911 - Greater flexibility in auto barcode number generation
Comment 7 Marc Véron 2015-01-05 16:35:12 UTC
Could no longer reproduce the issue on current master 3.19.00.005