IBM Books

Image, Audio, and Video Extenders Administration and Programming

QBIC catalog sample program

The following figure shows part of a program coded in C that creates a QBIC catalog. The program also catalogs into the QBIC catalog a column of images. You can find the complete program in the QBCATDMO.C file in the SAMPLES subdirectory. Before running the complete program, you must run the ENABLE and POPULATE sample programs (also found in the SAMPLES subdirectory). For more information about the sample programs, see Appendix B, Sample programs and media files.

Note the following points in the program:

(1)Include the dmbqbapi header file.

(2)Connect to the database.

(3)Create the catalog. The catalog is created with automatic cataloging turned off.

(4)Open the catalog for update.

(5)Add the average color feature to the catalog.

(6)Catalog a column of images.

(7)Close the catalog.

Figure 20. QBIC catalog sample program

#include <sql.h>
#include <sqlcli.h>
#include <sqlcli1.h>
#include <dmbqbqpi.h> (1)
#include <stdio.h>
 
/****************************************************************************/
/*  Define the function prototypes                                          */
/****************************************************************************/
 
void printError(SQLHSTMT hstmt);
void createCatalog();
void openCatalog();
void closeCatalog();
void addFeature();
void catalogImageColumn();
 
QbCatalogHandle cHdl = 0;
 
static SQLHENV henv;
static SQLHDBC hdbc;
static SQLHSTMT hstmt;
static SQLRETURN rc;
char tableName[] = "sobay_catalog";
char columnName[] = "covers";
 
SQLCHAR uid[18+1];
SQLCHAR pwd[30+1];
SQLCHAR dbnName[SQL_MAX_DSN_LENGTH+1];
 
void main ()
{
/*---- prompt for database name, userid, and password ----*/
  printf("Enter database name:\n");
  gets((char *) dbName);
  printf("Enter userid:\n");
  gets((char *) pwd);
/* set up the SQL CLI environment */
 SQlAllocEnv(&henv);
 SQLAllocConnect(henv, &hdbc);
 rc = SQLConnect(hdbc,dbname,SQL_NTS,uid,SQL_NTS,pwd,SQL_NTS); (2)
 if (rc != SQL_SUCCESS)
 {
  printError(SQL_NULL_HSTMT);
  exit(1);
 }
 createCatalog();
   openCatalog();
   addFeature();
 getCatalogInfo();
 listFeatures();
 catalogImageColumn();
 closeCatalog();
 
 SQLDisconnect(hdbc);
 SQLFreeConnect(hdbc);
 SQLFreeEnv(henv);
}
/**********************************************************************/
void createCatalog()
{
 SQLINTEGER autoCatalog = 0;
 SQLINTEGER retLen;
   SQLINTEGER errCode = 0;
   char errMsg[500];
 
   QbCreateCatalog( (3)
         (char *) tableName,
         (char *) columnName,
         autoCatalog,
         0
        );
 
   DBiGetError(&errCode, errMsg);
   if(errCode) printf("Error code is %d Error Message %s", errCode, errMsg);
}
/**********************************************************************/
void openCatalog()
{
   SQLINTEGER errCode = 0;
   char errMsg[500];
 SQLINTEGER mode = qbiUpdate;
 
   QbOpenCatalog( (4)
         (char *) tableName,
         (char *) columnName,
         mode,
         &cHdl
        );
 
   DBiGetError(&errCode, errMsg);
   if(errCode) printf("Error code is %d Error Message %s", errCode, errMsg);
}
 
/**********************************************************************/
void addFeature()
{
 SQLINTEGER errCode=0;
 char errMsg[5
 if(cHdl) /* if we have an open catalog, else do nothing */
 {
   char featureName*lbrk.] = "QbColorFeatureClass"; (5)
     QbaddFeature(
         cHdl,
         featureName
        );
 
     DBiGetError(&errCode, errMsg);
     if(errCode) printf("Error code is %d Error Message %s", errCode, errMsg);
 }
 else
 {
  exit(1);
 }
}
/**********************************************************************/
void catalogImageColumn()
{
   SQLINTEGER errCode = 0;
   char errMsg[500];
 
 if(cHdl) /* if we have an open catalog, else do nothing */
 {
  SQLRETURN rc;
    QbCatalogColumn( (6)
         cHdl,
        );
 
    DBiGetError(&errCode, errMsg);
    if(errCode) printf("Error code is %d Error Message %s", errCode, errMsg);
 
 else
 {
  exit(1);
 }
}
/**********************************************************************/
void closeCatalog()
{
 if(cHdl) /* if we have an open catalog, else do nothing */
 {
    QbCloseCatalog( (7)
         cHdl,
        );
 }
}
/**********************************************************************/


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