IBM Books

Image Extender、Audio Extender 和 Video Extender 管理和程序设计

QBIC 目录样本程序

下图显示了 用 C 语言编写的,用于创建 QBIC 目录的程序的一部分。该程序还将一列图象编目到 QBIC 目录中。可在 SAMPLES 子目录中的 QBCATDMO.C 文件中找到完整的程序。在运行整个程序之前,必须运行 ENABLE 和 POPULATE 样本程序(也可在 SAMPLES 子目录中找到)。有关样本程序的更多信息,参见附录 B, 样本程序和媒体文件

注意程序中的下列几点:

(1)包括 dmbqbapi 头文件。

(2)连接到数据库。

(3)创建目录。在自动编目关闭的情况下创建目录。

(4)为更新操作打开目录。

(5)将平均颜色特性添加至该目录。

(6)编目图象列。

(7)关闭目录。

图 20. QBIC 目录样本程序

#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,
        );
 }
}
/**********************************************************************/


[ 页的顶部 | 上一页 | 下一页 | 目录 | 索引 ]