SQL Query of a Value with Timestamp

Created by Vester Business Support Team, Modified on Thu, 5 Nov, 2020 at 10:15 PM by Vester Business Support Team

// First define the ODBC connection in Windows


var odbcClient = new ODBCClient();


//------------details via http://www.connectionstrings.com/ .----------------------------------------------


odbcClient.source = "DSN=MySQL_ODBC; Uid=root; Pwd=DundasB1;"; // DNS, user and password of your database


if (odbcClient.open()) {    

//console.log ("ODBC Opend:", odbcClient.info());            //.info -> information of connected datasource


    try

    {

        var querytag = tagquery // define the Node we want to use to read the Query String from.

        var query = odbcClient.query(tagquery); // SQL query to bring the desired value from your database

        var value = []; //Create an array variable

        value.push(query[0][0]);//define las 2 partes del array y=0 x=0        

        //console.log("value is " +value);

        var timestamp = []; //Create an array variable

        timestamp.push(query[0][1]);//extract the second part of the array        

        //console.log("timestamp is " +timestamp);

            

        

                

        var node = new UaNode("AGENT.OBJECTS.Database_ARF.ValorResultado"); // Define the node that we want to assign the query result

        node.assign({value: value, sourcetime:new Date(timestamp)}); // Assign the query result to the node value

        //console.log(error);

                

        return(value);

        odbcClient.close();

    }

    catch (exp)

    {

        console.log(exp);

        if (exp.indexOf('No Data') > -1)

            return 0; // ok

            

        return undefined;

    }

    finally

    {

        if (odbcClient && odbcClient.opened == true)

            odbcClient.close();

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article