Procedures¶
Procedures are custom pieces of AmiScript for consistently manipulating tables. They are a useful way to reuse code and make projects easier to maintain.
CREATE PROCEDURE¶
This command allows you to create stored procedures that can be called via AmiScript to execute a sequence of statements and return a value. Arguments can be supplied when calling the stored procedure (see CALL PROCEDURE):
procedure_name- name of the procedure to be created, each procedure's name must be unique within the database
Logging options:
off(default): No logging.on: Logs the time when the procedure is called and when it completes.verbose: Equivalent of using show_plan=ON in AMIDB. Logs the time that a timer starts and finishes and also each query step.
Example¶
In this example lets assume we have a table MyTable(id int,price double). We will make a simple procedure that inserts a row into that table and deletes any other rows with an equal or lesser price. (See CALL PROCEDURE clause for example of calling this procedure.)
CALL¶
This command allows you to execute stored procedures, typically declared using the CREATE PROCEDURE clause. When calling procedures, you must supply the appropriate arguments expected for the declared procedure.
Example¶
In this example, we will call the procedure declared in the CREATE PROCEDURE clause.
DROP PROCEDURE¶
Example¶
This example will drop the procedure MyProcedure from the database.
String Templating¶
String templating can be complex with procedures, this section will go through an example of how to use string templating. First let us create a simple table and add 4 values to it:
Running this select query:
Gives us the following table:
Now let's create a string and assign A to it:
Try running the following script:
This produces an error as string_template=off.
Let's set string_template=on. Note we find string_template under the setlocal command:
To set this to 'on' run the following:
Try running the following script again:
This will now output table A.
Let's roll back and set string_template=off. This time we will create the following PROCEDURE:
And then call the procedure as such:
List of System Procedures¶
This section will cover most of the procedures included in 3forge by default. However, the following procedures are covered in the Center Replication page:
-
__ADD_CENTER -
__REMOVE_CENTER -
__ADD_REPLICATION -
__REMOVE_REPLICATION
Add Datasource¶
__ADD_DATASOURCE(String name, String datasource_type, String url, String username, String password, String options, String relayId, String permittedOverrides)-
Add a datasource via AMIDB shell tool with the given properties:
name: Name of the datasource as displayed in the Data Modeler.datasource_type: adapter type, e.g: MYSQL, AMIDB, etc.url: Url of datasource.
The following arguments can be supplied optionally:
username: Username to access datasource if required.password: Password to access datasource if required.options: A comma-delimited list of datasource-specific options, e.g.DISABLE_BIGDEC=true,URL_OVERRIDE=jdbc:mysql://serverUrl:1234/databaseName.relayId: The name of the Relay to run on.-
permittedOverrides: Overridable values that can be called post-launch, e.g: to supply a password within a datamodel.- Valid options are:
"URL","USERNAME","PASSWORD","OPTIONS","RELAY"
Note
If you supply any optional parameters, you will need to supply
nullfor any other optional fields you are not using. - Valid options are:
Example¶
Supported Adapter Types¶
Name Alias (to be used in the procedure call) AMI datasource __AMISybase IQ JDBC SYBASE_IQShell Command SHELLAMIDB AMIDBMySQL JDBC MYSQLKDB KDBSSH Command SSHRedis RedisFred FREDSQLServer JDBC SQLSERVEROracle JDBC ORACLESybase JDBC SYBASERestAPI RESTAPIPostgres JDBC POSTGRESFlat File Reader FLAT_FILEGeneric JDBC GENERIC_JDBCIMB DB2 IMBDB2SQLITE JDBC SQLITEOneTick ONETICKQuandl QUANDL
Remove Datasource¶
__REMOVE_DATASOURCE(String datasourceName)-
Remove datasource by name.
datasourceName: Name of datasource to remove as visible in the Data Modeler.
Example¶
Reset Timer Stats¶
__RESET_TIMER_STATS(String timerName, Boolean executedStats, Boolean errorStats)-
Clears a given timer with the following properties:
timerName: Name of the timer .executedStats: Whether to clear the statsExecutedCount,MillisSpent, andAvgMillisSpent.errorStats: Whether to clear ErrorCounts.
Reset Trigger Stats¶
__RESET_TRIGGER_STATS(String triggerName)-
Clears a given trigger with the following properties:
-
triggerName: Name of the trigger.- This procedure will reset
ExecutedCount,MillisSpent,AvgMillisSpent,ErrorsCount,ReturnedFalseCountfor that trigger.
- This procedure will reset
-
Schedule Timer¶
__SCHEDULE_TIMER(String timerName, Long delayMillis)-
Schedules when a timer should run after a specified number of milliseconds.
timerName: Name of the timer to schedule.delayMillis: Time in milliseconds to wait before running the timer.
Example¶
Show Timer Error¶
__SHOW_TIMER_ERROR(String timerName)-
Shows the last error the timer encountered in a table format:
timerName: Name of the timer to show error for.
Example¶
Show Trigger Error¶
__SHOW_TRIGGER_ERROR(String triggerName)-
Shows the last error the trigger encountered in a table format:
timerName: Name of the trigger to show error for.
Example¶
Get Timezone¶
__GET_TIMEZONE()-
Gets the timezone of the 3forge session.
Example¶
Set Timezone¶
__SET_TIMEZONE(String timezone)-
Sets the timezone of the 3forge session.
timezone: Java-accepted timezone
Example¶





