User's Guide
Part V. The SQL Anywhere Programming Interfaces
Chapter 34. The Embedded SQL InterfaceThe 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. Using ESQLDLL.C is recommended as it is easier to use and more robust in its ability to locate the interface DLL.
To use the dynamic interface library loading:
You must still call the db_initand db_finilibrary functions.
| Macro | Platforms |
|---|---|
| _SQL_OS_WINNT | Windows 95 and Windows NT |
| _SQL_OS_WINDOWS | Windows 3.x |
| _SQL_OS_OS232 | 32-bit OS/2 |
The following example illustrates how to use ESQLDLL.C and ESQLDLL.H.:
#include <stdio.h>#include "esqldll.h"EXEC SQL INCLUDE SQLCA;#include "sqldef.h"#include <windows.h>EXEC SQL BEGIN DECLARE SECTION;int x;a_sql_statement_number stat1;EXEC SQL END DECLARE SECTION;#define TRUE 1#define FALSE 0void printSQLError( void ){char buffer[200];sqlerror_message( &sqlca, buffer, sizeof(buffer) );#ifdef _SQL_OS_WINDOWSprintf( "Error %ld -- %Fs\n", SQLCODE, buffer );#elseprintf( "Error %ld -- %s\n", SQLCODE, buffer );#endif}char *dllpaths[] = { "s:\\jasonhi\\",NULL };#include <windows.h>int main( void ){struct sqlda _fd_ * sqlda1;int result;char string[200];printf( "Initing DLL\n" );result = db_init_dll( dllpaths );switch( result ) {case ESQLDLL_OK:printf("OK\n");break;case ESQLDLL_DLL_NOT_FOUND:printf("DLL NOT FOUND\n");return( 10 );case ESQLDLL_WRONG_VERSION:printf("WRONG VERSION\n");return( 10 );}if( !db_init( &sqlca ) ) {printf("db_init failed.\n");db_fini_dll();return( 10 );}#ifdef _SQL_OS_WINNTresult = db_string_connect( &sqlca, "UID=dba;PWD=sql;DBF=d:\\sqlany50\\sample.db");#elif defined( _SQL_OS_WINDOWS )result = db_string_connect( &sqlca, "UID=dba;PWD=sql;DBF=c:\\wsql50\\sample.db");#elif defined( _SQL_OS_OS232 )result = db_string_connect( &sqlca, "UID=dba;PWD=sql;DBF=h:\\wsql50\\sample.db");#endifif( ! result ) {printf( "db_string_connect returned = %d\n", result );printSQLError();}sqlda1 = alloc_descriptor( sqlcaptr, 20 );EXEC SQL PREPARE :stat1 FROM'select * from employeeWHERE empnum = 80921';if( SQLCODE != 0 ) {printSQLError();}EXEC SQL DECLARE curs CURSOR FOR :stat1;if( SQLCODE != 0 ) {printSQLError();}EXEC SQL OPEN curs;if( SQLCODE != 0 ) {printSQLError();}EXEC SQL DESCRIBE :stat1 INTO sqlda1;if( SQLCODE != 0 ) {printSQLError();}sqlda1->sqlvar[1].sqltype = 460;fill_sqlda( sqlda1 );EXEC SQL FETCH FIRST curs INTO DESCRIPTOR sqlda1;if( SQLCODE != 0 ) {printSQLError();}printf( "name = %Fs\n", (char _fd_ *)sqlda1->sqlvar[1].sqldata );x = sqlda1->sqld;printf( "COUNT = %d\n", x );free_filled_sqlda( sqlda1 );db_string_disconnect( &sqlca, "" );db_fini( &sqlca );db_fini_dll();return( 0 );}