Skip to content
Center

Methods

There are a number of AmiScript methods that can be called within the AMIDB shell tool and throughout the AMI platform to perform different actions.

They can be used in conjunction with Center objects, like triggers, procedures, and timers, to perform complex aggregations or calculations.

3forge also supports the ability for users to write their own custom methods for easy project reusability and maintainability.

SHOW METHODS

To view all available methods, use:

SHOW METHODS;

These will be returned in alphabetical order. To filter by user-defined methods, run the following command instead:

SHOW METHODS WHERE DefinedBy == "USER"

Note

Custom methods declared in the Web cannot be called within AMIDB. They are separate.

CREATE METHOD

To create a custom method, the syntax is as follows:

1
2
3
4
CREATE METHOD [IF NOT EXISTS] return_type method_name (data_type arg1, data_type arg2) {
    //code goes here;
    return result;
};

For example, to create a simple method (called foo) to return the sum of two numbers (of Integer type):

CREATE METHOD int foo (int a, int b) { return a + b; };

Altneratively, using the optional term IF NOT EXISTS to prevent overwriting an existing custom method is also valid:

CREATE METHOD IF NOT EXISTS int foo (int a, int b) { return a + b; };

This method can now be called/used inside of timers/procedures/triggers, e.g: for a procedure:

1
2
3
CREATE PROCEDURE myProcedure OFTYPE AMISCRIPT USE arguments="int a, int b" script="
int i = foo(a,b);
INSERT INTO table_name VALUES (i);";

Method Overloading

Like in Java, 3forge supports method overloading, which allows for methods with the same name but different parameters to be created.

For example, if we currently have int foo(int a, int b), which returns the sum of two Integers, we can overload the method to return the sum of two doubles as well, with:

CREATE METHOD double foo (double a, double b) { return a + b; };

3forge will auto-resolve the method to use based on the parameters used in the method call.

DROP METHOD

To drop the newly created method foo:

DROP METHOD foo(int a, int b);