Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Conexión con bases de datos
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Conexión con bases de datos

 
 
Herramientas Buscar en Tema Desplegado
  #3  
Antiguo 23-06-2011
Avatar de fjcg02
[fjcg02] fjcg02 is offline
Miembro Premium
 
Registrado: dic 2003
Ubicación: Zamudio
Posts: 1.418
Poder: 24
fjcg02 Va camino a la fama
Muy buena la página relacionada.

Prueba esto que por cortesía de Al González pude conocer. Luego le añadí alguna cosilla.

Necesitas crear esta tabla para que te rule el procedimiento almacenado.
Código SQL [-]
/******************************************************************************/
/*                                   Tables                                   */
/******************************************************************************/


CREATE GENERATOR GEN_Z_DEFINICION_CAMPO;

CREATE TABLE Z_DEFINICION_CAMPO (
    IDCAMPO       INTEGER NOT NULL,
    TABLA         VARCHAR(20) NOT NULL,
    CAMPO         VARCHAR(20) NOT NULL,
    LABEL         VARCHAR(20),
    MASCARA       VARCHAR(20),
    TAMANIO       INTEGER,
    NOMBRE_SI_FK  VARCHAR(20),
    LABEL_SI_FK   VARCHAR(20),
    QUERY_SI_FK   VARCHAR(200)
);




/******************************************************************************/
/*                                Primary Keys                                */
/******************************************************************************/

ALTER TABLE Z_DEFINICION_CAMPO ADD CONSTRAINT FK_Z_DEFINICION_CAMPO PRIMARY KEY (IDCAMPO);


/******************************************************************************/
/*                                  Indices                                   */
/******************************************************************************/

CREATE UNIQUE INDEX Z_DEFINICION_CAMPO_IDX1 ON Z_DEFINICION_CAMPO (TABLA, CAMPO);


/******************************************************************************/
/*                                  Triggers                                  */
/******************************************************************************/


SET TERM ^ ;



/******************************************************************************/
/*                            Triggers for tables                             */
/******************************************************************************/



/* Trigger: Z_DEFINICION_CAMPO_BI0 */
CREATE OR ALTER TRIGGER Z_DEFINICION_CAMPO_BI0 FOR Z_DEFINICION_CAMPO
ACTIVE BEFORE INSERT POSITION 0
AS
begin
  /* Trigger text */
    IF (NEW.IDCAMPO IS NULL) THEN
     NEW.IDCAMPO = GEN_ID(gen_z_definicion_campo,1);
end
^


SET TERM ; ^

Ahora el procedimiento almacenado

Código SQL [-]
SET TERM ^ ;

CREATE OR ALTER PROCEDURE Z_TABLAS 
returns (
    tabla varchar(20),
    posicion integer,
    campo varchar(20),
    tipo varchar(25),
    longitud integer,
    decimales integer,
    permite_nulos char(2),
    pk integer,
    fk_campo varchar(50),
    fk_tabla varchar(50),
    descripcion varchar(500),
    label varchar(20),
    mascara varchar(20),
    tamanio varchar(20),
    nombre_si_fk varchar(20),
    label_si_fk varchar(20),
    query_si_fk varchar(200))
as
declare variable wtipo integer;
declare variable subtipo integer;
declare variable wprecision integer;
declare variable escala integer;
declare variable nulo integer;
begin
  /* Procedure Text */
 for
  Select

RF.RDB$Relation_Name TABLA,  /* Nombre de la tabla/vista */
RF.RDB$Field_Name CAMPO,  /* Nombre del campo */
RF.RDB$Field_Position POSICION,  /* Posición del campo */
RF.RDB$Description DESCRIPCION,  /* Descripción del campo */
F.RDB$Field_Type,
F.RDB$Field_Sub_Type,
/* Tipo concreto */
F.RDB$Field_Length,
F.RDB$Field_Precision,
/* Decimales */
F.RDB$Field_Scale,
/* Permite o no valores nulos */
RF.RDB$Null_Flag

From RDB$Relation_Fields RF

/* La información de campos está distribuida en las tablas
RDB$Relation_Fields y RDB$Fields */
Left Join RDB$Fields F On RF.RDB$Field_Source = F.RDB$Field_Name

/* No incluir tablas del sistema */
Where RF.RDB$System_Flag = 0
order by
RF.RDB$Relation_Name,RF.RDB$Field_Position

INTO :tabla, :campo, posicion, :descripcion, :wtipo, :subtipo, :longitud,
     :wprecision, :escala, :nulo
