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

SAP Sybase SQL Anywhere 16.0 » MobiLink - Client Administration » SQL Anywhere clients for MobiLink » Scripted upload » Tutorial: Using scripted upload

 

Lesson 1: Creating the consolidated database

This tutorial shows you how to set up a scripted upload that provides conflict detection. The tutorial creates the consolidated and remote databases, stored procedures, publications and subscriptions that are required by scripted upload.

Prerequisites

This lesson assumes you have the roles and privileges listed in the Privileges section at the start of this tutorial: Tutorial: Using scripted upload.

Context and remarks

This tutorial specifies file names and assumes they are in the current directory, which is scriptedupload. In a real application, you should specify the full path to the file.

This tutorial is presented in such a way that you can either just read through it, or you can cut and paste the text to run the sample.

 Task
  1. Run the following command to create a directory to hold the tutorial files, and switch to that directory.

    md c:\scriptedupload
    cd c:\scriptedupload
  2. Run the following command to create a consolidated database:

    dbinit -dba DBA,sql consol.db
  3. Next, run the following command to define an ODBC data source for the consolidated database:

    dbdsn -w dsn_consol -y -c "UID=DBA;PWD=sql;DBF=consol.db;SERVER=consol"
  4. To use a database as a consolidated database, you must run a setup script that adds system tables, views, and stored procedures that are used by MobiLink. The following command sets up consol.db as a consolidated database:

    dbisql -c "DSN=dsn_consol" "%SQLANY16%\MobiLink\setup\syncsa.sql"
  5. To open Interactive SQL and connect to consol.db using the dsn_consol DSN, run the following command:

    dbisql -c "DSN=dsn_consol"
  6. Run the following SQL statements. They create the employee table on the consolidated database, insert values into the table, and create the required synchronization scripts.



    CREATE TABLE employee (
       id      unsigned integer primary key,
       name    varchar( 256),
       salary  numeric( 9, 2 )
    );
    
    INSERT INTO employee VALUES( 100, 'smith', 225000 );
    COMMIT;
    
    CALL ml_add_table_script( 'default', 'employee', 'upload_insert',
           'INSERT INTO employee ( id, name, salary ) VALUES ( {ml r.id}, {ml r.name}, {ml r.salary} )' );
    
    CALL ml_add_table_script( 'default', 'employee', 'upload_update',
           'UPDATE employee SET name = {ml r.name}, salary = {ml r.salary} WHERE id = {ml r.id}' );
    
    CALL ml_add_table_script( 'default', 'employee', 'upload_delete',
           'DELETE FROM employee WHERE id = {ml r.id}' );
    
    CALL ml_add_table_script( 'default', 'employee', 'download_cursor',
           'SELECT * from employee' );

    After you have executed the SQL, leave Interactive SQL running and connected to the consolidated database as you will be running more SQL against the database as you work through the tutorial.

Results

The consolidated database is created and set up to be used with MobiLink.