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.
| Example | Description |
|---|---|
| Asynchronous execution | Execute a parameterised SELECT statement asynchronously. |
SQLBindCol |
Bind result set columns. |
SQLBindParameter |
Parameterised INSERT. |
SQLBrowseConnect |
Prompt for connection string values if any are missing from the supplied ODBC data source. |
SQLBulkOperations |
Read, update, delete, insert data in bulk. |
SQLColAttribute |
For each column in a result set, use SQLColAttribute to get column name or label. |
SQLCopyDesc |
Copy 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 and SQLBindCol |
Describe and bind columns. |
SQLDescribeCol and SQLColAttribute |
Read records based on column attributes |
SQLDescribeParam and SQLDescribeCol |
Identify parameters and columns in SQL statement. |
| Drop table | Drop database table. |
SQLPrepare and SQLExecute |
Insert records into a table. |
SQLColumnPrivileges |
List the privileges associated with the columns of a specified table. |
SQLGetConnectAttr |
Retrieve connection attribute values. |
SQLGetTypeInfo |
List SQL data type information. |
SQLTables |
List table, catalog, and schema names. |
SQLDrivers |
List the available ODBC drivers. |
SQLDataSources |
List the available ODBC data sources. |
SQLGetEnvAttr |
List environment attribute settings. |
SQLGetFunctions |
Determine ODBC function support. |
SQLProcedureColumns |
List input and output parameters, as well as the column details for the procedures visible to a data source. |
SQLProcedures |
List procedure names stored in a specific data source. |
SQLSpecialColumns |
List optimal set of columns that uniquely identifies a row in the table. |
SQLStatistics |
List table and index statistics. |
SQLColumns |
List table column information. |
SQLPrimaryKeys and SQLForeignKeys |
Display primary and foreign key structures within tables. |
SQLTablePrivileges |
List tables and table privileges. |
SQLTables and SQLNumResultCols |
List table information. |
SQLNativeSql |
Return a SQL string as modified by the ODBC driver. |
SQLExtendedFetch |
Retrieve data using both row and column wise binding (ODBC version 2 method). |
SQLExecDirect and SQLFetch and SQLGetData (I) |
Read multiple long text fields. |
SQLExecDirect and SQLFetch and SQLGetData (II) |
Read a single long text field. |
SQLExecDirect and SQLBindCol and SQLFetch |
Retrieve records using a SELECT statement within a WHERE clause. |
SQLGetDescRec |
Display descriptor values. |
SQLEndTran |
Commit and roll back transaction. |
SQLSetPos and SQLFetchScroll |
Use keyset driven cursor type. |
SQLBindParameter and SQLBindCol (I) |
Select data by using multiple parameter arrays. |
SQLBindParameter and SQLBindCol (II) |
Select data by using a single parameter array. |
SQLSetStmtAttr and SQLFetchScroll and SQLMoreResults |
Use 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 and SQLBindParameter |
Use an INSERT statement with parameter arrays. |
SQLSetStmtAttr and SQLBindParameter |
Use a SELECT statement with parameter arrays. |
| Helper functions | Helper 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 and output parameters, which returns a value. |
| Stored Procedure (III) | Call a stored procedure using input and output parameters, which returns a value. |
| Stored Procedure (IV) | Call a stored procedure using input and 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 functions | Helper functions used by stored procedure examples (CallSPUtil.c) |