Hello, please help my
I used multiple plctagnumber, I get the data perfectly, but I have to write it to the database from one insert, how to combine the data into one request
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't know about your database structure. If you use the three collumn model (datetime,varID,Value) you can use a single insert with a list of values. Example:
Note that FormatFloat will format the number as string using the regional system settings. So if you has (like I have here in Brazil) the comma as decimal separator, you should create a function that replaces temporary the decimal separator by dot, format the number and restore the old decimal separator point. Here an example?
function FormatSQLNumber(aValue:Double):String;
var
oldDecSeparator: Char;
begin
try
oldDecSeparator:=FormatSettings.DecimalSeparator;
FormatSettings.DecimalSeparator:='.';
Result:=FormatFloat('#0.00000',aValue);
finally
FormatSettings.DecimalSeparator := oldDecSeparator;
end;
end;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello, please help my
I used multiple plctagnumber, I get the data perfectly, but I have to write it to the database from one insert, how to combine the data into one request
I don't know about your database structure. If you use the three collumn model (datetime,varID,Value) you can use a single insert with a list of values. Example:
'INSERT INTO table(datetime,varID,Value) VALUES (''2020-03-03 00:00:00'', ''Tag1'','+FormatFloat('#0.000', Tag1.Value)+'), (''2020-03-03 00:00:00'', ''Tag2'','+FormatFloat('#0.000', Tag2.Value)+'),(''2020-03-03 00:00:00'', ''Tag3'','+FormatFloat('#0.000', Tag3.Value)+')';
If you have a table that has one collumn for each tag it's more simple SQL statement:
'INSERT INTO table(datetime, Tag1, Tag2, Tag3) VALUES (''2020-03-03 00:00:00'','+FormatFloat('#0.000', Tag1.Value)+','+FormatFloat('#0.000', Tag2.Value)','+FormatFloat('#0.000', Tag3.Value)+')';
Note that FormatFloat will format the number as string using the regional system settings. So if you has (like I have here in Brazil) the comma as decimal separator, you should create a function that replaces temporary the decimal separator by dot, format the number and restore the old decimal separator point. Here an example?
function FormatSQLNumber(aValue:Double):String;
var
oldDecSeparator: Char;
begin
try
oldDecSeparator:=FormatSettings.DecimalSeparator;
FormatSettings.DecimalSeparator:='.';
Result:=FormatFloat('#0.00000',aValue);
finally
FormatSettings.DecimalSeparator := oldDecSeparator;
end;
end;
The best part is that the sourceforge cuts off my code identation
if you has Telegram, join to PascalSCADA group
https://t.me/pascalscada
Thank you Fabio,
but, "'INSERT INTO table (datetime, varID, Value) VALUES (' '2020-03-03 00:00:00' ',' 'Tag1' ',' + FormatFloat ('# 0.000', Tag1.Value) + ') , ('' 2020-03-03 00:00:00 '', '' Tag2 '', '+ FormatFloat (' # 0.000 ', Tag2.Value) +'), ('' 2020-03-03 00: 00:00 '', '' Tag3 '', '+ FormatFloat (' # 0.000 ', Tag3.Value) +') ';" where insert this insert command? plctagnumber1.onupdate? or plctagnumber2.onupdate? how can i combine the values of a few pls