Wednesday, December 20, 2017

Execute SQL in x++

server static void main(Args _args)
{
   Connection      connection;
    Statement       statement;
    str             query;
    Resultset       resultSet;
    Str1260         test = "delay";
    ;

    // create connection object
    connection = new Connection();

    // create statement
    statement = connection.createStatement();

    // Set the SQL statement
    query = "select recid from LANGUAGETXT where LANGUAGETXT.txt = '" + test +"'";

    // assert SQL statement execute permission
    new SqlStatementExecutePermission(query).assert();

    // when the query returns result,
    // loop all results for processing
    //BP Deviation documented
    resultSet = statement.executeQuery(query);

    while(resultSet.next())
    {
        // do something with the result
        info(strFmt("%1",resultSet.getInt64(1)));
    }

    // limit the scope of the assert call
    CodeAccessPermission::revertAssert();
}

No comments:

How to identify the user that was used to change an object from AOT in AX2012

Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...