Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

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

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 21-02-2018
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Posts: 1.350
Poder: 19
Angel.Matilla Va por buen camino
UPDATE / DELETE: En programa no funciona, en SQL Manager sí

Hola. A ver si alguno es capaz de decirme donde está el error en el código porque yo llevo dos horas dando vueltas y no soy capaz de verlo. Perdonad si el código es un poco pesado.

Tengo una aplicación en BCB 6 que monta un query por código:
Código PHP:
fPersona->Query->Close();
switch ((
nItem Mensaje(2"Hay " FormatFloat("###,##0"fPersona->Auxiliar->Fields->FieldByNumber(1)->AsInteger) + " recibos " +
                         
LowerCase(RadioGroup1->Items->Strings[RadioGroup1->ItemIndex]) + " pendientes de emitir. Seleccione acción"cAux)))
{
     case 
1:
          
dFecha dFcargo;
          if (
RadioGroup1->ItemIndex == 0)
          {
               
fCalendar->Fecha->MinDate EncodeDate(197755);
               
fCalendar->Fecha->MaxDate DiaHabil(IncMonth(Date(), 12));
               
fCalendar->Fecha->Date    DiaHabil(Date());
               
fCalendar->ShowModal();

               if ((int)
fCalendar->Fecha->Date == dFechaNula)
               {
                    
Mensaje(4"Cancelado por el usuario""Volver");
                    
FormCreate(NULL);
                    return;
               }
               
dFecha = (int)fCalendar->Fecha->Date;
                    
               
fCalendar->Fecha->Date     DiaHabil((int)Date());
               
fCalendar->Fecha->MinDate  DiaHabil((int)Date());
               
fCalendar->Fecha->MaxDate  DiaHabil((int)Date() + 3);
          }
          
fPersona->Query->SQL->Text "UPDATE Emision SET Fecha = :Fecha, RefInt = :NewRef";
          
fPersona->Query->ParamByName("Fecha")->AsDateTime dFecha;
          
fPersona->Query->ParamByName("NewRef")->AsString  dFecha.FormatString("'1'yyyymmdd");
          break;
     case 
2:
          
fPersona->Query->SQL->Text "DELETE FROM Emision";
          break;
     case 
3:
          
Application->CreateForm(__classid(TfVerRec), &fVerRec);
          
fVerRec->Label1->Caption "";
          
fVerRec->Label2->Caption "";
          
fVerRec->Tag 2;

          
fPersona->Query->SQL->Text "SELECT Apellidos||', '||Nombre, Referencia, Nif, Codigo, Texto, Importe FROM Rc01 WHERE RefInt LIKE :RefInt ORDER BY 1, 2, 3, 4";
          
fPersona->Query->ParamByName("RefInt")->AsString FormatFloat("0'%'"RadioGroup1->ItemIndex 1);
          
fPersona->Query->Open();

          for (; !
fPersona->Query->EoffPersona->Query->Next())
          {
               
pItem fVerRec->LisRec->Items->Add();
               
pItem->Caption fPersona->Query->Fields->FieldByNumber(1)->AsString;
               if (!
fPersona->Query->FieldByName("Referencia")->AsString.IsEmpty())
                    
pItem->SubItems->Add(fPersona->Query->FieldByName("Referencia")->AsString);
               else if (!
fPersona->Query->FieldByName("Nif")->AsString.IsEmpty())
                    
pItem->SubItems->Add(fPersona->Query->FieldByName("Nif")->AsString);
               else
                    
pItem->SubItems->Add(fPersona->Query->FieldByName("Codigo")->AsInteger);
               
pItem->SubItems->Add(fPersona->Query->FieldByName("Texto")->AsString);
               
pItem->SubItems->Add(FormatFloat("##,##0.00 €"fPersona->Query->FieldByName("Importe")->AsFloat));
               
pItem->SubItems->Add(fPersona->Query->FieldByName("Codigo")->AsInteger);
          }
          
fVerRec->ShowModal();

          
cAux "";
          for (
nItem 0nItem fVerRec->LisRec->Items->CountnItem ++)
               if (
fVerRec->LisRec->Items->Item[nItem]->Checked)
                    
cAux cAux fVerRec->LisRec->Items->Item[nItem]->SubItems->Strings[3] + ", ";
          
cAux cAux.SubString(1cAux.LastDelimiter(",") - 1);
          
delete fVerRec;
          break;
     case 
4:
          
FormCreate(NULL);
          return;
}

