Executed whenever the MobiLink server encounters an error triggered by the ODBC Driver Manager.
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, but 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 |
---|---|---|
s.action_code | INTEGER. This is an INOUT parameter. | 1 |
s.ODBC_state | VARCHAR(5) | 2 |
s.error_message | TEXT | 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) | 5 |
The MobiLink server selects a default action code. You can modify the action code in the script, and return a value instructing MobiLink how to proceed. The action code parameter takes one of the following values:
1000 Skip the current row and continue processing.
3000 Rollback the current transaction and cancel the current synchronization. This is the default action code, and is used when no handle_error script is defined or this script causes an error.
4000 Rollback the current transaction, cancel the synchronization, and shut down the MobiLink server.
The MobiLink server executes this script whenever it encounters an error flagged by the ODBC Driver Manager if the error occurs while MobiLink is processing an insert, update, or delete script during the upload transaction or is fetching download rows. If an ODBC error occurs at another time, the MobiLink server calls the report_error or report_ODBC_error script and aborts the synchronization.
The error codes allow you to identify the nature of the error.
The action code tells the MobiLink server what to do next. Before it calls this script, the MobiLink server sets the action code to a default value, which depends upon the severity of the error. Your script may modify this value. Your script must return or set an action code.
The handle_odbc_error script is called after the handle_error and report_error scripts, and before the report_odbc_error script.
When only one, but not both, error-handling script is defined, the return value from that script decides error behavior. When both error-handling scripts are defined, the MobiLink server uses the numerically highest action code. If both handle_error and handle_ODBC_error are defined, MobiLink uses the action code with the highest numerical value returned from all calls.
The following example works with a SQL Anywhere consolidated database. It allows your application to ignore ODBC integrity constraint violations.
The following call to a MobiLink system procedure assigns the HandleODBCError stored procedure to the handle_odbc_error event.
CALL ml_add_connection_script( 'ver1', 'handle_odbc_error', 'CALL HandleODBCError( {ml s.action_code}, {ml s.ODBC_state}, {ml s.error_message}, {ml s.username}, {ml s.table} )' ) |
The following SQL statement creates the HandleODBCError stored procedure.
CREATE PROCEDURE HandleODBCError( INOUT action integer, IN odbc_state varchar(5), IN error_message varchar(1000), IN user_name varchar(128), IN table_name varchar(128) ) BEGIN IF odbc_state = '23000' then -- Ignore the error and keep going. SET action = 1000; ELSE -- Abort the synchronization. SET action = 3000; END IF; END |
The following call to a MobiLink system procedure registers a Java method called handleODBCError as the script for the handle_odbc_error event when synchronizing the script version ver1.
CALL ml_add_java_connection_script( 'ver1', 'handle_odbc_error', 'ExamplePackage.ExampleClass.handleODBCError' ) |
Following is the sample Java method handleODBCError. It processes an error based on the data that is passed in. It also determines the resulting error code.
public String handleODBCError( ianywhere.ml.script.InOutInteger actionCode, String ODBCState, String errorMessage, String user, String table ) { int newAC; if( user == null ) { newAC = handleNonSyncError( ODBCState, errorMessage ); } else if( table == null ) { newAC = handleConnectionError( ODBCState, errorMessage, user ); } else { newAC = handleTableError( ODBCState, errorMessage, user, table ); } // Keep the most serious action code. if( actionCode.getValue() < newAC ) { actionCode.setValue( newAC ); } return( null ); } |
The following call to a MobiLink system procedure registers a .NET method called HandleODBCError as the script for the handle_odbc_event when synchronizing the script version ver1.
CALL ml_add_dnet_connection_script( 'ver1', 'handle_odbc_error', 'TestScripts.Test.HandleODBCError' ) |
Following is the sample .NET method HandleODBCError.
public string HandleODBCError ( ref int actionCode, string ODBCState, string errorMessage, string user, string table ) { int new_ac; if( user == null ) { new_ac = HandleNonSyncError( ODBCState, errorMessage ); } else if( table == null ) { new_ac = HandleConnectionError( ODBCState, errorMessage, user ); } else { new_ac = HandleTableError( ODBCState, errorMessage, user, table ); } // Keep the most serious action code. if( actionCode < new_ac ) { actionCode = new_ac; } return( null ); } |
Send feedback about this page via email or DocCommentXchange | Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0 |