2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`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
|
2024-11-18 07:58:38 +00:00
|
|
|
JOIN postCode p ON p.townFk = t.id
|
2024-11-18 12:09:33 +00:00
|
|
|
JOIN zoneGeo zg ON zg.id = p.geoFk
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE a.id = vSelf
|
2024-11-18 07:58:38 +00:00
|
|
|
ORDER BY (a.city SOUNDS LIKE t.name) DESC,
|
|
|
|
(p.code = a.postalCode) DESC
|
2024-01-15 11:31:03 +00:00
|
|
|
LIMIT 1;
|
|
|
|
|
|
|
|
RETURN vGeoFk;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|