下圖顯示以 C 語言撰寫的部份程式碼,此程式碼可用來建立 QBIC 型錄。 此程式也會將影像直欄編入 QBIC 型錄中。 您可以在 SAMPLES 次目錄中的 QBCATDMO.C 檔找到完整程式。 在執行完整程式之前,您必須先執行 ENABLE 和 POPULATE 範例程式 (這兩個範例程式也位於 SAMPLES 次目錄中)。 有關範例程式的詳細資訊, 請參閱附錄 B, 範例程式和媒體檔案。
請注意程式中下列各點:
(1)併入 dmbqbapi 標頭檔。
(2)連接到資料庫。
(3)建立型錄。此型錄在自動編目關閉時建立。
(4)開啟用於更新的型錄。
(5)將平均色特性加入型錄。
(6)將影像直欄編入型錄。
(7)關閉型錄。
#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, ); } } /**********************************************************************/ |