UltraLite User's Guide
Tutorial: Build an Application Using Embedded SQL
After you have created a source file sample.sqc using the sample code in the previous section, you are ready to build your UltraLite application. Follow these steps in Microsoft Visual C++ 6.0 to create the sample embedded SQL UltraLite application.
To build the sample embedded SQL UltraLite application
Start the Adaptive Server Anywhere personal database server.
By starting the database server, both the SQL preprocessor and the UltraLite analyzer will have access to your reference database. The sample application uses the CustDB sample database custdb.db as a reference database and as consolidated database. Start the database server at the command line from the Samples\UltraLite\CusDB directory containing custdb.db as follows:
dbeng9.exe custdb.db
Alternatively, you can start the database server by selecting Start
Start Microsoft Visual C++ from your desktop in the standard fashion.
Configure Visual C++ to search the appropriate directories for Embedded SQL header files and UltraLite library files.
Select Tools
C:\Program Files\Sybase\SQL Anywhere 9\h
If you have installed SQL Anywhere to a directory other than the default, substitute your installation directory above. On the same tab, select Library Files under the Show Directories For drop down menu. Include the following directory so that the UltraLite library files can be accessed.
C:\Program Files\Sybase\SQL Anywhere 8\UltraLite\win32\386\lib
Click OK to submit the changes.
Create a new workspace tutorial:
Select File
Click the Workspaces tab.
Choose Blank Workspace. Specify a workspace name tutorial and specify C:\esqltutorial\tutorial as the location to save this workspace. Click OK. Workspace tutorial will be added to the Workspace window.
Create a new project ultutorial and add it to the tutorial workspace:
Select File
Click the Project tab.
Choose Win32 Console Application. Specify a project name ultutorial and select Add To Current Workspace. Click OK. Choose to create An Empty Project and click Finish. The project will be saved in the tutorial folder.
Click the FileView tab on the Workspace window. The workspace tutorial now consists of one project. Project ultutorial is listed under the workspace tutorial and has three folders: Source Files, Header Files, Resource Files.
Add the sample.sqc embedded SQL source file to the project:
Right click on the Source Files folder and select Add Files to Folder. Locate your sample.sqc file and click OK. Open the Source Files folder to verify that it contains sample.sqc.
Configure the sample.sqc source file settings to invoke the SQL preprocessor to preprocess the source file:
Right click on the sample.sqc file in the Workspace window and select Settings. A Project Settings dialog appears.
From the Settings For drop down menu, choose All Configurations.
In the Custom Build tab, enter the following statement in the Commands box. Ensure that the statement is entered all on one line.
"%asany8%\win32\sqlpp.exe" -q -o WINNT -c "dsn=Ultralite 9.0 Sample" $(InputPath) sample.cpp
Specify sample.cpp in the Outputs box.
Click OK to submit the changes. This statement runs the SQL preprocessor sqlpp on the sample.sqc file, and writes the processed output in a file named sample.cpp. The SQL preprocessor translates SQL statements in the source file into C/C++.
Because the sample application consists of only one source file, the preprocessor automatically runs the UltraLite analyzer as well and appends extra C/C++ code to the generated source file.
Preprocess the sample.sqc file:
Select sample.sqc in the Workspace window. Choose Build
Add the sample.cpp file to the project:
Right click on the Source Files folder in the Workspace window and select Add Files to Folder. Locate your sample.cpp file (in c:\esqltutorial\tutorial\ultutorial) and click OK. The sample.cpp file appears inside the Source Files folder.
Configure the project settings:
Right click on the ultutorial project and select Settings. The Project Settings dialog appears.
Select All Configurations under the Settings For drop down menu.
Click the Link tab and add the following runtime library to the Object/Library Modules box.
ulimp.lib
Click the C/C++ tab. Select Preprocessor from the Category drop-down menu. Ensure that the following are included in the Preprocessor definitions:
__NT__,UL_USE_DLL
Click OK to close the dialog.
Build the executable:
Select Build
Run the application:
Select Build
Adding synchronization to your application