Allows you to log errors and to record the actions selected by the handle_odbc_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.odbc_state |
VARCHAR(5). The ODBC SQLSTATE. |
2 |
s.error_message |
TEXT. The ODBC 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_odbc_error script. This script is executed after the handle_odbc_error event, whether or not a handle_odbc_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 ODBC state 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_odbc_error', 'INSERT INTO sync_error( action_code, odbc_state, error_message, user_name, table_name ) VALUES( {ml s.action_code}, {ml s.odbc_state}, {ml s.error_message}, {ml s.username}, {ml s.table} )' ) |
The following call to a MobiLink system procedure registers a Java method called reportODBCError as the script for the report_odbc_error event when synchronizing the script version ver1.
CALL ml_add_java_connection_script( 'ver1', 'report_odbc_error', 'ExamplePackage.ExampleClass.reportODBCError' ) |
The following is the sample Java method reportODBCError. 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 reportODBCError( InOutInteger actionCode, String odbcState, String odbcMessage, String user, String table ) throws SQLException { // Insert error information in a table, Connection conn = _cc.getConnection(); PreparedStatement stmt = conn.prepareStatement( "INSERT INTO sync_error( action_code, odbc_state, error_message, " + "user_name, table_name ) VALUES ( ?, ?, ?, ?, ? )" ); stmt.setInt( 1, actionCode.getValue() ); stmt.setString( 2, odbcState ); stmt.setString( 3, odbcMessage ); 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 ReportODBCError as the script for the report_odbc_error event when synchronizing the script version ver1.
CALL ml_add_dnet_connection_script( 'ver1', 'report_odbc_error', 'TestScripts.Test.ReportODBCError' ) |
The following is the sample .NET method ReportODBCError. 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, string odbcState, string errorMessage, string user, string table ) { DBConnection conn = _cc.GetConnection(); DBCommand cmd = conn.CreateCommand(); cmd.CommandText = "INSERT INTO sync_error( action_code, odbc_state, error_message, " + "user_name, table_name ) VALUES ( ?, ?, ?, ?, ? )"; cmd.Parameters[0] = actionCode; cmd.Parameters[1] = odbcState; 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 |