UltraLite User's Guide
Developing Embedded SQL Applications
Building embedded SQL applications
The SQL preprocessor and the UltraLite generator are key features of UltraLite application development. Most development tools use a dependency-based model to assist in compilation, and this section describes how to incorporate UltraLite features into such a model.
For a general overview of the techniques needed, see Configuring development tools for UltraLite development.
The UltraLite plug-in for Metrowerks CodeWarrior automatically provides Palm Computing platform developers with the techniques described here. For information on this plug-in, see Developing UltraLite applications with Metrowerks CodeWarrior.
This section describes how to add UltraLite code generation and the SQL preprocessor into a dependency-based development environment. The specific instructions provided are for Visual C++.
For a tutorial describing details for a very simple project, see Tutorial: Build an Application Using Embedded SQL.
The first set of instructions describes how to add instructions to run the SQL preprocessor to your development tool.
To add embedded SQL preprocessing into a dependence-based development tool
Add the .sqc files to your development project.
The development project is defined in your development tool. It is separate from the UltraLite project name used by the UltraLite generator.
Add a custom build rule for each .sqc file.
The custom build rule should run the SQL preprocessor. In Visual C++, the build rule should have the following command (entered on a single line):
"%asany8%\win32\sqlpp.exe" -q -o WINNT -c connection-string -p project-name $(InputPath) $(InputName).c
where asany8 is an environment variable that points to your SQL Anywhere installation directory, connection-string provides the connection to the reference database, and project-name is the name of your UltraLite project.
If you are generating an executable for a non-Windows platform, choose the appropriate setting instead of WINNT.
For a full description of the SQL preprocessor command-line, see The SQL preprocessor.
Set the output for the command to $(InputName).c.
Compile the .sqc files, and add the generated .c files to your development project.
You need to add the generated files to your project even though they are not source files, so that you can set up dependencies and build options.
For each generated .c file, set the preprocessor definitions.
Under General or Preprocessor, add UL_USE_DLL to the Preprocessor definitions.
Under Preprocessor, add $(asany8)\h and any other include folders you require to your include path, as a comma-separated list.
The following set of instructions describes how to add UltraLite code generation to your development tool.
To add UltraLite code generation into a dependency-based development environment
Add a dummy file to your development project.
Add a file named, for example, uldatabase.ulg, in the same directory as your generated files.
Set the build rules for this file to be the UltraLite generator command line.
In Visual C++, use a command of the following form (which should be all on one line):
"%asany8%\win32\ulgen.exe" -q -c "connection-string" $(InputName) $(InputName).c
where asany8 is an environment variable that points to your SQL Anywhere installation directory, connection-string is a connection to your reference database, and InputName is the UltraLite project name, and should match the root of the text file name. The output is $(InputName).c.
Set the dummy file to depend on the output files from the preprocessor.
In Visual C++, click Dependencies on the custom build page, and enter the names of the generated .c files produced by the SQL preprocessor.
This instructs Visual C++ to run the UltraLite generator after all the necessary embedded SQL files have been preprocessed.
Compile your dummy file to generate the .c file that implements the UltraLite database.
Add the generated UltraLite database file to your project and change its C/C++ settings.
Add the UltraLite imports library to your object/libraries modules list.
In Visual C++, go to the project settings, choose the Link tab, and add the following to the Object/libraries module list for Windows development.
$(asany8)\ultralite\win32\386\lib\ulimp.lib
For other targets, choose the appropriate import library.