IBM Books

Image, Audio, and Video Extenders Administration and Programming

Examples

In the following examples, a database is enabled to hold image data using the default table space.

Using the API: The code in the following figure connects to an existing database before enabling it. This example is written using the DB2 call level interface. It includes some set-up and error-checking code. The complete sample program is in the ENABLE.C file in the SAMPLES subdirectory.

Figure 10. Sample code that enables a database

 
/*---- Set-up -------------------------------------------------*/
#include <stdio.h>
#include <stlib.h>
#include <string.h>
#include "dmbimage.h" /* image extender function prototypes (DBi) */
#include "utility.h"  /* utility functions */
 
#define MMDB_ERROR_MSG_TEXT_LEN         1000
#define SERVER_IS_DB2390 (strcmp(dbms,"DB2")==0 || strcmp(dmbs,"DSN06010")==0)
 
int
main(int argc, char *argv[])
{
        SQLHENV henv = SQL_NULL_HENV;
        SQLHDBC hdbc = SQL_NULL_HDBC;
        SQLHSTMT hstmt = SQL_NULL_HSTMT;
        SQLCHAR uid[18+1];
        SQLCHAR pwd[30+1];
        SQLCHAR dbname[SQL_MAX_DSN_LENGTH+1];
        SQLCHAR buffer[500];
        SQL SMALLINT dbms_sz = 0;
        char    dbms[20];
 
        SQLRETURN rc = SQL_SUCCESS;
        SQLINTEGER sqlcode = 0;
        char errorMsgText[MMDB_ERROR_MSG_TEXT_LEN+1];
        char *program = "enable;
        char *step;
         
 
/*---- Prompt for database name, userid, and password ----*/
       if (argc > 5) ||  (argc >=2 && strcmp(argv[1],"?")== 0))
          {
            printf("Syntax for enable - enabling a DB2 UDB database: \n"
                   "   enable database_name userid password\n");
            exit(0);
          }
 
        if (argc == 4) {
          strcpy((char *)dbname, argv[1]);
          strcpy((char *)uid   , argv[2]);
          strcpy((char *)pwd   , argv[3]);
          }
        else {
          printf("Enter database name:\n");
          gets((char *) dbName);
          printf("Enter userid:\n");
          gets((char *) uid); 
          printf("Enter password:\n");
          gets((char *) pwd);
          }
/*----- connect to the database -----------------------------------------------*/
         rc = cliInitialize(&henv, &hdbc, dbname, uid, pwd);
         cliCheckError(henv, hdbc, SQL_NULL_HSTMT, rc);
         if (rc < 0) goto SERROR;
 
/*----- find out if application is connected to DB2/UDB or DB2/390?------------*/
         rc = SQLGetInfo(hdbc, SQL_DBMS_NAME, (SQLPOINTER) &dbms,
                         sizeof(dbms), &dbms_sz);
         cliCheckError(henv, hdbc, SQL_NULL_HSTMT, rc); 
         if (rc < 0) goto SERROR;
  
/****** enable server for image extender ****************************************/
         if (!SERVER_IS_DB2390)
           {
            printf("%s: Enabling database......\n", program);
           }
         printf("%s: This may take a few minutes, please wait......\n", program);
 
         if (!SERVER_IS_DB2390)
           {
            step="DBiEnableDatabase with NULL tablespace"
            rc=DBiEnableDatabase(NULL);
           }
         if (rc < 0) {
            printf ("%s: %s failed!\n", program, step);
            printMsg(rc);
            DBiGetError(&sqlcode, errorMsgText);
            if (sqlcode)
              printf("sqlcode=%i, ",sqlcode);
         }else if (rc > 0) {
            printf("%s: %s, warning detected.\n", program, step);
            printMsg(rc);
            DBiGetError(&sqlcode, errorMsgText);
            printf("warning MsgText=%s\n", errorMsgText);
         } else
            printf("%s: %s OK\n", program, step);
/****** end of enable server *************************************************/
 

Using the db2ext command line: In this example, the database is already connected.

enable database for db2image


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]