Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Conexión con bases de datos (https://www.clubdelphi.com/foros/forumdisplay.php?f=2)
-   -   clientdataset error No key specified (https://www.clubdelphi.com/foros/showthread.php?t=65498)

ehdez82 19-12-2009 21:22:19

clientdataset error No key specified
 
Hola tengo un CDS con un ADODataSet detrás que tiene la siguiente consulta:

Código SQL [-]SELECT `embalaje_item`.* FROM `embalaje_item` WHERE `embalaje_item`.`embalajeId` = :id_Embalaje AND `embalaje_item`.`ventaId` = :id_Venta;


En esta tabla el campo llave es "idEmbalajeItem". En el CDS le tengo activado en el ProviderFlags la marca pfInKey. Sin embargo me arroja un error de "Unable to find record. No key specified".

Específicamente falla porque en el método UseFieldInWhere no encuentra el valor en la línea seleccionada. Al no poder incluir ningún campo el método: Provider.TSQLResolver.GenWhereSQL($1C509E0,$1C2FF90,$1B341C8,upWhereKeyOnly,'') lanza un error de SNoKeySpecified.

Código:

function TSQLResolver.UseFieldInWhere(Field: TField; Mode: TUpdateMode): Boolean;
const
  ExcludedTypes = [ftDataSet, ftADT, ftArray, ftReference, ftCursor, ftUnknown];
begin
  with Field do
  begin
    Result := not (DataType in ExcludedTypes) and not IsBlob and
      (FieldKind = fkData) and (Tag <> tagSERVERCALC);
    if Result then
      case Mode of
        upWhereAll:
          Result := pfInWhere in ProviderFlags;
        upWhereChanged:
          Result := ((pfInWhere in ProviderFlags) and not VarIsClear(NewValue)) or
            (pfInKey in ProviderFlags);
        upWhereKeyOnly:
          Result := pfInKey in ProviderFlags;
      end;
  end;
end;

Alguna idea de como puede perder el valor pfInKey. He probado ponerlo por código pero nada. Los datos se refrescan con el siguiente código:


Código:

with dm_Ventas.ds_VentaItems do
    begin
      Parameters.ParamByName('id_Embalaje').Value := IntToStr(id_Embalaje);
      Parameters.ParamByName('id_Venta').Value := '0';
      Active:= False;
      Active:= True;
    end;
    dm_Ventas.cds_VentaItems.Refresh;

¿Es posible que cerrar y abrir el dataset provoque la perdida del valor pfInKey?

Gracias de antemano.
salu2.

ehdez82 19-12-2009 21:26:17

Había seleccionado la línea en el método UseFieldInWhere pero no se ve. Disculpen. Me refería a:

upWhereKeyOnly:
Result := pfInKey in ProviderFlags;

Gracias.
salu2.

ehdez82 21-12-2009 17:03:30

He probado un montón de configuraciones y nada. Puse la siguiente comprobación:

Código:

if pfInKey in cds_VentaItemsidEmbalajeItem.ProviderFlags then
    ShowMessage('idEmbalajeItem es llave');
  cds_VentaItems.ApplyUpdates(-1);

y se cumple la condición. Es decir antes de dar ApplyUpdate el campo tiene el valor pfInKey.

Ahora si no entiendo nada.
Por favor cualquier idea de donde puede estar el problema.

Gracias de antemano.
salu2.

ehdez82 21-12-2009 17:24:32

Solucionado el problema. Implementé el evento onUdUpdateData como sigue:

Código:

procedure TForm1.dsp_VentaItemsUpdateData(Sender: TObject;
  DataSet: TCustomClientDataSet);
begin
  with DataSet do
  begin
    FieldByName('idEmbalajeItem').ProviderFlags := [pfInWhere, pfInUpdate, pfInKey];
    FieldByName('ventaId').ProviderFlags := [pfInWhere, pfInUpdate];
    FieldByName('pcPrecio').ProviderFlags := [pfInWhere, pfInUpdate];
    FieldByName('precioVenta').ProviderFlags := [pfInWhere, pfInUpdate];
  end;
end;

Todavía no entiendo la necesidad de esta implementación pero ya funciona. ¿Por qué tener que especificar el ProviderFlags en este evento si ya está configurado en el CDS?
Si alguien pudiera aclararme más.

Gracias de antemano.
salu2.


La franja horaria es GMT +2. Ahora son las 04:06:55.

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