Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - Programming » SQL Anywhere Embedded SQL » Introduction to embedded SQL

Structure of embedded SQL programs Next Page

Loading the interface library dynamically


The usual practice for developing applications that use functions from DLLs is to link the application against an import library, which contains the required function definitions.

This section describes an alternative to using an import library for developing SQL Anywhere applications. The SQL Anywhere interface library can be loaded dynamically, without having to link against the import library, using the esqldll.c module in the src subdirectory of your installation directory.

To load the interface DLL dynamically
  1. Your program must call db_init_dll to load the DLL, and must call db_fini_dll to free the DLL. The db_init_dll call must be before any function in the database interface, and no function in the interface can be called after db_fini_dll.

    You must still call the db_init and db_fini library functions.

  2. You must #include the esqldll.h header file before the EXEC SQL INCLUDE SQLCA statement or #include <sqlca.h> line in your embedded SQL program.

  3. A SQL OS macro must be defined. The header file sqlca.h, which is included by esqdll.c, attempts to determine the appropriate macro and define it. However, certain combinations of platforms and compilers may cause this to fail. In this case, you must add a #define to the top of this file, or make the definition using a compiler option.

    Macro Platforms
    _SQL_OS_NETWARE NetWare
    _SQL_OS_UNIX Unix
    _SQL_OS_UNIX64 64-bit Unix
    _SQL_OS_WINDOWS All Windows operating systems
  4. Compile esqldll.c.

  5. Instead of linking against the imports library, link the object module esqldll.obj with your embedded SQL application objects.

Sample

You can find a sample program illustrating how to load the interface library dynamically in the samples-dir\SQLAnywhere\ESQLDynamicLoad directory. The source code is in sample.sqc.