Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Get started with the IBM Data Server CLI Driver for Informix

Premnath Srinivasan (s.premnath@in.ibm.com), Development Engineer, IBM
Premnath Srinivasan photo
Premnath Srinivasan is a development engineer for the IBM Data Server CLI Driver team with IBM Software Lab, India. He has been with the IBM software lab for over five years, working with other drivers such as Informix ODBC drivers, Informix OLEDB Drivers, and Informix .NET providers.
Roopa Ramanathan (roopa.ramanathan@in.ibm.com), Software Test Specialist, IBM
Roopa Ramanathan photo
Roopa Ramanathan works with IBM Common Application Development for CLI QA team in IBM India Software Labs. She has been working on CLI driver for the past 3 years.

Summary:  The IBM® Data Server CLI Driver supports application development for IBM Informix® and IBM DB2®. It is available for download as part of the Informix Client Software Development Kit (CSDK). This article describes how the CLI Driver supports ODBC application development for Informix, and highlights the benefits of using the Data Server CLI Driver. The article also provides examples to help you quickly get started using the IBM Data Server CLI Driver.

Date:  09 Dec 2010
Level:  Intermediate PDF:  A4 and Letter (61KB | 12 pages)Get Adobe® Reader®
Also available in:   Chinese

Activity:  4537 views
Comments:  

Introduction

Open database connectivity (ODBC) is a standard, callable, SQL interface for accessing data from a variety of databases that helps to make applications independent of database management systems. An application can use these interfaces regardless of the underlying database.

ODBC drivers are libraries that have the implementations of the ODBC APIs. Database vendors each have their own set of ODBC drivers, and these drivers communicate to the DBMS using a known protocol.

The following descriptions show the differences between the two ODBC drivers that you can use for application development with Informix, and Figure 1 shows the different databases that the common client CLI Driver works with.

  • IBM Informix ODBC Driver — IBM Informix ODBC Driver is available for download as part of the Informix Client SDK. This ODBC Driver works only with Informix and uses the SQLI protocol for communication with Informix servers.

  • IBM Data Server CLI Driver (Common CLI Driver) — The IBM Data Server CLI Driver is also referred to as the Common CLI Driver. It is available for download as part of the Informix Client SDK (version 3.50xC6 or later) or the IBM Data Server Driver Package. This ODBC Driver(version v97FP2 or later) supports both Informix (V11.10 or later) and DB2 databases and uses the DRDA protocol for communication with data servers.

Figure 1. Common client CLI Driver with different databases
diagram shows .NET apps connected through common .NET provideer to Common client CLI driver, which then connects to various databases

Benefits for using IBM Data Server CLI Driver for Informix database

The rich features in IBM Data Server CLI Driver help the application to efficiently access data. The following are some of the advanced features that are available in IBM Data Server CLI Driver:

  • Asynchronous execution
  • LOB locators
  • Retry on error
  • Advanced tracing mechanisms
  • Advanced CLI APIs
  • Batch SQL and SQLMoreResults()
  • CLI array input chaining
  • Mechanism to register Microsoft ODBC DSN from command line

Each of these advanced features will be explained in detail in later sections.

Using IBM Data Server CLI Driver lets a single application access data from Informix and DB2 servers. This application will load IBM Data Server CLI Driver and use it to insert or retrieve data from Informix as well as DB2 servers. Listing 1 shows an example of two connection handles, one connecting to an Informix server and the other connecting to a DB2 server, and how a table is created in both Informix and DB2 databases.


Listing 1. Sample code to connect to both Informix and DB2

...
SQLRETURN cliRC = SQL_SUCCESS;
SQLHANDLE henv1, henv2;   // Environment handles
SQLHANDLE hdbc1, hdbc2;   // Connection handles
SQLHANDLE hstmt1, hstmt2; // Statement handles

// DB2 Database details
char szDbAlias1[] = "DB2_DATABASE";
char szUser1[] = "USER";
char szPwd1[] = "********";
int rc = 0;

// Informix Database details
char szDbAlias2[] = "INFORMIX_DB";
char szUser2[] = "USER";
char szPwd2[] = "*********";
// allocate an environment handle 
cliRC = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, henv1);
if (cliRC != SQL_SUCCESS)
{
printf("\n--ERROR while allocating the environment handle.\n");
return 1;
}

// allocate a database connection handle - DB2
cliRC = SQLAllocHandle(SQL_HANDLE_DBC, henv1, hdbc1);
ENV_HANDLE_CHECK(henv1, cliRC);
// allocate a database connection handle - Informix
cliRC = SQLAllocHandle(SQL_HANDLE_DBC, henv1, hdbc2);
ENV_HANDLE_CHECK(henv1, cliRC);

printf("\n  Connecting to the DB2 database %s ...\n", szDbAlias1);

// connect to the database
cliRC = SQLConnect(hdbc1,
                 (SQLCHAR *)szDbAlias1,
                 SQL_NTS,
                 (SQLCHAR *)szUser1,
                 SQL_NTS,
                 (SQLCHAR *)szPwd1,
                 SQL_NTS);
DBC_HANDLE_CHECK(hdbc1, cliRC);
printf("  Connected to the database %s.\n", szDbAlias1);

printf("\n  Connecting to the Informix database %s ...\n", szDbAlias2);

// connect to the database
cliRC = SQLConnect(hdbc2,
                 (SQLCHAR *)szDbAlias2,
                 SQL_NTS,
                 (SQLCHAR *)szUser2,
                 SQL_NTS,
                 (SQLCHAR *)szPwd2,
                 SQL_NTS);
DBC_HANDLE_CHECK(hdbc1, cliRC);
printf("  Connected to the database %s.\n", szDbAlias2);

// allocate the handle for statement 1
cliRC = SQLAllocHandle(SQL_HANDLE_STMT, hdbc1, hstmt1);
DBC_HANDLE_CHECK(hdbc1, cliRC);

// allocate the handle for statement 2
cliRC = SQLAllocHandle(SQL_HANDLE_STMT, hdbc2, hstmt2);
DBC_HANDLE_CHECK(hdbc2, cliRC);

printf("\n  Executing query against DB2 database %s ...\n", szDbAlias1);

// execute statement 1 on connection 1
cliRC = SQLExecDirect(hstmt1,
                    (SQLCHAR *)"CREATE TABLE table1(col1 INTEGER)",
                    SQL_NTS);
MC_STMT_HANDLE_CHECK(hstmt1, henv1, cliRC);


printf("  Query executed against database %s.\n", szDbAlias1);

printf("\n  Executing query against Informix database %s ...\n", szDbAlias2);

// execute statement 1 on connection 2
cliRC = SQLExecDirect(hstmt2,
                    (SQLCHAR *)"CREATE TABLE table1(col1 INTEGER)",
                    SQL_NTS);
MC_STMT_HANDLE_CHECK(hstmt2, henv1, cliRC);

printf("  Query executed against database %s.\n", szDbAlias2);

// execute statement 2 on connection 1
cliRC = SQLExecDirect(hstmt1, (SQLCHAR *)"DROP TABLE table1", SQL_NTS);
MC_STMT_HANDLE_CHECK(hstmt1, henv1, cliRC);

// execute statement 2 on connection 2
cliRC = SQLExecDirect(hstmt2, (SQLCHAR *)"DROP TABLE table1", SQL_NTS);
MC_STMT_HANDLE_CHECK(hstmt2, henv2, cliRC);

printf("\n  Disconnecting from the database %s...\n", szDbAlias1);

// disconnect from the database
cliRC = SQLDisconnect(hdbc1);
DBC_HANDLE_CHECK(hdbc1, cliRC);

printf("  Disconnected from the database %s.\n", szDbAlias1);

printf("\n  Disconnecting from the database %s...\n", szDbAlias2);

// disconnect from the database
cliRC = SQLDisconnect(hdbc2);
DBC_HANDLE_CHECK(hdbc2, cliRC);

printf("  Disconnected from the database %s.\n", szDbAlias2);

// free the connection handle
cliRC = SQLFreeHandle(SQL_HANDLE_DBC, hdbc1);
DBC_HANDLE_CHECK(hdbc1, cliRC);

// free the connection handle
cliRC = SQLFreeHandle(SQL_HANDLE_DBC, hdbc2);
DBC_HANDLE_CHECK(hdbc2, cliRC);

// free the environment handle
cliRC = SQLFreeHandle(SQL_HANDLE_ENV, henv1);
ENV_HANDLE_CHECK(henv1, cliRC);
...




Advanced CLI features

Asynchronous execution

By default, an application makes calls to an ODBC driver which then synchronously executes statements against the database server. In this mode of operation, the driver does not return control to the application until its own request to the database server is complete. For complex queries taking more than few seconds to execute, synchronous execution may affect the overall application's performance.

