Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Bases de datos > MySQL
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 31-01-2017
koalasoft koalasoft is offline
Miembro
 
Registrado: oct 2004
Ubicación: Tenosique Tabasco
Posts: 86
Poder: 20
koalasoft Va por buen camino
Mensaje Conflicto entre tablas, Migración Query a ADOQuery

Buen dia .. tengo un detalle .... anterior mente usaba el siguiente código con el componente Query y me funcionaba muy bien sin problemas, usando en aquel entonces tablas paradox..

Código PHP:
with QueryRegONT do          // Busqueda por Modelo y Tipo
 
begin
   Close
;
   
SQL.Clear;
   
// ------------------------------------------------------------
   // Se ultilizó el PArametro JOIN para unir las otras Tablas
   // relacionando el Campo FOLIO en todas ellas siempre y cuando
   // Se cumpliera la condicion de busqueda del ONT ya registrado.
   // ------------------------------------------------------------
   
SQL.Add('SELECT * FROM CTRLONT.db CTRL ');
   
SQL.Add('join CLIENTES.db CL on CTRL.FOLIO = CL.FOLIO ');
   
SQL.Add('join ONT.db ONT on CTRL.FOLIO = ONT.Folio ');
   
SQL.Add('WHERE BOARD_ONT=:BOARD_ONT');
   
SQL.Add(' AND FRAME_ID=:FRAME_ID');
   
SQL.Add(' AND SLOT_ID=:SLOT_ID');
   
SQL.Add(' AND PORT_ID=:PORT_ID');
   
SQL.Add(' AND ONT_ID=:ONT_ID');

   
// --------------------------------------------------------
   //  Valores de búsqueda para el registro de Cliente.
   // --------------------------------------------------------
   
ParamByName('BOARD_ONT').AsInteger := StrToInt(Edit1.Text);
   
ParamByName('FRAME_ID').AsInteger := StrToInt(Edit2.Text);
   
ParamByName('SLOT_ID').AsInteger := StrToInt(Edit3.Text);
   
ParamByName('PORT_ID').AsInteger := StrToInt(Edit4.Text);
   
ParamByName('ONT_ID').AsInteger := StrToInt(Edit5.Text);
   
Open;
   if 
QueryRegONT.IsEmpty then
    Begin
    msError
('El ONT no se encuentra registrado, porfavor verifica los datos.','No existe Datos..');
    exit;
    
End
     
Else
      
Begin
      F
:= QueryRegONT.FieldByName('FOLIO').AsInteger;
      
// -------------------
      
with QueryCL do          // Busqueda por Modelo y Tipo
        
begin
          Close
;
          
SQL.Clear;
          
SQL.Add('SELECT * FROM CLIENTES.db ');
          
SQL.Add('WHERE FOLIO=:FOLIO');
          
ParamByName('FOLIO').AsInteger :=F;
          
Open;
        
end;
      
with QueryONT do          // Busqueda por Modelo y Tipo
        
begin
          Close
;
          
SQL.Clear;
          
SQL.Add('SELECT * FROM ONT.db ');
          
SQL.Add('WHERE FOLIO=:FOLIO');
          
ParamByName('FOLIO').AsInteger :=F;
          
Open;
        
end;
      
// -------------------
      
Bok.Enabled := True;
      
BBuscar.Enabled := False;
      
DesactivarCampos([Edit1,Edit2,Edit3,Edit4,Edit5]);
      
End;
 
end

Ahora el mismo código lo intenté migrar al componente ADOQuery ya que ahora estoy trabajando con tablas Mysql y lo tengo de esta forma:

Código PHP:
with ADOQueryCtrlONT do          // Busqueda por Modelo y Tipo
 
begin
   Close
;
   
SQL.Clear;
   
