From 2a48da12ea5229e42491d827dc2acfc51df2e473 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Wed, 31 Aug 2011 16:08:48 -0400 Subject: [PATCH] Break barcode generator into smaller pieces This should make it easier to expose evergreen.lu_generate_barcode() for manual purposes (e.g. for creating a new user on the fly in the Register Patron UI). Signed-off-by: Dan Scott --- tools/patron-load/ldap_sync | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tools/patron-load/ldap_sync b/tools/patron-load/ldap_sync index e2b87ef855..216250f98f 100644 --- a/tools/patron-load/ldap_sync +++ b/tools/patron-load/ldap_sync @@ -178,15 +178,11 @@ def generate_lu_barcode(): print """ CREATE SEQUENCE evergreen.lu_barcode START 200000; -CREATE OR REPLACE FUNCTION evergreen.generate_lu_barcode(usr_id INT) RETURNS TEXT AS $$ +CREATE OR REPLACE FUNCTION evergreen.lu_update_barcode(usr_id INT) 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); + barcode := evergreen.lu_generate_barcode(); INSERT INTO actor.card (usr, barcode) VALUES (usr_id, barcode); @@ -197,6 +193,20 @@ BEGIN RETURN barcode; 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; """ -- 2.11.0