do  begin
  tipo= 'Desconocido';
  if  (wtipo = 261) /* BLOb */ Then
  begin
    if (subtipo = 1) Then
      tipo='Texto BLOb';
     else
      tipo='BLOb';
  end
  if  (wtipo = 14) Then tipo='Texto Char';
  if  (wtipo = 40) Then tipo='Texto CString';
  if  (wtipo = 11) Then tipo='Numérico D_Float';
  if  (wtipo = 27) Then tipo='Numérico Double'  ;
  if  (wtipo = 10) Then tipo='Numérico Float' ;
  if  (wtipo = 16) Then
  begin
    if  (subtipo = 1) Then tipo='Numérico';
    if  (subtipo = 2) Then
       tipo='Decimal';
    Else
       tipo='Entero Int64';
  End
  if  (wtipo =  8) /* Integer */ Then
  begin
    if  (subtipo = 1) Then tipo='Numérico';
    if  (subtipo = 2) Then tipo='Decimal';  Else tipo='Entero Integer';
  End
  if  (wtipo = 9) Then tipo='Quad';
  if  (wtipo = 7 )/* SmallInt */ Then
  begin
    if  (subtipo = 1) Then tipo='Numérico';
    if  (subtipo = 2) Then tipo='Decimal' ;Else tipo='Entero SmallInt';
  End
  if  (wtipo = 12) Then tipo='Fecha Date';
  if  (wtipo = 13) Then tipo='Hora Time';
  if  (wtipo = 35) Then tipo='Fecha y hora TimeStamp';
  if  (wtipo= 37) Then tipo='Texto Varchar';

  if  (wtipo= 11) /* D_Float */ Then longitud= wPrecision;
  if  (wtipo= 27) /* Double */ Then longitud= wPrecision;
  if  (wtipo= 10) /* Float */ Then longitud= wPrecision;
  if  (wtipo= 16) /* Int64 */ Then
    if (subtipo = 1 or subtipo =2) Then longitud= wPrecision;
  if  (wtipo= 8) /* Integer */ Then
      if (subtipo= 1 or subtipo=2) Then longitud= wPrecision;
  if  (wtipo= 7 )/* SmallInt */ Then
    if  (subtipo=1 or subtipo= 2) /* Decimal */ Then longitud= wPrecision;

  if (escala = 0) Then DECIMALES= Null;
  if (escala <> 0 and escala is not null) then DECIMALES= Cast (ESCALA * -1 As integer);

  if (NULO = 1) Then PERMITE_NULOS= 'No'; Else PERMITE_NULOS= 'Si';
  PK = null;
  select i.rdb$field_position
   from rdb$relation_constraints rc, rdb$index_segments i, rdb$indices idx
   where (i.rdb$index_name = rc.rdb$index_name) and
         (idx.rdb$index_name = rc.rdb$index_name) and
         (rc.rdb$constraint_type = 'PRIMARY KEY') and
         (rc.rdb$relation_name = :TABLA) and
         (i.rdb$field_name = :CAMPO)
   into :PK ;
   if (pk  is not null )  then pk = pk+1;

   FK_CAMPO = null;
   FK_TABLA = Null;
   select trim(D.RDB$FIELD_NAME), trim(C.RDB$RELATION_NAME)
   from RDB$REF_CONSTRAINTS B, RDB$RELATION_CONSTRAINTS A, RDB$RELATION_CONSTRAINTS C,
        RDB$INDEX_SEGMENTS D, RDB$INDEX_SEGMENTS E, RDB$INDICES I
   where (A.RDB$CONSTRAINT_TYPE = 'FOREIGN KEY') and
         (A.RDB$CONSTRAINT_NAME = B.RDB$CONSTRAINT_NAME) and
         (B.RDB$CONST_NAME_UQ=C.RDB$CONSTRAINT_NAME) and (C.RDB$INDEX_NAME=D.RDB$INDEX_NAME) and
         (A.RDB$INDEX_NAME=E.RDB$INDEX_NAME) and
         (A.RDB$INDEX_NAME=I.RDB$INDEX_NAME) and
         (A.RDB$RELATION_NAME = :TABLA) and
         (D.RDB$FIELD_NAME = :CAMPO)
         into :FK_CAMPO, :FK_TABLA;

   LABEL= Null;
   MASCARA= null;
   TAMANIO=Null;
   NOMBRE_SI_FK = Null;
   LABEL_SI_FK = Null;
   QUERY_SI_FK = Null;
   select LABEL,MASCARA, TAMANIO, NOMBRE_SI_FK, LABEL_SI_FK,QUERY_SI_FK
   FROM z_definicion_campo
   WHERE TABLA=:TABLA AND CAMPO = :CAMPO
   INTO :LABEL, :MASCARA, :TAMANIO, :NOMBRE_SI_FK, :LABEL_SI_FK,:QUERY_SI_FK;

  suspend;
  end

end^

SET TERM ; ^

GRANT SELECT ON Z_DEFINICION_CAMPO TO PROCEDURE Z_TABLAS;

Espero qiue te mole. Si quieres condensar, quita todo lo que dependa de la tabla que te he comentado para crear.

Para usarlo, utiliza "select * from z_tablas". Puedes filtrar por la tabla que quieras.

Saludos
__________________
Cuando los grillos cantan, es que es de noche - viejo proverbio chino -
Responder Con Cita
 


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Como seleccionar campos de una tabla sin saber cuantos van a seleccionar david duarte SQL 7 05-04-2010 21:15:43
Saber Campos Con Clave Forana, Saber campos con clave FORANA vivamotos Firebird e Interbase 2 18-09-2007 13:09:41
como puedo saber la cantidad de campos que tiene una tabla CottonMouth OOP 1 27-06-2007 07:02:49
Campos calculados, facturas y detalles de facturas. Letty Conexión con bases de datos 7 07-11-2003 11:19:44
cómo saber el nombre de los campos en ejecucion? ramiretor Conexión con bases de datos 5 26-05-2003 17:20:47


La franja horaria es GMT +2. Ahora son las 06:38:45.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi