Listings for main.htm and tutorial.js

Following is a complete listing of main.htm for your use:

<html>
<script src="tutorial.js"></script>

<script>
function DisplayRow() {
    Fetch();
    document.form.ID.value = ID;
    document.form.GivenName.value = GivenName;
    document.form.Surname.value = Surname;
    document.form.Street.value = Street;
    document.form.City.value = City;
    document.form.Phone.value = Phone;
}

function FetchForm() {
    GivenName = document.form.GivenName.value;
    Surname = document.form.Surname.value;
    Street = document.form.Street.value;
    City = document.form.City.value;
    Phone = document.form.Phone.value;
}

function ClickInsert()
{
    FetchForm();
    Insert();
    DisplayRow();
}

function ClickNext()
{
    Next();
    DisplayRow();
}

function ClickPrev()
{
    Prev();
    DisplayRow();
}

function ClickSync()
{
    Synchronize();
    DisplayRow();
}
</script>

<body onload="Connect(); DisplayRow();" >

<form name="form">
<br><td> ID: </td>
    <td> <input type="text" name="ID" size="10"> </td>
<br><td> Given Name: </td>
    <td> <input type="text" name="GivenName" size="15"> </td>
<br><td> Surname: </td>
    <td> <input type="text" name="Surname" size="50"> </td>
<br><td> Street: </td>
    <td> <input type="text" name="Street" size="20"> </td>
<br><td> City: </td>
    <td> <input type="text" name="City" size="20"> </td>
<br><td> Phone: </td>
    <td> <input type="text" name="Phone" size="12"> </td>
<br>
<br>

<table>
<tr>
    <td> <input type="button" value="Insert" onclick="ClickInsert();"> </td>
    <td> <input type="button" value="Next" onclick="ClickNext();"> </td>
    <td> <input type="button" value="Prev" onclick="ClickPrev();"> </td>
</tr>
<tr>
    <td colspan=3>
    <input type="button" value="Synchronize" onclick="ClickSync();">
    </td>
</tr>
</table>
</form>

<a href="AG_DEVICEOS/ul_deps.htm"></a>
</body>
</html> 

Following is a complete listing of tutorial.js for your reference and use:

// UltraLite Tutorial

var DB_mgr;
var Connection;
var Table;

var GivenName = "";
var Surname = "";
var Street = "";
var City = "";
var Phone = "";
var ID = "";

function Connect()
{
    var	    dir;
    var	    open_parms;
    var	    browser = navigator.platform;
    
    DB_mgr = CreateObject( "iAnywhere.UltraLite.DatabaseManager.Tutorial" );
    if( DB_mgr == null ) {
    	alert( "Error: cannot create database manager: " + DB_mgr.sqlCode );
	return;
    }
    dir = DB_mgr.directory;
    if( browser == "Palm OS" ) {
	open_parms = "con=tutorial;palm_file=tutorial"
    } else {
    	open_parms = "con=tutorial;" + "file_name=" + dir + "\\tutorial.udb";
    }
    try {
	Connection = DB_mgr.reOpenConnection( "tutorial" );    
    	if( Connection == null ) {
	    Connection = DB_mgr.openConnection( open_parms );
	}
    } catch( ex ) {
    	if( DB_mgr.sqlCode != DB_mgr.SQLError.SQLE_ULTRALITE_DATABASE_NOT_FOUND ) {
    	    alert( "Error: cannot connect to database: " + ex.getMessage() );
	    return;
    	}
    }
    try {
	Table = Connection.getTable( "Customer", null );
	if( Table != null ) {
	    Table.open();
	}
    } catch( ex ) {
	alert( "Error: cannot open table: " + ex.getMessage() );
    }
}

function Fetch() 
{
    if( Table.getRowCount() == 0 ) {
	GivenName = "";
	Surname = "";
	Street = "";
	City = "";
	Phone = "";
	ID = "";
	return;
    } 
    ID = Table.getString( Table.schema.getColumnID( "ID" ) );
    GivenName = Table.getString( Table.schema.getColumnID( "GivenName" ) );
    Surname = Table.getString( Table.schema.getColumnID( "Surname" ) );
    Street = Table.getString( Table.schema.getColumnID( "Street" ) );
    if( Table.isNull( Table.schema.getColumnID( "City" ) ) ) {
	City = "";
    } else {
	City = Table.getString( Table.schema.getColumnID( "City" ) );
    }
    if( Table.isNull( Table.schema.getColumnID( "Phone" ) ) ) {
	Phone = "";
    } else {
	Phone = Table.getString( Table.schema.getColumnID( "Phone" ) );
    }
}

function Insert()
{
    try {
	Table.insertBegin();
	Table.setString( Table.schema.getColumnID( "GivenName" ), GivenName );
	Table.setString( Table.schema.getColumnID( "Surname" ), Surname );
	Table.setString( Table.schema.getColumnID( "Street" ), Street );
	if( City.length > 0 ) {
	    Table.setString( Table.schema.getColumnID( "City" ), City );
	}
	if( Phone.length > 0 ) {
	    Table.setString( Table.schema.getColumnID( "Phone" ), Phone );
	}
	Table.insert();
	Table.moveLast();
    } catch( ex ) {
	alert( "Error: cannot insert row: " + ex.getMessage() );
    }
}

function Next()
{
    if( ! Table.moveNext() ) {
	Table.moveLast();
    }
}

function Prev()
{
    if( ! Table.movePrevious() ) {
	Table.moveFirst();
    }
}

function Synchronize()
{
    var sync_parms; 
    
    sync_parms = Connection.syncParms;	    
    sync_parms.setUserName( "tutorial" );				
    sync_parms.setPassword( "tutorial" );				
    sync_parms.setVersion( "tutorial" );				
    sync_parms.setStream( sync_parms.STREAM_TYPE_TCPIP );
    try {
	Connection.synchronize();
    } catch( ex ) {
    	alert( "Error: cannot synchronize: " + ex.getMessage() );
    }
}