// ------------------------------------------------------------
   // Se ultilizó el PArametro JOIN para unir las otras Tablas
   // relacionando el Campo FOLIO en todas ellas siempre y cuando
   // Se cumpliera la condicion de busqueda del ONT ya registrado.
   // ------------------------------------------------------------
   
SQL.Add('SELECT * FROM CTRLONT CTRL ');
   
SQL.Add('join CLIENTES CL on CTRL.FOLIO = CL.FOLIO ');
   
SQL.Add('join ONTs ONT on CTRL.FOLIO = ONT.Folio ');
   
SQL.Add('WHERE BOARD_ONT= :BOARD_ONT');
   
SQL.Add(' AND FRAME_ID= :FRAME_ID');
   
SQL.Add(' AND SLOT_ID= :SLOT_ID');
   
SQL.Add(' AND PORT_ID= :PORT_ID');
   
SQL.Add(' AND ONT_ID= :ONT_ID');

   
// --------------------------------------------------------
   //  Valores de búsqueda para el registro de Cliente.
   // --------------------------------------------------------
   
Parameters.ParamByName('BOARD_ONT').Value  := Edit1.Text;
   
Parameters.ParamByName('FRAME_ID').Value := Edit2.Text;
   
Parameters.ParamByName('SLOT_ID').Value := Edit3.Text;
   
Parameters.ParamByName('PORT_ID').Value := Edit4.Text;
   
Parameters.ParamByName('ONT_ID').Value := StrToInt(Edit5.Text);
   
Open;
   if 
ADOQueryCtrlONT.IsEmpty then
    Begin
    msError
('El ONT no se encuentra registrado, por favor verifica los datos.','No existe Datos..');
    exit;
    
End
     
Else
      
Begin
      F
:= ADOQueryCtrlONT.FieldByName('FOLIO').Value;
      
// -------------------
      
with ADOQueryCL do          // Busqueda por Modelo y Tipo
        
begin
          Close
;
          
SQL.Clear;
          
SQL.Add('SELECT * FROM CLIENTES ');
          
SQL.Add('WHERE FOLIO= :FOLIO');
          
Parameters.ParamByName('FOLIO').Value :=F;
          
Open;
        
end;
      
with ADOQueryONT do          // Busqueda por Modelo y Tipo
        
begin
          Close
;
          
SQL.Clear;
          
SQL.Add('SELECT * FROM ONTs ');
          
SQL.Add('WHERE FOLIO= :FOLIO');
          
Parameters.ParamByName('FOLIO').Value :=F;
          
Open;
        
end;
      
// -------------------
      
Bok.Enabled := True;
      
BBuscar.Enabled := False;
      
DesactivarCampos([Edit1,Edit2,Edit3,Edit4,Edit5]);
      
End;
 
end
Al ejecutarlo me marca un mensaje de error que dices asi:

"Argumentos incorrectos, fuera del intervalo permitido o en conflicto con otro"

El compilador no marca error y prácticamente estoy usando el mismo código con el que si me funcionaba, saben cual podría ser el error?

EL error del mensaje lo genera en esta línea:

Código PHP:
SQL.Add('WHERE BOARD_ONT=:BOARD_ONT'); 

Última edición por koalasoft fecha: 31-01-2017 a las 16:59:32.
Responder Con Cita
  #2  
Antiguo 31-01-2017
aposi aposi is offline
Miembro
 
Registrado: dic 2006
Posts: 146
Poder: 18
aposi Va por buen camino
Hola,
En el Where indica a que tabla se refiere el campo
CL si es la tabla cliente, CTRL si esta en CTRLON o ONT si esta en ONTs
Responder Con Cita
  #3  
Antiguo 31-01-2017
koalasoft koalasoft is offline
Miembro
 
Registrado: oct 2004
Ubicación: Tenosique Tabasco
Posts: 86
Poder: 20
koalasoft Va por buen camino
Gracias por responder ..

Hice lo que mencionas, lo cambié por esto...

Código PHP:
   SQL.Add('SELECT * FROM CTRLONT CTRL ');
   
