maya
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
ot_rw_enable_chapas(character varying)
Parameters
Name
Type
Mode
_serialnumber
character varying
IN
Definition
DECLARE _idport integer; _iddevice integer; BEGIN /* 2017-11-05 To enable the chapas (manual door locks) functionality for a given device's serialnumber */ SELECT iddevice INTO _iddevice FROM device WHERE serialnumber = _serialnumber; SELECT p.idport INTO _idport FROM port p inner join device d using(iddevice) left join unit u using(idunit) inner join digital_outputport_cfg o using(idport) inner join peripheral t using(idport) where d.iddevice = _iddevice and p.portnumber = 3 and active = true; IF _idport IS NOT NULL THEN UPDATE peripheral SET idperipheraltype = 13 /* manual door lock (fs) */, idperipheral_template = 1 WHERE idport = _idport; ELSE INSERT INTO port(idport,iddevice,portnumber,idperipheral,idporttype,active) values (nextval('sec_port'),_iddevice,3,NULL,2/*digital*/,true); INSERT INTO digital_outputport_cfg (idport) values (currval('sec_port')); INSERT INTO peripheral (idperipheral,idport,idperipheraltype,idperipheral_template,creationdate,lastmodificationdate) VALUES (nextval('peripheral_idperipheral_seq'),currval('sec_port'),13 /* manual door lock (fs) */,1,now(),now()); END IF; RETURN _idport; END;