2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-07-22 09:52:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` FUNCTION `vn`.`address_getGeo`(vSelf INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
RETURNS int(11)
|
|
|
|
DETERMINISTIC
|
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Returns the geo for the passed address.
|
|
|
|
*
|
|
|
|
* @param vSelf The address id
|
|
|
|
* @return The geo id
|
|
|
|
*/
|
|
|
|
DECLARE vGeoFk INT;
|
|
|
|
|
|
|
|
SELECT p.geoFk INTO vGeoFk
|
|
|
|
FROM address a
|
|
|
|
JOIN town t ON t.provinceFk = a.provinceFk
|
|
|
|
JOIN postCode p ON p.townFk = t.id AND p.`code` = a.postalCode
|
|
|
|
WHERE a.id = vSelf
|
|
|
|
ORDER BY (a.city SOUNDS LIKE t.`name`) DESC
|
|
|
|
LIMIT 1;
|
|
|
|
|
|
|
|
RETURN vGeoFk;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|