Einzelnen Beitrag anzeigen

Ykcim

Registriert seit: 29. Dez 2006
Ort: NRW
824 Beiträge
 
Delphi 10.4 Sydney
 
#4

AW: Manipulation eines Records in einer FDQuery

  Alt 15. Jun 2023, 12:32
Hallo Zusammen,

vielen Dank für Eure Gedanken. Wenn ich die Daten ohne Manipulation ziehe und an die Clients übergebe, funktioniert das wunderbar. Leider sind die Daten aber in der Datenbank nicht korrekt, worauf ich keinen Einfluss habe. Daher ist es erforderlich die korrekten Daten aus der anderen Datenbank zu holen.

Ich habe mal JOB_NAME in JOB_NAME1 umbenannt:
Delphi-Quellcode:
 MsQuery.SQL.Add('SELECT TOP 1 '+
                                'CASE WHEN ( '+
                                  'concat(rj.JOB_ID, ' + QuotedStr(' ') + ', JOB_NAME) is NULL) then '+
                                  'LAG(Concat(rj.JOB_ID, ' + QuotedStr(' ') + ', rj.JOB_NAME)) OVER (ORDER BY re.TIME_LOCAL DESC) ELSE '+
                                  'concat(rj.JOB_ID, ' + QuotedStr(' ') + ',rj.JOB_NAME) end AS JOB_NAME1, '+
                                'CONVERT( varchar( 10 ), re.Time_Local, 104 ) AS Datum, '+
Dann bekomme ich die gleiche Fehlermeldung beim Post.

Ich hatte ja auch schon getestet, ob die Fehlermeldung ausbleibt, wenn ich ein echtes Feld verwende (OPERATION_NAME). Aber das klappt auch nicht.

Wie gesagt, ohne die Manipulation klappt das wunderbar und derzeit nutze ich die Software auch so, aber es arbeiten manchmal die falschen Mitarbeiter gerade an den Maschinen.

Hat jemand eine Idee, warum mit dem Post ein Problem auftritt?

Vielleicht verwende ich die FDQuery falsch, denn diese habe ich ohne Felder angelegt, sondern lasse die mit dem Open anlegen...

Hier mal die ganze Procedure...
Delphi-Quellcode:
procedure TMxSQL.Get_act_MachineData(Machine_ID: string; LStream: TStream; RefreshData, SendData: boolean);
var Logic: TLogic;
      MsQuery: TFDQuery;
      CDMQuery: TFDQuery;
      Operationslist: string;
begin
   if (RefreshData = false) and (DB_Modul.Tmr_LM_RefreshData.Enabled = false) and (SendData = true) then begin
      RefreshData := true;
      DB_Modul.Tmr_LM_RefreshData.Enabled := true;
      DB_Modul.FLM_OfflineState := 0;
      DB_Modul.Write_LM_Protokoll('RefreshTimer aktiviert.');
   end;

   if (RefreshData = false) and (DB_Modul.Tmr_LM_RefreshData.Enabled = true) and (SendData = true) then begin
      DB_Modul.Tmr_LM_RefreshData.Enabled := true;
      DB_Modul.FLM_OfflineState := 0;
      DB_Modul.Write_LM_Protokoll('OfflineState-Counter zurückgesetzt.');
   end;
   if (DB_Modul.Tmr_LM_RefreshData.Enabled = false) then begin
      DB_Modul.Tmr_LM_RefreshData.Enabled := true;
      DB_Modul.FLM_OfflineState := 0;
      DB_Modul.Write_LM_Protokoll('RefreshTimer aktiviert. OfflineState-Counter zurückgesetzt.');
   end;
   Logic := TLogic.create;
   MsQuery := TFDQuery(DB_Modul.FindComponent('Qry_LM_' + Machine_ID));
   Logic.Set_Query(CDMQuery, DB_Modul.PRINECT_CDM);
   try
      if (RefreshData = true) then begin
         MsQuery.Connection:=DB_Modul.PRINECT_APS;
         MsQuery.SQL.Clear;
         MsQuery.FetchOptions.AutoFetchAll;
         MsQuery.FetchOptions.Mode := fmAll;
         OperationsList := DB_Modul.Read_Einstellungswert('Life_Data_OperationList');
         MsQuery.SQL.Add('SELECT TOP 1 '+
                                'CASE WHEN ( '+
                                  'concat(rj.JOB_ID, ' + QuotedStr(' ') + ', JOB_NAME) is NULL) then '+
                                  'LAG(Concat(rj.JOB_ID, ' + QuotedStr(' ') + ', rj.JOB_NAME)) OVER (ORDER BY re.TIME_LOCAL DESC) ELSE '+
                                  'concat(rj.JOB_ID, ' + QuotedStr(' ') + ',rj.JOB_NAME) end AS JOB_NAME, '+
                                'CONVERT( varchar( 10 ), re.Time_Local, 104 ) AS Datum, '+
                                'convert(char(5), re.Time_Local, 108) AS Startzeit, '+
                                'rd.device_id, '+
                                'rd.device_name, '+
                                'ro.OPERATION_NAME, '+
                                'concat(ry.FIRST_NAME,' +QuotedStr(' ') + ', ry.FAMILY_NAME) AS Operator, '+
                                'CASE WHEN ( '+
                                  'DateDiff(minute, re.Time_Local, LAG(re.Time_Local) OVER (ORDER BY re.TIME_LOCAL DESC)) is NULL) then '+
                                  'Concat(DateDiff(minute, re.Time_Local, GETDATE()),' + QuotedStr(':00 (') + ',convert(char(5), re.Time_Local, 108), ' + QuotedStr(')') + ') ELSE '+
                                  'ConCat(DateDiff(minute, re.Time_Local, LAG(re.Time_Local) OVER (ORDER BY re.TIME_LOCAL DESC)),' + QuotedStr(':00 (') + ',convert(char(5), re.Time_Local, 108), ' + QuotedStr(')') + ') end AS Dauer, '+
                                '(SELECT SPEED FROM RBC_DEVICE_BASIC_INTERVALS RDB WHERE RDB.DEVICE_BASIC_INTERVAL_KEY = '+
                                  '(SELECT MAX(Device_Basic_interval_key) FROM RBC_DEVICE_BASIC_INTERVALS RDBI WHERE RDBI.DEVICE_KEY = re.DEVICE_KEY)) AS Speed, '+
                                'Concat(ws.PERCENT_COMPLETED,' + QuotedStr(' %') + ') AS PERCENT_COMPLETED, '+
                                'ws.PLANNED_GOOD_AMOUNT, '+
                                'ws.GOOD_CYCLES, '+
                                'ro.OPERATION_KEY, '+
                                'ws.WORK_STEP_NAME '+
                         'from RPS_EVENTS re '+
                         'LEFT JOIN RPS_WORK_STEPS ws ON ws.WORK_STEP_KEY = re.WORK_STEP_KEY '+
                         'LEFT JOIN RPS_JOBS rj ON rj.JOB_KEY = ws.JOB_KEY '+
                         'LEFT JOIN RPS_EMPLOYEE_ACTIVITIES ea ON ea.WORK_STEP_KEY = ws.WORK_STEP_KEY '+
                         'LEFT JOIN RPS_OPERATIONS ro ON ro.OPERATION_KEY = re.OPERATION_KEY '+
                         'LEFT JOIN RBC_DEVICES rd ON rd.device_key = re.device_key '+
                         'LEFT JOIN RBC_EMPLOYEES ry ON ry.EMPLOYEE_KEY = ea.EMPLOYEE_KEY '+
                         'WHERE rd.DEVICE_ID = :Device_ID '+
                         'AND CONVERT( date, re.TIME_LOCAL) = CONVERT( date, GETDATE()) '+
                         'AND re.OPERATION_KEY IN ( ' + OperationsList + ' ) '+
                         'GROUP BY rj.JOB_NAME, '+
                                  'rj.job_id, '+
                                  're.Time_Local, '+
                                  're.Device_key, '+
                                  'rd.device_id, '+
                                  'rd.device_name, '+
                                  're.OPERATION_KEY, '+
                                  'ro.OPERATION_KEY, '+
                                  'ro.OPERATION_NAME, '+
                                  'ry.FIRST_NAME, '+
                                  'ry.FAMILY_NAME, '+
                                  'ws.PERCENT_COMPLETED, '+
                                  'ws.PLANNED_GOOD_AMOUNT, '+
                                  'ws.GOOD_CYCLES, '+
                                  'ws.WORK_STEP_NAME '+
                         'ORDER BY re.TIME_LOCAL desc ');
         MsQuery.ParamByName('Device_ID').AsString := Machine_ID;
         MsQuery.Open;
         DB_Modul.Write_LM_Protokoll('Refresh Daten Maschine ' + Machine_ID);


         CDMQuery.SQL.Clear; //Ohne den nachfolgenden Teil bis zum Post klappt alles wunderbar. Felder und Werte sind da.
         CDMQuery.sql.Add('select * from CDM_SM_DEVICE_OP_STATUS '+
                          'where deviceID = :Device '+
                          'and roleID = ' + QuotedStr('ID_Operator'));
         CDMQuery.ParamByName('Device').AsString := MsQuery.FieldByName('device_id').AsString;
         CDMQuery.Open;

         CDMQuery.First;
         MsQuery.First;
         MsQuery.Edit;
         MsQuery.FieldByName('Operator').AsString := CDMQuery.FieldByName('userID').AsString;
         MsQuery.Post; //Hier knallt es
      end;



      if SendData then begin
         if Assigned(LStream) then begin
            if MsQuery.State = dsInactive then begin
               DB_Modul.Write_LM_Protokoll('Query('+Machine_ID+') ist inaktiv. Wartezeit 2 Sek.');
               Sleep(2000);
            end;
            if MsQuery.State = dsBrowse then begin
               MsQuery.SaveToStream(LStream, sfJSON);
               DB_Modul.Write_LM_Protokoll('Sent Daten ('+Machine_ID+') LifeMonitor.');
            end
            else begin
               DB_Modul.Write_LM_Protokoll('ERROR: Query nicht aktiv ('+Machine_ID+').');
            end;
         end
         else begin
            DB_Modul.Write_LM_Protokoll('ERROR: No Stream assigned ('+Machine_ID+').');
         end;
      end;
   Finally
      Logic.Free;
      CDMQuery.Free;
   end;
end;
Vielen Dank
Patrick
Patrick

Geändert von Ykcim (15. Jun 2023 um 12:35 Uhr)
  Mit Zitat antworten Zitat