Delphi-PRAXiS
Seite 2 von 4     12 34      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Datenbanken (https://www.delphipraxis.net/15-datenbanken/)
-   -   Delphi SQL problem (https://www.delphipraxis.net/144409-sql-problem.html)

nanix 7. Dez 2009 14:42

Re: SQL problem
 
Sorry was a little typo which happens if you type faast! :)

But now no updated records :(

Delphi-Quellcode:
Item:=false;
end
else begin
ABSQuery1.SQL.Clear;
ABSQuery1.SQL.Text := 'UPDATE Sensors SET Field="' +sField+'"' +','+'Value="'+sValue+'"'+','+'Min="'+sMin+'"'+','+'Max="'+sMax+'"'+' WHERE HWM_ID = :HWM_ID and Sensor_Class = :Sensor_Class and Sensor_ID = :Sensor_ID';






for hwm_index := 0 to NBMonitors - 1 do

for sensor_index := 0 to CPUIDSDK_GetNumberOfSensors(hwm_index, SENSOR_CLASS_VOLTAGE) - 1 do begin
if CPUIDSDK_GetSensorInfos(hwm_index,
sensor_index,
SENSOR_CLASS_VOLTAGE,
ptrName,
iValue,
Value,
Min,
Max)
then begin
ABSQuery1.ParamByName('HWM_ID').AsString:=inttostr(hwm_index);
ABSQuery1.ParamByName('Sensor_Class').AsString:=inttostr(SENSOR_CLASS_VOLTAGE);
ABSQuery1.ParamByName('Sensor_ID').AsString:=inttostr(sensor_index);

sField:=pansichar(ptrname);
sValue:=Format('%.3f V', [Value]);
sMin:=Format('%.3f V', [Min]);
sMax:=Format('%.3f V', [Max]);

ABSQuery1.ExecSQL;


end;
end;
end;

ToFaceTeKilla 7. Dez 2009 14:50

Re: SQL problem
 
What are :Sensor_Class, :HWM_ID, :Sensor_ID? Are these Delphi-Variables? Then you must quote and add them (if they are strings! otherwise you must convert them to string!)
Delphi-Quellcode:
'...WHERE (HWM_ID = '+:HWM_ID+') and (Sensor_Class = '+:Sensor_Class+') and (Sensor_ID ='+ :Sensor_ID+')';
And put brackets () around every logical statement!

edit: rubbish

nanix 7. Dez 2009 14:52

Re: SQL problem
 
I thought with parameters is good?

delphi variables are
Delphi-Quellcode:
var
sField,sMax,sMin,sValue:String;
begin

mkinzler 7. Dez 2009 14:54

Re: SQL problem
 
Zitat:

And put brackets () around every logical statement!
And why? Just makes statement less readable

Zitat:

What are :Sensor_Class, :HWM_ID, :Sensor_ID? Are these Delphi-Variables? Then you must quote and add them (if they are strings! otherwise you must convert them to string!)
No this are Parameters. Type is automatically set by dbms.

ToFaceTeKilla 7. Dez 2009 14:58

Re: SQL problem
 
Oh :oops: my fault. Just overlooked the whole parameter thing... Then move on Mr ;-) I don't know, how to address the parameters here.

Ok, brackets arent necessary. Just a habit of me oO

nanix 7. Dez 2009 14:59

Re: SQL problem
 
Yes setting long SQL texts is trouble for most 3rd party databases..

mkinzler 7. Dez 2009 15:02

Re: SQL problem
 
Ist just oen reason for parameters. But the main reasons are type-conversion, type formats (e.g. date values) and the performance boost of using prepared statements for mass import/updates etc.

nanix 7. Dez 2009 15:04

Re: SQL problem
 
I don't understand why it won't update Records :wall:

Edit:
Delphi-Quellcode:
Edit1.Text:=ABSQuery1.SQL.Text;
Edit1 reports this

SQL-Code:
UPDATE Sensors SET Field="",Value="",Min="",Max="" WHERE HWM_ID = :HWM_ID and Sensor_Class = :Sensor_Class and Sensor_ID = :Sensor_ID

mkinzler 7. Dez 2009 15:08

Re: SQL problem
 
Is an error shown or just nothing happens?

ToFaceTeKilla 7. Dez 2009 15:08

Re: SQL problem
 
Does the code compile? Do you get any error messages or arent there just any updated records?

If it runs and there are just no records updated then set breakpoints and step through your code. Maybe one of the functions (CPUIDSDK_GetNumberOfSensors or CPUIDSDK_GetSensorInfos) returns a wrong value?


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:43 Uhr.
Seite 2 von 4     12 34      

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz