Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 17 » MobiLink - Server Administration » MobiLink events » Synchronization events » Overview of MobiLink events

Events during upload

The following pseudocode illustrates how upload events and upload scripts are invoked.

The pseudocode uses the following conventions:

  • A script is defined as a real script

    This means the script is defined as a real script that will be executed against the consolidated database during synchronization.

  • A script is defined as an ignored script

    This means the script is defined as an ignored script using "--{ml_ignore}".

  • A script is defined

    This means the script is defined as a real or an ignored script.

  • A script is not defined

    This means there is no script defined for the event at all. You must define it as an ignored script if it is a required script, but you do not want to use that script.

These events take place at the upload location in the complete event model.

Overview of the upload
------------------------------------------------------
upload
------------------------------------------------------

begin_upload // Connection event
for each table being synchronized {
    begin_upload // Table event
}
handle_UploadData
for each table being synchronized {
    begin_upload_rows
    for each uploaded INSERT or UPDATE for this table {
	if( INSERT ) {
	    <upload_inserted_row>
	}
	if( UPDATE ) {
	    <upload_updated_row>
	}
    }
    end_upload_rows
}
for each table being synchronized IN REVERSE ORDER {
    begin_upload_deletes
    for each uploaded DELETE for this table {
	<upload_deleted_row>
    }
    end_upload_deletes
}
For each table being synchronized {
    if( begin_upload table script was processed ) {
	end_upload // Table event
    }
}
if( begin_upload connection script was processed ) {
    end_upload // Connection event
}
for each table being synchronized {
    upload_statistics  // Table event.
}
upload_statistics  // Connection event.

COMMIT
Upload inserts
------------------------------------------------------
<upload_inserted_row>
------------------------------------------------------
// NOTES:
// - Only table scripts for the current table are involved.

if( upload_insert script is real ) {
    upload_insert
} else if( handle_uploadData script is real or
    upload_insert script is defined as an ignored script ) {
    // Ignore the insert. (Only ignored in SQL, possibly handled by handle_uploadData.)
} else {
    error
}
Upload updates
------------------------------------------------------
upload_updated_row
------------------------------------------------------
// NOTES:
// - Only table scripts for the current table are involved.
// - Both the old (original) and new rows are uploaded for
//   each update.

ConflictsAreExpected <- (
    upload_new_row_insert script is defined or
    upload_old_row_insert script is defined )
Conflicted <- FALSE

if( upload_update script is real ) {
    if( upload_fetch or upload_fetch_column_conflict script is real ) {
        if( ConflictsAreExpected ) {
            FETCH using upload_fetch INTO current_row
            if( current_row <> old row ) {
                Conflicted <- TRUE
            } else {
                upload_update
            }
        } else {
            error
        } 
    } else if( upload_fetch and upload_fetch_column_conflict scripts are not defined ) {
        if( ConflictsAreExpected ) {
	    error
        } else {
            // No conflict detection and resolution by the MobiLink server
            // The upload_update script should handle conflict detection and resolution
            upload_update
        }
    } else {
	// the upload_fetch script cannot defined as an ignored script
	error
    } 
} else if( handle_uploadData script is defined or upload_update script is defined as an ignored script ) {
    // Ignore the upload update (Only ignored in SQL, possibly handled by handle_uploadData.)
} else {
    error
}
if( Conflicted ) {
    if( upload_old_row_insert script is real ) {
        upload_old_row_insert
    } else if( upload_old_row_insert script is defined as ignored script ) {
        // Ignore the old value
    } else {
        error
    }
    if( upload_new_row_insert script is real ) {
        upload_new_row_insert
    } else if( upload_new_row_insert script is defined as ignored script ) {
        // Ignore the new value
    } else {
        error
    }
    if( no error ) {
        resolve_conflict
    }
}
Upload deletes
------------------------------------------------------
upload_deleted_row
------------------------------------------------------
// NOTES:
// - Only table scripts for the current table are involved.

if( upload_delete is real ) {
    upload_delete
} else if( handle_UploadData script is real or
    upload_delete script is defined as an ignored script ) {
    // Ignore this delete. (Only ignored in SQL, possibly handled by handle_uploadData.)
} else {
    error
}