Accessing the ODBC API |
Top Previous Next |
The necessary include files for directly accessing the ODBC API are provided for advanced programmers with more complex database needs. These include files are installed to your Emergence BASIC include directory and are named 'sql.inc', 'sqltypes.inc' and 'sqlext.inc'. These files define all of the constants and functions used by the API. It is only necessary to include the main sqlext.inc file with $INCLUDE "sqlext.inc" to begin using the API. The other files are brought in automatically. The files are intended for use with ODBC version 3.0 or higher. To define constants introduced in ODBC version 3.5 add $define ODBCVER35 before the $INCLUDE statement for any file that may need those constants. Here is a short example that uses the ODBC API directly and shows the basic steps involved in connecting to a database: $INCLUDE "sqlext.inc" Combining API access with the command pak. You can mix direct API calls with commands from the command pak. For example dbGet, dbGetNext, and dbGetPrev take only a statement handle allocated with SQLAllocHandle. To use commands that require a database pointer it is necessary to create a UDT that contains both the environment and connection handles. The UDT is defined as: TYPE DBConnection DEF hEnv as UINT DEF hDbc as UINT ENDTYPE Create a variable of type DBConnection and fill in the members with the connection and environment handles returned by SQLAllocHandle. For example in the above code we use dbExecSQL after a connection is established with a few modifications: DEF DBC as DBConnection |