Ver Mensaje Individual
  #3  
Antiguo 06-07-2007
Avatar de unreal4u
unreal4u unreal4u is offline
Miembro
 
Registrado: nov 2004
Ubicación: Temuco, Chile
Posts: 105
Reputación: 20
unreal4u Va por buen camino
ejemplo de la ejecución, delphi 7, zeos 6.1.5 stable, postgres 8:

Código Delphi [-]
// llenamos algunos datos (no los puse todos) y nos conectamos a la base:
 zConnection1.HostName := host;
 zConnection1.Port     := puerto;
 zConnection1.User     := 'hola';
 zConnection1.Password := 'mundo';
 zConnection1.Connect;

// haciendo una consulta SQL: 
 zQuery1.SQL.Clear;
 ZQuery1.SQL.Add('SET CLIENT_ENCODING TO ' + #39 + 'LATIN2' + #39 + ';');
 zQuery1.SQL.Add('SELECT * FROM busca_CD(');
 zQuery1.SQL.Append('NULL'       + ',' +
              #39 + cadena + #39 + ',' +
              #39 + 'NULL' + #39 + ',' +
              #39 + 'NULL' + #39);
 zQuery1.SQL.Append(') AS ("Cód." char, "Título Principal" varchar, "Título Secundario" varchar, "Contenido" text);');
 zQuery1.Active := TRUE;
// nos desconectamos
 ZConnection1.Disconnect

el cual llama a esta función:

Código SQL [-]
CREATE OR REPLACE FUNCTION busca_cd(bpchar, character varying, character varying, character varying)
  RETURNS SETOF record AS
'
SELECT
 CD.cod_amigable,
 CD.titulo1, 
 CD.titulo2,
 Contenido_CD.descripcion
FROM CD, Contenido_CD
WHERE
 (((CD.cod_barra LIKE $1) OR
   (CD.titulo1 LIKE ''%'' || $2 || ''%'') OR 
   (CD.titulo2 LIKE ''%'' || $3 || ''%'') OR
   (Contenido_CD.descripcion LIKE ''%'' || LOWER($4) || ''%'')) AND
  Contenido_CD.cod_barra = CD.cod_barra);
'
  LANGUAGE 'sql' VOLATILE;


En el código delphi, #39 corresponde al caracter --> ' <-- (ALT+39), que lo ingresé así pq sino me cerraba el string en el código de delphi :P

Si quieres ver los datos, enlazas a un DBGrid y listo

Saludos !!
__________________
Código Delphi [-]
procedure Gracias; 
begin
 if Respuesta_a_Mensaje = TRUE then showmessage('Ojalá que te sirva')
 else showmessage('Gracias por responder... :-)');
end; // (c) unreal4u
Responder Con Cita