Allows you to log errors and to record the actions selected by the handle_error script.
In the following table, the description provides the SQL data type. If you are writing your script in Java or .NET, you should use the appropriate corresponding data type. See SQL-Java data types and SQL-.NET data types.
In SQL scripts, you can specify event parameters by name or with a question mark. Using question marks has been deprecated and it is recommended that you use named parameters. You cannot mix names and question marks within a script. If you use question marks, the parameters must be in the order shown below and are optional only if no subsequent parameters are specified (for example, you must use parameter 1 if you want to use parameter 2). If you use named parameters, you can specify any subset of the parameters in any order.
Parameter name for SQL scripts | Description | Order (deprecated for SQL) |
---|---|---|
s.action_code |
INTEGER. This is an INOUT parameter. This parameter is mandatory. |
1 |
s.error_code |
INTEGER. The native DBMS error code. |
2 |
s.error_message |
TEXT. The native DBMS error message. |
3 |
s.remote_id | VARCHAR(128). The MobiLink remote ID. You can only reference the remote ID if you are using named parameters. | Not applicable |
s.username |
VARCHAR(128). The MobiLink user name. |
4 |
s.table |
VARCHAR(128). The table whose script caused the error. |
5 |
None.
This script allows you to log errors and to record the actions selected by the handle_error script. This script is executed after the handle_error event, whether a handle_error script is defined. It is always executed in its own transaction, on a different database connection than the synchronization connection (the administrative/information connection).
The MobiLink server always reports an error if the error is recoverable and the MobiLink server is planning to call the handle_error or handle_odbc_error script. For instance, if an error occurs when the MobiLink server is trying to upload an insert, the MobiLink server reports this error and calls the hande_error script. If the action returned from the handle_script is 1000, then the server ignores the error and continues the synchronization. However, if the MobiLink server detects an error before sending anything to the consolidated database, the server may not report the error because the error is not recoverable. More precisely, the MobiLink server reports the errors generated by the ODBC driver and the consolidated database.
The error code and error message allow you to identify the nature of the error. The action code value is returned by the last call to an error handling script for the SQL operation that caused the current error.
If the error happened as part of synchronization, the user name is supplied. Otherwise, this value is null.
If the error happened while manipulating a particular table, the table name is supplied. Otherwise, this value is null. The table name is the name of a table in the remote database. This name may or may not have a direct counterpart in the consolidated database, depending on how your remote table names map to consolidated database table names.
The following example works with a SQL Anywhere consolidated database. It inserts a row into a table used to record synchronization errors.
CALL ml_add_connection_script( 'ver1', 'report_error', 'INSERT INTO sync_error( action_code, error_code, error_message, user_name, table_name ) VALUES ( {ml s.action_code}, {ml s.error_code}, {ml s.error_message}, {ml s.username}, {ml s.table} )' ) |
The following call to a MobiLink system procedure registers a Java method called reportError as the script for the report_error connection event when synchronizing the script version ver1.
CALL ml_add_java_connection_script( 'ver1', 'report_error', 'ExamplePackage.ExampleClass.reportError' ) |
The following is the sample Java method reportError. It logs the error to a table using the JDBC connection provided by MobiLink. It also sets the action code.
package ExamplePackage; import java.sql.*; import ianywhere.ml.script.*; public class ExampleClass { DBConnectionContext _cc; public ExampleClass( DBConnectionContext cc ) { _cc = cc; } public void reportError( ianywhere.ml.script.InOutInteger actionCode, int errorCode, String errorMessage, String user, String table ) throws SQLException { actionCode.setValue( errorCode ); // Insert error information in a table, Connection conn = _cc.getConnection(); PreparedStatement stmt = conn.prepareStatement( "INSERT INTO sync_error( action_code, error_code, error_message, " + "user_name, table_name ) VALUES ( ?, ?, ?, ?, ? )" ); stmt.setInt( 1, actionCode.getValue() ); stmt.setInt( 2, errorCode ); stmt.setString( 3, errorMessage ); stmt.setString( 4, user ); stmt.setString( 5, table ); stmt.executeUpdate(); stmt.close(); } } |
The following call to a MobiLink system procedure registers a .NET method called ReportError as the script for the report_error connection event when synchronizing the script version ver1.
CALL ml_add_dnet_connection_script( 'ver1', 'report_error', 'TestScripts.Test.ReportError' ) |
The following is the sample .NET method ReportError. It logs the error to a table using a .NET method.
using System; using iAnywhere.MobiLink.Script; namespace TestScripts { public class Test { DBConnectionContext _cc; public Test( DBConnectionContext cc ) { _cc = cc; } public void ReportError( ref int actionCode, int errorCode, string errorMessage, string user, string table ) { actionCode = errorCode; DBConnection conn = _cc.GetConnection(); DBCommand cmd = conn.CreateCommand(); cmd.CommandText = "INSERT INTO sync_error( action_code, error_code, error_message, " + "user_name, table_name ) VALUES ( ?, ?, ?, ?, ? )"; cmd.Parameters[0] = actionCode; cmd.Parameters[1] = errorCode; cmd.Parameters[2] = errorMessage; cmd.Parameters[3] = user; cmd.Parameters[4] = table; cmd.ExecuteNonQuery(); } } } |
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |