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

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 24-02-2011
Avatar de gluglu
[gluglu] gluglu is offline
Miembro Premium
 
Registrado: sep 2004
Ubicación: Málaga - España
Posts: 1.455
Poder: 23
gluglu Va por buen camino
Código Delphi [-]
SET TERM ^ ;
CREATE OR ALTER PROCEDURE NEW_PROCEDURE2 (
    in_random decimal(12,0))
returns (
    out_random decimal(12,0))
as
 declare variable aux_rand decimal(12,0);
 declare variable aux_rand2 decimal(12,0);
 declare variable aux_true integer;
begin
 
  Select RANDOMNO from PRUEBA
    where RANDOMNO = :"IN_RANDOM"
    rows 1
  into AUX_RAND;
 
  if (:"AUX_RAND" is not null) then
    IN_RANDOM = IN_RANDOM + 1;
 
  Select RANDOMNO from PRUEBA
    where RANDOMNO = :"IN_RANDOM"
    rows 1
  into AUX_RAND;
 
  if (:"AUX_RAND" is not null) then
    IN_RANDOM = IN_RANDOM + 1;
 
  OUT_RANDOM = IN_RANDOM;
 
  suspend;
 
end
^
SET TERM ; ^

Por qué esta modificación, si ejecuto con el valor de entrada 1, entonces me devuelve 3 (!!! ) y si el valor de entrada es 2, entonces me devuelve 2 !!

Parece como si no gestionase correctamente la Suma + 1 del parámetro de Entrada In_Random. Pero es que como ya dije anteriormente lo he probado incluso con variables propias del procedimiento, sin tocar la variable de entrada, y tampoco ....
__________________
Piensa siempre en positivo !
Responder Con Cita
  #2  
Antiguo 24-02-2011
Avatar de Casimiro Noteví
Casimiro Noteví Casimiro Noteví is offline
Merodeador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.669
Poder: 10
Casimiro Noteví Tiene un aura espectacularCasimiro Noteví Tiene un aura espectacular
Prueba esto:

Código SQL [-]
CREATE OR ALTER PROCEDURE NEW_PROCEDURE2 (in_random decimal(12,0))
returns (out_random decimal(12,0))
as
  declare variable aux_rand decimal(12,0);
  declare variable aux_true integer;
begin
  AUX_TRUE  = 0;
 
  while (:AUX_TRUE = 0) do
  begin

    aux_rand = null;   /*   <------------------------------- */

    Select RANDOMNO from PRUEBA
      where RANDOMNO = :IN_RANDOM
      rows 1 into AUX_RAND;

    if (:AUX_RAND is null) then
    begin
      Leave;
    end
    else
    begin
      IN_RANDOM = :IN_RANDOM + 1;
      if (:IN_RANDOM > 200) then
        Leave;
    end

  end
 
  OUT_RANDOM = IN_RANDOM;
 
  suspend;
 
end
Responder Con Cita
  #3  
Antiguo 24-02-2011
Avatar de gluglu
[gluglu] gluglu is offline
Miembro Premium
 
Registrado: sep 2004
Ubicación: Málaga - España
Posts: 1.455
Poder: 23
gluglu Va por buen camino
... ahora lo pruebo ....

... PEOR todavía .....

Código Delphi [-]
begin
 
  AUX_RAND2 = IN_RANDOM;
 
  Select RANDOMNO from PRUEBA
    where RANDOMNO = 1
    rows 1
  into AUX_RAND;
 
  if (:"AUX_RAND" is not null) then
    AUX_RAND2 = AUX_RAND2 + 1;
 
  Select RANDOMNO from PRUEBA
    where RANDOMNO = 2
    rows 1
  into AUX_RAND;
 
  if (:"AUX_RAND" is not null) then
    AUX_RAND2 = AUX_RAND2 + 2;
 
  OUT_RANDOM = AUX_RAND2;
 
  suspend;
 
end

Si lo ejecuto con 1 de entrada, entonces el primer Select encuentra un valor, y suma 1 a la entrada. Correcto. El segundo Select busca un 2 en la base de datos, QUE NO EXISTE !. A pesar de eso, al parecer Aux_Rand is not null y suma otros 2 a Aux_Rand2, y me devuelve 4 !!!

Por qué carajo el segundo select me devuelve un valor que no es null ???
__________________
Piensa siempre en positivo !
Responder Con Cita
  #4  
Antiguo 24-02-2011
Avatar de Casimiro Noteví
Casimiro Noteví Casimiro Noteví is offline
Merodeador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.669
Poder: 10
Casimiro Noteví Tiene un aura espectacularCasimiro Noteví Tiene un aura espectacular
Pues no sé qué tienes en tu tabla, a mí no me devuelve eso

Si le paso 1, me devuelve 2.
Si le paso 2, me devuelve 2.
Si le paso 3, me devuelve 3.
Si le paso 88, me devuelve 88.

Tan sólo tengo el registro con valor '1' en la tabla.
Responder Con Cita
  #5  
Antiguo 24-02-2011
Avatar de gluglu
[gluglu] gluglu is offline
Miembro Premium
 
Registrado: sep 2004
Ubicación: Málaga - España
Posts: 1.455
Poder: 23
gluglu Va por buen camino
Pues YA ESTA !!!!

La solución es la que tu propones Casimiro !!!

Hay que 'resetear' la variable a null para que funciona correctamente.

En el mismo ejemplo que acabo de poner ahora último, si se 'resetea' de nuevo la variable a Null, entonces funciona también correctamente.



.... pero 'lógicamente' no debería hacer falta, no ??

MUCHAS GRACIAS !!!
__________________
Piensa siempre en positivo !
Responder Con Cita
  #6  
Antiguo 24-02-2011
Avatar de Casimiro Noteví
Casimiro Noteví Casimiro Noteví is offline
Merodeador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.669
Poder: 10
Casimiro Noteví Tiene un aura espectacularCasimiro Noteví Tiene un aura espectacular
Pues en teoría no sería necesario, no, debe ser un "bug" muy gracioso
Responder Con Cita
Respuesta


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
Stored Procedure !!! Ledian_Fdez C++ Builder 0 02-03-2010 14:01:29
Stored Procedure StartKill MySQL 2 27-08-2008 06:18:44
Ver los Stored Procedure tgsistemas SQL 0 06-04-2004 17:18:22
Stored Procedure tgsistemas SQL 1 27-02-2004 13:10:33
problema con stored procedure Markoz Firebird e Interbase 8 27-06-2003 13:46:31


La franja horaria es GMT +2. Ahora son las 06:37:54.


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