/* ... */
/* Allocate an environment handle */
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
/* Connect to first data source */
DBconnect(henv, &hdbc[0]);
/* Connect to second data source */
DBconnect(henv, &hdbc[1]);
/********* Start processing step *************************/
/* NOTE: at this point two connections are active */
/* Set current connection to the first database */
if ( (rc = SQLSetConnection(hdbc[0])) != SQL_SUCCESS )
printf("Error setting connection 1¥n");
/* Call function that contains embedded SQL */
if ((rc = Create_Tab() ) != 0)
printf("Error Creating Table on 1st connection, RC=
/* Commit transaction on connection 1 */
SQLEndTran(SQL_HANDLE_DBC, hdbc[0], SQL_COMMIT);
/* set current connection to the second database */
if ( (rc = SQLSetConnection(hdbc[1])) != SQL_SUCCESS )
printf("Error setting connection 2¥n");
/* call function that contains embedded SQL */
if ((rc = Create_Tab() ) != 0)
printf("Error Creating Table on 2nd connection, RC=
/* Commit transaction on connection 2 */
SQLEndTran(SQL_HANDLE_DBC, hdbc[1], SQL_COMMIT);
/* Pause to allow the existance of the tables to be verified. */
printf("Tables created, hit Return to continue¥n");
getchar();
SQLSetConnection(hdbc[0]);
if (( rc = Drop_Tab() ) != 0)
printf("Error dropping Table on 1st connection, RC=
/* Commit transaction on connection 1 */
SQLEndTran(SQL_HANDLE_DBC, hdbc[0], SQL_COMMIT);
SQLSetConnection(hdbc[1]);
if (( rc = Drop_Tab() ) != 0)
printf("Error dropping Table on 2nd connection, RC=
/* Commit transaction on connection 2 */
SQLEndTran(SQL_HANDLE_DBC, hdbc[1], SQL_COMMIT);
printf("Tables dropped¥n");
/********* End processing step ***************************/
/* ... */
/************* Embedded SQL functions *******************************
** This would normally be a separate file to avoid having to *
** keep precompiling the embedded file in order to compile the DB2 CLI *
** section50 *
************************************************************************/
EXEC SQL INCLUDE SQLCA;
int
Create_Tab( )
{
EXEC SQL CREATE TABLE mixedup
(ID INTEGER, NAME CHAR(10));
return( SQLCODE);
}
int
Drop_Tab( )
{
EXEC SQL DROP TABLE mixedup;
return( SQLCODE);
}
/* ... */