In this lesson, you compile a class associated with the CustDB sample database.
SQL Anywhere ships with a SQL Anywhere sample database (CustDB) that is already set up for synchronization, including the SQL scripts required for synchronization. The CustDB ULCustomer table, for example, is a synchronized table that supports a variety of table-level events.
CustDB is designed to be a consolidated database server for both UltraLite and SQL Anywhere clients. The CustDB database has an ODBC data source named SQL Anywhere 12 CustDB.
.NET classes encapsulate synchronization logic in methods. In this section, you create a .NET class called CustdbScripts with logic to handle the ULCustomer upload_insert and download_cursor events.
To execute .NET synchronization logic, the MobiLink server must have access to the classes in iAnywhere.MobiLink.Script.dll. iAnywhere.MobiLink.Script.dll contains a repository of MobiLink server API for .NET classes to use in your .NET methods.
For more information about the MobiLink server API for .NET, see MobiLink server .NET API reference.
When compiling the CustdbScripts class, you must include this assembly to make use of the API. You can compile your class using Visual Studio or at a command prompt.
Create a new Class Library and enter the CustdbScripts code. Link iAnywhere.MobiLink.Script.dll, and build the assembly for your class.
Put the CustdbScripts code in a text file and save the file as CustdbScripts.cs ( or CustdbScripts.vb for Visual Basic). Using a command line compiler, reference iAnywhere.MobiLink.Script.dll and build the assembly for your class.
You can use Visual Studio to create the CustdbScripts assembly.
Start a new Visual C# or Visual Basic Windows Class Library project.
Use CustdbScripts for the project Name and enter an appropriate path. This tutorial assumes the path c:\mldotnet.
In Visual Studio 2010, change the top dropbox from .NET Framework 4 to .NET Framework 3.5.
To use the v4.0 assemblies, you must explicitly include the -clrVersion option when you load the MobiLink server. For more information about the -clrVersion option, see -sl dnet mlsrv12 option.
Ensure that the Class1.cs file is highlighted in the Solution Explorer.
Enter the CustdbScripts code.
For C#, replace the existing code with the following code:
namespace MLExample { class CustdbScripts { public static string UploadInsert() { return("INSERT INTO ULCustomer(cust_id,cust_name) values ({ml r.cust_id}, {ml r.cust_name})"); } public static string DownloadCursor(System.DateTime ts, string user ) { return("SELECT cust_id, cust_name FROM ULCustomer WHERE last_modified >= '" + ts.ToString("yyyy-MM-dd hh:mm:ss.fff") +"'"); } } } |
For Visual Basic, replace the existing code with the following code:
Namespace MLExample Class CustdbScripts Public Shared Function UploadInsert() As String Return("INSERT INTO ULCustomer(cust_id,cust_name) values ({ml r.cust_id}, {ml r.cust_name})") End Function Public Shared Function DownloadCursor(ByVal ts As System.DateTime, ByVal user As String) As String Return("SELECT cust_id, cust_name FROM ULCustomer " + "WHERE last_modified >= '" + ts.ToString("yyyy-MM-dd hh:mm:ss.fff") +"'") End Function End Class End Namespace |
For Visual Basic, right-click the CustdbScripts project, and choose the table Properties » General. Make sure that the text field Root Namespace is cleared of all text.
Build CustdbScripts.dll.
Click Build » Build CustdbScripts.
This file CustdbScripts.dll is created in C:\mldotnet\CustdbScripts\CustdbScripts\bin\Debug.
Proceed to Lesson 2: Creating a MobiLink project.
You can use command lines, a text editor, and a Visual Studio compiler as an alternative to the Visual Studio IDE to create the CustdbScripts assembly.
Create a directory for the .NET class and assembly.
This tutorial assumes the path c:\mldotnet.
Using a text editor, enter the CustdbScripts code.
For C#, type:
namespace MLExample { class CustdbScripts { public static string UploadInsert() { return("INSERT INTO ULCustomer(cust_id,cust_name) values ({ml r.cust_id}, {ml r.cust_name})"); } public static string DownloadCursor(System.DateTime ts, string user ) { return("SELECT cust_id, cust_name FROM ULCustomer WHERE last_modified >= '" + ts.ToString("yyyy-MM-dd hh:mm:ss.fff") +"'"); } } } |
For Visual Basic, type:
Namespace MLExample Class CustdbScripts Public Shared Function UploadInsert() As String Return("INSERT INTO ULCustomer(cust_id,cust_name) values ({ml r.cust_id}, {ml r.cust_name})") End Function Public Shared Function DownloadCursor(ByVal ts As System.DateTime, ByVal user As String) As String Return("SELECT cust_id, cust_name FROM ULCustomer " + "WHERE last_modified >= '" + ts.ToString("yyyy-MM-dd hh:mm:ss.fff") +"'") End Function End Class End Namespace |
Save the file as CustdbScripts.cs ( CustdbScripts.vb for Visual Basic ) in c:\mldotnet.
Compile the file.
For C#, run the following command:
csc /out:c:\mldotnet\custdbscripts.dll /target:library /reference:"C:\Program Files\SQL Anywhere 12\Assembly\v2\iAnywhere.MobiLink.Script.dlmldotnetmldotnet\CustdbScripts.cs |
For Visual Basic, run the following command:
vbc /out:c:\mldotnet\custdbscripts.dll /target:library /reference:"C:\Program Files\SQL Anywhere 12\Assembly\v2\iAnywhere.MobiLink.Script.dll" c:\mldotnet\CustdbScripts.vb |
The CustdbScripts.dll assembly is generated.
Proceed to Lesson 2: Creating a MobiLink project.
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |