Executed whenever the MobiLink server encounters an ODBC error while invoking a data 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. Set this value to tell the MobiLink server how to respond to the error. | 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 name. | 5 |
The MobiLink server selects a default action. You can modify the action 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' ) |
The 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.
package ExamplePackage; public class ExampleClass { public void handleODBCError( ianywhere.ml.script.InOutInteger actionCode, String oDBCState, String errorMessage, String user, String table ) { if( oDBCState == "23000" ) { // Ignore the error and keep going. actionCode.setValue( 1000 ); } else { // Abort the synchronization. actionCode.setValue( 3000 ); } } } |
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' ) |
The following is the sample .NET method HandleODBCError.
namespace TestScripts { public class Test { public void HandleODBCError( ref int actionCode, string oDBCState, string errorMessage, string user, string table ) { if( oDBCState == "23000" ) { // Ignore the error and keep going. actionCode = 1000; } else { // Abort the synchronization. actionCode = 3000; } } } } |
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |