PostgreSQL - Generar Funciones 4

   
Vista:
Imágen de perfil de outrera

Generar Funciones 4

Publicado por outrera (35 intervenciones) el 01/04/2014 15:41:54
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
--
-- TOC entry 420 (class 1255 OID 25313)
-- Name: psp_verificar_funcion(character varying, character varying); Type: FUNCTION; Schema: utils; Owner: postgres
--
 
CREATE FUNCTION psp_verificar_funcion(p_schemaname character varying, p_nombre_funcion character varying) RETURNS boolean
    LANGUAGE plpgsql
    AS $$BEGIN
	PERFORM  proname, prosrc
		FROM    pg_catalog.pg_namespace n
		JOIN    pg_catalog.pg_proc p
		ON      pronamespace = n.oid
	WHERE   nspname = p_schemaname and proname=p_nombre_funcion;
	IF FOUND THEN
	   RETURN true;
	END IF;
 
	RETURN false;
END;$$;
 
 
ALTER FUNCTION utils.psp_verificar_funcion(p_schemaname character varying, p_nombre_funcion character varying) OWNER TO postgres;
 
--
-- TOC entry 639 (class 1255 OID 26390)
-- Name: psp_verificar_idioma(character varying, character varying); Type: FUNCTION; Schema: utils; Owner: postgres
--
 
CREATE FUNCTION psp_verificar_idioma(p_schemaname character varying, p_tablename character varying) RETURNS boolean
    LANGUAGE plpgsql
    AS $$
DECLARE
	oPkDef REFCURSOR ;
	oRecord record;
 
	oFieldList character varying;
	oExisteIdioma boolean;
BEGIN
 
 
 
	oFieldList:='';
	oExisteIdioma:=false;
 
	OPEN oPkDef FOR SELECT  utils.psp_listar_campos(p_schemaname, p_tablename);
	FETCH oPkDef INTO oPkDef;
 
	-- LISTA DE TABLAS
	LOOP
	    FETCH oPkDef INTO oRecord ;
 
		IF NOT FOUND THEN
			EXIT ;
		END IF;
 
		IF lower(trim(oRecord.column_name)) = 'id_idioma' THEN
 
			oExisteIdioma:=true;
			exit;
 
		END IF ;
 
 
	END LOOP ;
 
	CLOSE oPkDef ;
 
 
 
	RETURN oExisteIdioma;
 
END;
$$;
 
 
ALTER FUNCTION utils.psp_verificar_idioma(p_schemaname character varying, p_tablename character varying) OWNER TO postgres;
 
--
-- TOC entry 417 (class 1255 OID 33395)
-- Name: psp_verificar_idioma_prueba(character varying, character varying); Type: FUNCTION; Schema: utils; Owner: postgres
--
 
CREATE FUNCTION psp_verificar_idioma_prueba(p_schemaname character varying, p_tablename character varying) RETURNS boolean
    LANGUAGE plpgsql
    AS $$
DECLARE
	oPkDef REFCURSOR ;
	oRecord record;
 
	oFieldList character varying;
	oExisteIdioma boolean;
BEGIN
 
	oFieldList:='';
	oExisteIdioma:=false;
 
	FOR oRecord IN
		SELECT * FROM   utils.psp_listar_campos_prueba(p_schemaname,p_tablename)
				as (column_name character varying ,column_type character varying)
	LOOP
 
		IF lower(trim(oRecord.column_name)) = 'id_idioma' THEN
 
			oExisteIdioma:=true;
			exit;
 
		END IF ;
 
 
	END LOOP;
 
 
 
 
	RETURN oExisteIdioma;
 
END;
$$;
 
 
ALTER FUNCTION utils.psp_verificar_idioma_prueba(p_schemaname character varying, p_tablename character varying) OWNER TO postgres;
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
1
Responder