With IBM Data Server CLI Driver, applications can take advantage of asynchronous execution.

For more information on CLI Drivers Asynchronous support, see the Asynchronous execution of CLI functions topic in the IBM Information Center.

Lob locators

Applications that use IBM Data Server CLI Driver can use LOB locators to retrieve LOB data in pieces. If you are interested in only a few parts of LOB data, then using LOB locators will greatly reduce network traffic and improve performance. A LOB locator is not stored in the database, it refers to a LOB value during a transaction, and does not persist beyond the transaction in which it was created.

The following CLI APIs uses LOB Locators to retrieve data in pieces.

Retry on error

When the applications bind a wrong datatype for the application parameters, the ODBC drivers will fail because of incorrect binding. IBM Data Server CLI Driver has the capability to detect such errors and take corrective actions using the IPD information obtained during SQLPrepare(). The CLI/ODBC configuration keyword ReportRetryErrorsAsWarnings allows you to set whether error recovery warnings are returned to the application or not. You should correct these errors in the application. Otherwise multiple executions will occur each time the application runs, making it less efficient.

For more information about retry on error, see the RetryOnError CLI/ODBC configuration keyword topic in the IBM Information Center.

Advanced tracing options

IBM Data Server CLI Driver comes with an extensive diagnostic support to diagnose a problem. The following tracing mechanism helps you to trace the complete flow of control and data.

CLI trace

CLI trace helps you to trace the following:

  • CLI API names that are being called by the application
  • Value of the parameters that are passed to the CLI APIs
  • The return codes of the various CLI APIs. This information is captured in a log file.
  • Time taken for the API call

You can enable the CLI trace mechanism as shown in Listing 2.


Listing 2. Enabling CLI trace


db2trc dump <dump_filename>
db2trc off 
db2trc fmt -cli <dump_filename> <ODBC-CLI_trace_filename>


For more information on CLI trace, see the Trace CLI/ODBC configuration keyword topic in the IBM Information Center.

DB2 trace

You can use db2trc to extensively trace function and data flows, as well as for troubleshooting any problems that you are investigating. Enabling this trace facility will negatively impact system performance, so you should not enable it unless recommended by IBM Software Support and development teams.

Perform the following steps to enable DB2 trace:

  1. Enable db2trc:
    db2trc on -f db2trc.dmp
  2. Run your application.
  3. Stop the trace:
    db2trc off
  4. Format the dump file:
    db2trc flw db2trc.dmp <filename.flw>
    db2trc fmt db2trc.dmp <filename.fmt>

For more information on DB2 trace, see the Obtaining a DB2 trace using db2trc topic in the IBM Information Center.

Advanced CLI APIs

The following shows three advanced CLI APIs.

  1. SQLExtendedPrepare() and SQLExtendedBind() API

IBM Data Server CLI Driver supports SQLExtendedPrepare() and SQLExtendedBind() APIs, which drastically reduce the ODBC API's call, and help you to achieve a goal with minimum calls.

Click the following links for more information about the arguments and usage for these APIs.

  1. SQLCreateDb() and SQLDropDb() API

IBM Data Server CLI Driver supports SQLCreateDb() and SQLDropDb() APIs. These APIs help you to create or drop a database.

Click the following links for more information about the arguments and usage for these APIs:

  1. Batch SQL and SQLMoreresults() API

IBM Data Server CLI Driver supports SQLMoreResults() API. This API helps you to do the following:

  • Execute a batch SQL
  • Fetch the result sets returned by a stored procedure

For more information on Batch SQL and SQLMoreresults() API, see the SQLMoreResults function (CLI) - Determine if there are more result sets topic in the IBM Information Center.

CLI array input chaining

You can greatly reduce network traffic by enabling array chaining in IBM Data Server CLI Driver. When enabled, execution of all the prepared statements will be chained and executed together when the chaining ends.

For more information on CLI array input chaining, see the Reduction of network flows with CLI array input chaining topic in the IBM Information Center.

Mechanism to register Microsoft ODBC DSN from command line

You can use the db2cli registerdsn option, provided by the IBM Data Server, to add or remove a Microsoft ODBC DSN from the command prompt. When there are multiple installations of IBM Data Server CLI Driver across multiple workstations, this feature lets you to use a single command to register the DSNs, rather than manually removing a DSN using the ODBC Data Source Administrator GUI.

For more information on registering Microsoft ODBC DSN, see the db2cli - DB2 interactive CLI command topic in the IBM Information Center.


Installing the IBM Data Server CLI Driver

