Open topic with navigation

TIBCO BusinessEvents® Enterprise Edition 6.3.1

# Simple Snapshot Query Example

The snapshot query example code could be placed in a preprocessor rule function that receives an event called `requestEvent`. The example code includes all steps from creating to closing the query.

The example is simplified for clarity. In a real-world use case, the creation step could be performed in a startup rule function, and the output could be sent in an event to an inference agent or other destination.

    Query.create("report853", "select agent_name, total_sales, zipcode from /Concepts/Sales");
    String id = requestEvent@extId;
    String stmt = "S" + id;
    String rset = "R" + id;
    Query.Statement.open("report853", stmt);
    Query.Statement.execute(stmt, rset);
    while(Query.ResultSet.next(rset)) {
        String agent = Query.ResultSet.get(rset, 0);
        double sales = Query.ResultSet.get(rset, 1);
        String zip = Query.ResultSet.get(rset, 2);
        System.debugOut(rset + ": Agent " + agent
            + " sold $" + sales
            + " in " + zip
            + ".");
    }
    System.debugOut(rset + ": ========");
    Query.ResultSet.close(rset);
    Query.Statement.close(stmt);
    Query.Close("report853");

The last three lines are provided for completeness. However, if the `Query.Close()` function is used, you would not need to include the `Query.ResultSet.close()` or `Query.Statement.close()` functions. See Statement Closing and Query Definition Deletion for details about these hierarchical relationships.

## Sample Output

    R123: Agent Mary Smith sold $15063.28 in 94304.
    R123: Agent Robert Jones sold $14983.05 in 94304.
    R123: ========

Did you find this helpful?

YesNo
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO BusinessEvents® Enterprise Edition

Copyright © 2004-2024. Cloud Software Group, Inc. All Rights Reserved.