Menu

Many plctagnumber and database

Help
ambako
2020-03-03
2020-03-04
  • ambako

    ambako - 2020-03-03

    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

     
  • Fabio Luis Girardi

    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;

     
  • Fabio Luis Girardi

    The best part is that the sourceforge cuts off my code identation

     
  • Fabio Luis Girardi

    if you has Telegram, join to PascalSCADA group

    https://t.me/pascalscada

     
  • ambako

    ambako - 2020-03-04

    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

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.