From: Dan Scott Date: Fri, 13 Jul 2012 15:20:15 +0000 (-0400) Subject: Ensure we only generate unique barcodes X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=6f19f34f1057d6213258acb788dce6d6b8622405;p=contrib%2FConifer.git Ensure we only generate unique barcodes Rather than looping over existing barcodes only when we update the patron account, let's not return duplicate barcodes in the first place, mmmkay? Signed-off-by: Dan Scott --- diff --git a/tools/patron-load/ldap_sync b/tools/patron-load/ldap_sync index 0cff2c9c90..9a7bfff61d 100644 --- a/tools/patron-load/ldap_sync +++ b/tools/patron-load/ldap_sync @@ -178,6 +178,26 @@ def generate_lu_barcode(): return """ CREATE SEQUENCE evergreen.lu_barcode START 200000; +CREATE OR REPLACE FUNCTION evergreen.lu_generate_barcode() RETURNS TEXT AS $$ +DECLARE + bc_gen TEXT; + mod TEXT; + bc_serial RECORD; + bc_holder TEXT; +BEGIN + LOOP + SELECT NEXTVAL('evergreen.lu_barcode') AS bc INTO bc_serial; + bc_gen := '0000700' || bc_serial.bc::text; + bc_gen := bc_gen || evergreen.mod10(bc_gen); + + SELECT barcode INTO bc_holder FROM actor.card WHERE barcode = bc_gen; + EXIT WHEN bc_holder IS NULL; + END LOOP; + + RETURN bc_gen; +END; +$$ LANGUAGE PLPGSQL; + CREATE OR REPLACE FUNCTION evergreen.lu_update_barcode(usr_id INT) RETURNS TEXT AS $$ DECLARE bc_gen TEXT; @@ -200,20 +220,6 @@ BEGIN RETURN bc_gen; END; $$ LANGUAGE PLPGSQL; - -CREATE OR REPLACE FUNCTION evergreen.lu_generate_barcode() RETURNS TEXT AS $$ -DECLARE - barcode TEXT; - mod TEXT; - bc_serial RECORD; -BEGIN - SELECT NEXTVAL('evergreen.lu_barcode') AS bc INTO bc_serial; - barcode := '0000700' || bc_serial.bc::text; - barcode := barcode || evergreen.mod10(barcode); - - RETURN barcode; -END; -$$ LANGUAGE PLPGSQL; """