To use the IBM Data Server CLI Driver, you need to install one of the following packages.

  • IBM Data Server Driver Package — This is a light weight deployment that provides runtime support for applications using ODBC, CLI, .NET, OLE DB, PHP, Ruby, JDBC, or SQLJ, without the need of installing IBM Data Server Client. IBM Data Server Driver installation can also be invoked while installing Informix CSDK. This is the recommended package when connecting to Informix servers.
  • IBM Data Server Client — This includes all of the functionality of IBM Data Server Runtime Client, along with the functionalities for database administration, application development, and client/server configuration. Though this supports connecting to Informix server, it is not the recommended client package for Informix users.

How to install and configure IBM Data Server Driver

Click the following links for information on how to install IBM Data Server Driver Package on Windows and UNIX platforms respectively.

Once the ODBC/CLI Driver is installed, you need to set up the CLI configuration keywords by editing the db2dsdriver.cfg or db2cli.ini file. The CLI Driver reads these configuration files before establishing the connection to the database.

Click the following links for information on how to edit the db2dsdriver.cfg or db2cli.ini files.

The db2dsdriver.cfg file is the recommended configuration file, as most of the entries in that file apply to ODBC, CLI, .NET, OLE DB, or open source (PHP or Ruby) applications.

Enabling the Informix DRDA port

The following error will be returned by IBM Data Server CLI Driver if the Informix DRDA port is not enabled correctly.

A communication error has been detected. Communication protocol being used: "TCP/IP". Communication API being used: "SOCKETS". Location where the error was detected: "Host Name". Communication function detecting the error "Connect". Protocol specific error code(s): "10061","*","*" SQLSTATE=08001.

For more information on configuring Informix to allow connections from IBM Data Server clients, see the Configuring Informix for connections to IBM Data Server Clients topic in the IBM Information Center.

Testing the IBM Data Server CLI Driver setup after installation

Listing 3 shows how you can check if the IBM Data Server CLI Driver is installed correctly. The connection section of the output shows whether the connection of successful or not.


Listing 3. Command to check if the IBM Data Server CLI Driver is installed correctly

db2cli validate
		{ [-dsn <dsn_name>] |
		  [-database <dbname:server:port>] }
		-connect [-user <user> [-passwd <password>]] 

Connection Section:
----------------------------------------------------------------------------------------
  Connecting to: <dsn_name>
  Connect Status: success
  End Connection Section
----------------------------------------------------------------------------------------

The command shown in Listing 3 validates the configuration files that the CLI Driver uses.

For more information on how to validate the configuration files, see the db2cli - DB2 interactive CLI command topic in the IBM Information Center.


Current limitations of CLI with Informix server

The following are some limitations that you may find with using CLI with Informix server.

  • User-defined data types and distinct data types are not currently supported by CLI Driver against Informix server.

  • Positioned updates using SQLBulkOperations() or SQLSetPos() are not supported with Informix servers, because Informix server does not support updatable scrollable cursors.

  • CLI LOAD utility is not supported against Informix server.

  • CLI LOB streaming and data interleaving are not supported with Informix server because the server does not support Dynamic Data Format.

  • Binary Large Object blocking is not supported against Informix server.

  • CLI Driver against Informix server does not allow binary values to be inserted into CHAR columns. Informix server will give the following error:

    -1260- It is not possible to convert between the specified types.

Conclusion

This article has given you the basic information that you need to start using the IBM Data Server CLI Driver for Informix. It includes an introductory-level description of the CLI Driver, highlights of the benefits of using it, and shows you how to install and configure the driver. You can now use this information as a foundation for using IBM Data Server CLI Driver for Informix for your own applications.


Resources

Discuss


About the authors

Premnath Srinivasan photo

Premnath Srinivasan is a development engineer for the IBM Data Server CLI Driver team with IBM Software Lab, India. He has been with the IBM software lab for over five years, working with other drivers such as Informix ODBC drivers, Informix OLEDB Drivers, and Informix .NET providers.

Roopa Ramanathan photo

Roopa Ramanathan works with IBM Common Application Development for CLI QA team in IBM India Software Labs. She has been working on CLI driver for the past 3 years.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Information Management
ArticleID=594442
ArticleTitle=Get started with the IBM Data Server CLI Driver for Informix
publish-date=12092010
author1-email=s.premnath@in.ibm.com
author1-email-cc=
author2-email=roopa.ramanathan@in.ibm.com
author2-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.

Special offers