// 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() );
}
}
|
|