From d654e104250fd118690dd4ccc7cef44df14f04e9 Mon Sep 17 00:00:00 2001 From: yorickdewid Date: Sat, 5 Mar 2016 23:17:05 +0100 Subject: [PATCH] Binary conversions --- iban--1.0.0.sql | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 iban--1.0.0.sql diff --git a/iban--1.0.0.sql b/iban--1.0.0.sql new file mode 100644 index 0000000..5d8fd85 --- /dev/null +++ b/iban--1.0.0.sql @@ -0,0 +1,67 @@ +--- IBAN datatype and verificator -*- sql -*- +--- +--- Copyright © 2016 Yorick de Wid +--- +--- This program is free software: you can redistribute it and/or modify +--- it under the terms of the GNU General Public License as published by +--- the Free Software Foundation, either version 2 of the License, or +--- (at your option) any later version. +--- +--- This program is distributed in the hope that it will be useful, but +--- WITHOUT ANY WARRANTY; without even the implied warranty of +--- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +--- General Public License for more details. +--- +--- You should have received a copy of the GNU General Public License +--- along with this program. If not, see +--- . + +CREATE TYPE iban; + +CREATE OR REPLACE FUNCTION ibanin(cstring) + RETURNS iban + AS 'iban' + LANGUAGE C + IMMUTABLE STRICT; + +CREATE OR REPLACE FUNCTION ibanout(iban) + RETURNS cstring + AS 'iban' + LANGUAGE C + IMMUTABLE STRICT; + +CREATE OR REPLACE FUNCTION ibanrecv(internal) + RETURNS iban + AS 'iban' + LANGUAGE C + IMMUTABLE STRICT; + +CREATE OR REPLACE FUNCTION ibansend(iban) + RETURNS bytea + AS 'iban' + LANGUAGE C + IMMUTABLE STRICT; + +CREATE TYPE iban ( + LIKE = text, + INPUT = ibanin, + OUTPUT = ibanout, + RECEIVE = ibanrecv, + SEND = ibansend, + -- make it a non-preferred member of string type category + CATEGORY = 'S', + PREFERRED = false +); + +COMMENT ON TYPE iban IS 'International Bank Account Number'; + +CREATE CAST (iban AS text) WITHOUT FUNCTION AS IMPLICIT; +CREATE CAST (iban AS varchar) WITHOUT FUNCTION AS IMPLICIT; +CREATE CAST (iban AS bpchar) WITHOUT FUNCTION AS ASSIGNMENT; + +CREATE OR REPLACE FUNCTION iban_validate(text) + RETURNS boolean AS 'MODULE_PATHNAME' + LANGUAGE C + IMMUTABLE STRICT; +COMMENT ON FUNCTION iban_validate (text) + IS 'Validate IBAN account';