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;
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;
"""