Compare commits

..

6 Commits
v0.0 ... master

Author SHA1 Message Date
jordi fita mas 0bbb04196f Mark vatin type as collatable
Otherwise, since it is a type based on text, users could receive an
error like

> ERROR: could not determine which collation to use for string comparison

when running VACUUM ANALYZE, for instance.
2023-07-03 17:46:18 +02:00
jordi fita mas 6db136f578 Fix CIF computation in cases where CIF ends with 0
This si because the computed value was 10, instead of 0.
2023-07-03 01:38:00 +02:00
jordi fita mas 9635b2f3a3 Fix a problem with CIF checksum due to using char instead of int 2023-06-20 19:41:54 +02:00
jordi fita mas c229754d6a Update PostgreSQL version to 15, used in Debian 12 2023-06-15 12:21:52 +02:00
jordi fita mas 256ba9c5e1 Correct architecture from all to any 2023-01-25 00:50:59 +01:00
jordi fita mas d280b233b1 Remove the provides for pgtag from Debian’s control 2023-01-24 13:03:53 +01:00
9 changed files with 53 additions and 17 deletions

View File

@ -2,7 +2,8 @@ MODULE_big = vat
OBJS = vatin.o es.o
EXTENSION = vat
DATA = vat--0.0.sql
DATA = vat--0.0.sql \
vat--0.0--0.1.sql
PGFILEDESC = "vat - data type for VAT identification numbers"
REGRESS = vat

18
debian/changelog vendored
View File

@ -1,3 +1,21 @@
vat (0.3-1) bookworm; urgency=medium
* Mark the type as collatable.
-- jordi fita mas <jordi@tandem.blog> Mon, 03 Jul 2023 17:44:51 +0002
vat (0.2-1) bookworm; urgency=medium
* Fix CIF computation for CIF ending with 0.
-- jordi fita mas <jordi@tandem.blog> Mon, 03 Jul 2023 01:37:34 +0002
vat (0.0-2) bookworm; urgency=medium
* Fix CIF computation.
-- jordi fita mas <jordi@tandem.blog> Sat, 21 Jan 2023 19:41:05 +0002
vat (0.0-1) bullseye; urgency=medium
* Initial release.

11
debian/control vendored
View File

@ -11,14 +11,13 @@ Vcs-Git: https://dev.tandem.ws/tandem/vat.git
Homepage: https://dev.tandem.ws/tandem/vat
Rules-Requires-Root: no
Package: postgresql-13-vat
Architecture: all
Package: postgresql-15-vat
Architecture: any
Depends:
${shlibs:Depends},
${misc:Depends},
postgresql-13
Provides: postgresql-pgtap
Description: VAT identification number extension for PostgreSQL 13
postgresql-15
Description: VAT identification number extension for PostgreSQL 15
vat is a library to check for valid format of VAT identification numbers.
.
This package contains the extension for PostgreSQL 13.
This package contains the extension for PostgreSQL 15.

3
debian/control.in vendored
View File

@ -12,12 +12,11 @@ Homepage: https://dev.tandem.ws/tandem/vat
Rules-Requires-Root: no
Package: postgresql-PGVERSION-vat
Architecture: all
Architecture: any
Depends:
${shlibs:Depends},
${misc:Depends},
postgresql-PGVERSION
Provides: postgresql-pgtap
Description: VAT identification number extension for PostgreSQL PGVERSION
vat is a library to check for valid format of VAT identification numbers.
.

4
es.c
View File

@ -50,13 +50,13 @@ valid_cif(const char *cif) {
if (n % 2 == 0) {
evens += cif[n] - 48;
} else {
int d = cif[n] * 2;
int d = (cif[n] - 48) * 2;
int a = d / 10;
int b = d % 10;
odds += a + b;
}
}
checksum = 10 - (odds + evens) % 10;
checksum = (10 - (odds + evens) % 10) % 10;
return cif[8] == checksum + 48 || cif[8] == "JABCDEFGHI"[checksum];
}

View File

@ -7,11 +7,13 @@ SELECT 'ES40404040D'::VATIN,
'ES40404040-D'::VATIN,
' esx0523821l '::VATIN,
'ESM0243487d'::VATIN,
' ESb17616756 '::VATIN
' ESb17616756 '::VATIN,
'ESb17385717'::VATIN,
'ESA08023780'::VATIN
;
vatin | vatin | vatin | vatin | vatin
-------------+-------------+-------------+-------------+-------------
ES40404040D | ES40404040D | ESX0523821L | ESM0243487D | ESB17616756
vatin | vatin | vatin | vatin | vatin | vatin | vatin
-------------+-------------+-------------+-------------+-------------+-------------+-------------
ES40404040D | ES40404040D | ESX0523821L | ESM0243487D | ESB17616756 | ESB17385717 | ESA08023780
(1 row)
-- Test invalid checksums

View File

@ -9,7 +9,9 @@ SELECT 'ES40404040D'::VATIN,
'ES40404040-D'::VATIN,
' esx0523821l '::VATIN,
'ESM0243487d'::VATIN,
' ESb17616756 '::VATIN
' ESb17616756 '::VATIN,
'ESb17385717'::VATIN,
'ESA08023780'::VATIN
;
-- Test invalid checksums

15
vat--0.0--0.1.sql Normal file
View File

@ -0,0 +1,15 @@
/*
* SPDX-FileCopyrightText: 2023 jordi fita mas <jfita@peritasoft.com>
*
* SPDX-License-Identifier: PostgreSQL
*/
-- complain if script is sources in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION vat UPDATE TO '0.1'" to load this file. \quit
-- mark the type as collatable
UPDATE pg_catalog.pg_type SET typcollation = 100
WHERE oid = 'vatin'::pg_catalog.regtype;
UPDATE pg_catalog.pg_attribute SET attcollation = 100
WHERE atttypid = 'vatin'::pg_catalog.regtype;

View File

@ -1,5 +1,5 @@
comment = 'data type for VAT registration numbers'
default_version = '0.0'
default_version = '0.1'
module_pathname = '$libdir/vat'
relocatable = true
superuser = false