/*******************************************************************************
**                                                                        
** Source File Name = basiccon.c  1.6                                      
**                                                                        
** Licensed Materials - Property of IBM                                   
**                                                                        
** (C) COPYRIGHT International Business Machines Corp. 1995, 1999
** All Rights Reserved.                                                   
**                                                                        
** US Government Users Restricted Rights - Use, duplication or            
** disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      
**                                                                        
**                                                                        
**    PURPOSE :                                                           
**    - demonstrate basic connection to two datasources.
**    - error handling mostly ignored for simplicity
**
**  Refer to mutlicon.c for an expanded version.
**
** For more information about these samples see the README file.
**
** For more information on programming in CLI see the:
**     - "Building CLI Applications" section of the Application Building Guide, and the
**     - CLI Guide and Reference.
**
** For more information on the SQL language see the SQL Reference.
**
*******************************************************************************/

/*--> SQLL1X11.SCRIPT */
#include <stdio.h>
#include <stdlib.h>
#include <sqlcli1.h>

/*<-- */
/* For the Macintosh environment when generating 68K applications */
#ifdef DB268K
   /* Need to include ASLM for 68K applications */
   #include <LibraryManager.h>
#endif
/*--> */

/* prompted_connect is defined in samputil.c */
SQLRETURN
prompted_connect( SQLHANDLE henv,
                  SQLHANDLE * hdbc);

#define MAX_UID_LENGTH   18
#define MAX_PWD_LENGTH   30
#define MAX_CONNECTIONS  2

int main( ) {

    SQLHANDLE henv;
    SQLHANDLE hdbc[MAX_CONNECTIONS] ;

/*<-- */
/* For the Macintosh environment when generating 68K applications */
#ifdef DB268K
   /*
    Before making any API calls for 68K environment,
    need to initialize the Library Manager
   */
   InitLibraryManager(0,kCurrentZone,kNormalMemory);
   atexit(CleanupLibraryManager);
#endif
/*--> */

    /* allocate an environment handle */
    SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv ) ;

    /* Connect to first data source */
    prompted_connect( henv, &hdbc[0] ) ;

    /* Connect to second data source */
    prompted_connect( henv, &hdbc[1] ) ;

    /*********   Start Processing Step  *************************/
    /* allocate statement handle, execute statement, etc.       */
    /*********   End Processing Step  ***************************/

    printf( "\nDisconnecting .....\n" ) ;
    SQLDisconnect( hdbc[0] ) ;  /* disconnect first connection */
    SQLDisconnect( hdbc[1] ) ;  /* disconnect second connection */

    /* free first connection handle */
    SQLFreeHandle( SQL_HANDLE_DBC, hdbc[0] ) ;

    /* free second connection handle */
    SQLFreeHandle( SQL_HANDLE_DBC, hdbc[1] ) ;

    /* free environment handle */
    SQLFreeHandle( SQL_HANDLE_ENV, henv ) ;

    return ( SQL_SUCCESS ) ;

}
/*<-- */