contato@conradosaud.com.br
Conheça meu trabalhocontato@conradosaud.com.br
CREATE TABLE public.geoip_states (
country CHAR(2) NOT NULL,
loc_id CHAR(2) NOT NULL,
name VARCHAR(100) NOT NULL
)
CREATE OR REPLACE FUNCTION public.geoip_city_state (
p_ip inet,
out loc_id integer,
out country char,
out region char,
out city varchar,
out postal_code varchar,
out latitude double precision,
out longitude double precision,
out metro_code integer,
out area_code integer
)
RETURNS record AS
$body$
SELECT l.loc_id, l.country, c.name, city, postal_code, latitude, longitude, metro_code, area_code
FROM geoip_city_block b JOIN geoip_city_location l ON (b.loc_id = l.loc_id)
JOIN geoip_states c ON (c.loc_id = l.region AND c.country = l.country)
WHERE $1 >= begin_ip AND $1 <= end_ip ORDER BY begin_ip DESC LIMIT 1;
$body$
LANGUAGE 'sql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100;
SELECT * FROM geoip_city_state('177.34.156.40');
CREATE OR REPLACE FUNCTION public.geoip_buscalocalizacao (
p_ip varchar
)
RETURNS public.geoip_type AS
$body$
DECLARE
record geoip_type;
v_ip inet := p_ip::inet;
BEGIN
SELECT
loc_id, country, region, city,postal_code, latitude, longitude, metro_code, area_code
INTO
record.loc_id, record.country, record.region, record.city,
record.postal_code, record.latitude, record.longitude, record.metro_code, record.area_code
FROM
geoip_localizacao(v_ip);
RETURN record;
END;
$body$
LANGUAGE 'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100;
public string formataEstado(string nome) {
switch(nome){
case "Acre": return "AC";
case "Alagoas": return "AL";
case "Amapa": return "AP";
case "Amazonas": return "AM";
case "Bahia": return "BA";
case "Ceara": return "CE";
case "Distrito Federal": return "DF";
case "Espirito Santo": return "ES";
case "Goias": return "GO";
case "Maranhao": return "MA";
case "Mato Grosso": return "MT";
case "Mato Grosso do Sul": return "MS";
case "Minas Gerais": return "MG";
case "Para": return "PA";
case "Paraiba": return "PB";
case "Parana": return "PR";
case "Pernambuco": return "PE";
case "Piaui": return "PI";
case "Rio de Janeiro": return "RJ";
case "Rio Grande do Norte": return "RN";
case "Rio Grande do Sul": return "RS";
case "Rondonia": return "RO";
case "Roraima": return "RR";
case "Santa Catarina": return "SC";
case "Sao Paulo": return "SP";
case "Sergipe": return "SE";
case "Tocantins": return "TO";
default: return nome;
}
}
Faça um comentário a respeito deste artigo!