SQL.Add('join CLIENTES CL on CTRL.FOLIO = CL.FOLIO ');
   
SQL.Add('join ONTs ONT on CTRL.FOLIO = ONT.Folio ');
   
SQL.Add('WHERE CTRL.BOARD_ONT= :BOARD_ONT');        // Aquí marca el error
   
SQL.Add(' AND CTRL.FRAME_ID= :FRAME_ID');
   
SQL.Add(' AND CTRL.SLOT_ID= :SLOT_ID');
   
SQL.Add(' AND CTRL.PORT_ID= :PORT_ID');
   
SQL.Add(' AND CTRL.ONT_ID= :ONT_ID'); 
Ya que la búsqueda correponde a la tabla CTRLONT, pero en la misma línea WHERE me sigue marcando el mismo error.
Responder Con Cita
  #4  
Antiguo 31-01-2017
aposi aposi is offline
Miembro
 
Registrado: dic 2006
Posts: 146
Poder: 18
aposi Va por buen camino
la tabla ONT se llama ONT o ONTs?

En el Query que funcionava se llama ONT
Código Delphi [-]
SQL.Add('join ONT.db ONT on CTRL.FOLIO = ONT.Folio ');
Y en el nuevo ONTs
Código Delphi [-]
SQL.Add('join ONTs ONT on CTRL.FOLIO = ONT.Folio ');
Responder Con Cita
  #5  
Antiguo 31-01-2017
koalasoft koalasoft is offline
Miembro
 
Registrado: oct 2004
Ubicación: Tenosique Tabasco
Posts: 86
Poder: 20
koalasoft Va por buen camino
Cita:
Empezado por aposi Ver Mensaje
la tabla ONT se llama ONT o ONTs?

En el Query que funcionava se llama ONT
Código Delphi [-]
SQL.Add('join ONT.db ONT on CTRL.FOLIO = ONT.Folio ');
Y en el nuevo ONTs
Código Delphi [-]
SQL.Add('join ONTs ONT on CTRL.FOLIO = ONT.Folio ');
Ahora se llama ONTs la tabla, pero pasa algo curioso, quite estas líneas:

Código PHP:
SQL.Add(' AND CTRL.FRAME_ID= :FRAME_ID'); 
   
SQL.Add(' AND CTRL.SLOT_ID= :SLOT_ID'); 
   
SQL.Add(' AND CTRL.PORT_ID= :PORT_ID'); 
   
SQL.Add(' AND CTRL.ONT_ID= :ONT_ID'); 
Dejando la consulta de esta forma:

Código PHP:
SQL.Add('SELECT * FROM CTRLONT ');  
SQL.Add('WHERE BOARD_ONT= :BOARD_ONT'); 
Y de nuevo en la segunda línea donde esta el WHERE me marca el mismo error.
Responder Con Cita
  #6  
Antiguo 31-01-2017
Avatar de TOPX
TOPX TOPX is offline
Miembro
 
Registrado: may 2008
Ubicación: Bogotá
Posts: 527
Poder: 16
TOPX Va camino a la fama
Buen día.

... información de interés ~ Using parameters with ADO Query (mysql/MyConnector) - StackOverflow
-
__________________
"constructive mind, destructive thoughts"
Responder Con Cita
Respuesta



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
conflicto entre aplicaciones zajoma Tablas planas 3 27-05-2008 17:48:58
Conflicto entre puertos jsanchez API de Windows 2 07-09-2007 00:37:17
Conflicto entre nospE y eagS marcoszorrilla La Taberna 3 09-01-2007 18:34:23
Query entre dos tablas de distintas databases tefots Firebird e Interbase 2 06-11-2006 15:28:29
Conflicto entre Query y Tabla filtrada Michael Varios 2 20-05-2004 21:37:43


La franja horaria es GMT +2. Ahora son las 20:47:45.


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