ODBC Code Samples

To run these examples, build them against your ODBC Driver Manager. Ensure that the helper function file, util.c, is present in the directory you build the examples in. For example:

$ ls
ListDSNs.c
util.c
$ cc -I/usr/local/easysoft/unixODBC/include ListDSNs.c \
   -o ListDSNs -L/usr/local/easysoft/unixODBC/lib/ -lodbc
$ chmod +x ./ListDSNs
$ ./ListDSNs
Data Source - FB_SAMPLE
Data Source - ORACLE_SAMPLE
Data Source - ORACLE_XE
Data Source - SQLSERVER_SAMPLE
Data Source - SQLSERVER_SAMPLE_SSL
Data Source - DERBY_SAMPLE
Data Source - IB_SAMPLE
Data Source - SF_SAMPLE

Complete.

Examples that demonstrate SQL Server functionality (such as Table Valued Parameters) use definitions stored in the Native Client header file, sqlncli.h. You need to tell your compiler where to find this file to build these examples. For example:

$ cc -I/usr/local/easysoft/unixODBC/include TVPInsertRecs.c \
-I/usr/local/easysoft/sqlserver/include -o TVPInsertRecs
-L/usr/local/easysoft/unixODBC/lib/ -lodbc

sqlncli.h is included in Easysoft's SQL Server ODBC driver distribution, as shown in the preceding cc command.

ExampleDescription
Asynchronous executionExecute a parameterised SELECT statement asynchronously.
SQLBindColBind result set columns.
SQLBindParameterParameterised INSERT.
SQLBrowseConnectPrompt for connection string values if any are missing in the supplied DSN.
SQLBulkOperationsRead/update/delete/insert data in bulk.
SQLColAttributeFor each column in a result set use SQLColAttribute to get column name/label.
SQLCopyDescCopy table through copy descriptor.
Create table (I)Use SQLExecDirect to create a table with an identity field.
Create table (II)Use SQLExecDirect to create a table.
Create table (III)Create tables used throughout the examples.
SQLDescribeCol / SQLBindColDescribe and bind columns.
SQLDescribeCol / SQLColAttributeRead records based on column attributes
SQLDescribeParam / SQLDescribeColIdentify parameters and columns in SQL statement.
Drop tableDrop database table.
SQLPrepare / SQLExecuteInsert records into a table.
SQLColumnPrivilegesList the privileges associated with the columns of a specified table.
SQLGetConnectAttrRetrieve connection attribute values.
SQLGetTypeInfoList SQL data type information
SQLTablesReturn list of table, catalog, and schema names.
SQLDriversList the available ODBC drivers.
SQLDataSourcesList the available ODBC data sources.
SQLGetEnvAttrList environment attribute settings.
SQLGetFunctionsDetermine ODBC function support.
SQLProcedureColumnsList input and output parameters, as well as the column details for the procedures visible to a data source.
SQLProceduresList procedure names stored in a specific data source.
SQLSpecialColumnsList optimal set of columns that uniquely identifies a row in the table.
SQLStatisticsList table and index statistics.
SQLColumnsList table column information.
SQLPrimaryKeys / SQLForeignKeysDisplay primary and foreign key structures within tables.
SQLTablePrivilegesList tables and table privileges.
SQLTables / SQLNumResultColsList table information.
SQLNativeSqlReturn a SQL string as modified by the ODBC driver.
SQLExtendedFetchRetrieve data using both row and column wise binding (ODBC version 2 method).
SQLExecDirect / SQLFetch / SQLGetData (I)Read multiple long text fields.
SQLExecDirect / SQLFetch / SQLGetData (II)Read a single long text field.
SQLExecDirect / SQLBindCol / SQLFetchRetrieve records using a SELECT statement within a WHERE clause.
SQLGetDescRecDisplay descriptor values.
SQLEndTranCommit and roll back transaction.
SQLSetPos / SQLFetchScrollUse keyset driven cursor type.
SQLBindParameter / SQLBindCol (I)Select data by using multiple parameter arrays.
SQLBindParameter / SQLBindCol (II)Select data by using a single parameter array.
SQLSetStmtAttr / SQLFetchScroll / SQLMoreResultsUse a parameter array with a keyset driven cursor to retrieve rowsets.
SQLPutData (I)Insert a record containing multiple long text fields.
SQLPutData (II)Insert a record containing a long text field.
SQLSetStmtAttr / SQLBindParameterUse an INSERT statement with parameter arrays.
SQLSetStmtAttr / SQLBindParameterUse a SELECT statement with parameter arrays.
Helper functionsHelper functions used by examples (util.c).
Stored Procedure (I)Call a stored procedure, which returns a result set.
Stored Procedure (II)Call a stored procedure using input/output parameters, which returns a value.
Stored Procedure (III)Call a stored procedure using input/output parameters, which returns a value.
Stored Procedure (IV)Call a stored procedure using input/output parameters, which inserts records.
Stored Procedure (V)Call a stored procedure, which returns multiple results sets.
Stored Procedure (VI)Call a stored procedure using input/output parameters, which returns a value.
Stored Procedure (VII)Call a stored procedure using input/output parameters, which selects data.
Stored Procedure (VIII)Call a stored procedure, which takes an array of parameters.
Stored Procedure (IX)Call a stored procedure, which reads, inserts, updates or deletes records.
Stored Procedure (X)Call a stored procedure, which demonstrates output procedure streaming, a feature introduced in ODBC 3.8.
SQL Server Table-Valued Parameter (I)Insert into SQL Server in bulk by using a Table-Valued Parameter.
SQL Server Table-Valued Parameter (II)Copy one table to another by using a Table-Valued Parameter, which passes several records to a stored procedure to do the insert.
SQL Server Table-Valued Parameter (III)Use stored procedure and Table-Valued Parameters to insert records into an Authors table and a Books table.
Helper functionsHelper functions used by stored procedure examples (CallSPUtil.c)