if (
nItem == && cAux.IsEmpty())
     return;

try
{
     
fPersona->Query->SQL->Add("WHERE RefInt LIKE :RefInt");
     
fPersona->Auxiliar->ParamByName("RefInt")->AsString FormatFloat("0'%'"RadioGroup1->ItemIndex 1);
     if (
nItem == 3)
     {
          if (
cAux.Pos(",") == 0)
               
fPersona->Query->SQL->Add("AND Codigo = " cAux);
          else
               
fPersona->Query->SQL->Add("AND Codigo IN (" cAux ")");
     }
     
fPersona->Query->ExecSQL();
     
fPersona->Query->Transaction->Commit();
}
catch(...)
{
     
fPersona->Query->Transaction->Rollback();
     
cAux nItem != "el borrado" "la actualización";
     
Mensaje(1"Ha habido un error en " cAux " de los recibos pendientes.\r\nInténtelo de nuevo.""Volver");
     
FormCreate(NULL);
     return;

Todas las funciones, formularios y variables están definidas y funcionan a la perfección. Con ese código pueden montarse dos tipos de query:

Uno de actualización que quedaría así por ejemplo:
Código SQL [-]
UPDATE Emision SET Fecha = :Fecha, RefInt = :NewRef WHERE RefInt LIKE :RefInt

y otro de borrado que podría ser este:
Código SQL [-]
DELETE FROM Emision WHERE RefInt LIKE :RefInt

Los parámetros NewRef y RefInt se componen de un dígito del 1 al 4 y una fecha en formato yyyymmdd y en la tabla sobre la que se trabaja no puede haber dos campos RefInt que comiencen, por ejmplo, por 1 y tengan fechas distintas.

Si la variable dFecha toma el valor 15/02/2018 y ese Radiogroup1->ItemIndex valiera 0, los parámetros quedaría así:
  • Sólo para la actualización:
    Fecha = 15/02/2018
    NewRef = 120180215
  • Para ambos:
    RefInt = 1%
Pues con esos datos y tal cual está el código si ejecuto el programa no me hace nada (ni borra ni actualiza), pero si con el código tal cual se genera me voy a SQL Manager y lo pruebo hace exactamente lo que debiera. ¿Se os ocurre cuál puede ser la causa?
Responder Con Cita
  #2  
Antiguo 21-02-2018
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Posts: 1.350
Poder: 19
Angel.Matilla Va por buen camino
Angry

¡SOY TONTO! ¡MUY TONTO!

Ya he descubierto el fallo. En una de las llamadas ParamByName estaba llamandoa un query distinto del que estaba usando y por eso no funcionaba.
Responder Con Cita
  #3  
Antiguo 22-02-2018
cloayza cloayza is offline
Miembro
 
Registrado: may 2003
Ubicación: San Pedro de la Paz, Chile
Posts: 913
Poder: 22
cloayza Tiene un aura espectacularcloayza Tiene un aura espectacular
Estimado amigo, no se maltrate así...

No va ha ser el ultimo error que cometa.

Saludos
Responder Con Cita
  #4  
Antiguo 22-02-2018
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Posts: 1.350
Poder: 19
Angel.Matilla Va por buen camino
Muchas gracias, pero es que me enciende la sangre semejante tontería.
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
update o delete en external table hecospina Firebird e Interbase 10 08-03-2018 18:44:41
ClientDataSet: ver instruciones Insert, Update, Delete StartKill Providers 10 19-11-2015 08:45:45
update, insert, delete fibplus, ayuda!!! montesoft SQL 19 11-12-2012 00:53:55
Trigger Before (Insert,update,delete)? estebanx MS SQL Server 2 25-05-2006 15:58:19
Error con Update y Delete c748a SQL 4 15-06-2005 15:23:03


La franja horaria es GMT +2. Ahora son las 17:23:07.


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