x521 发表于 2007-05-09 21:53

DB2的API编程问题...(基于DB2数据库的应用开发研究)

请教下关于DB2的API编程.
要求我用数据处理API:EXPORT(凋出数据)、IMPORT(调入数据)、LOAD(调入数据)三个函数实现数据的整块调入调出.

这个题目怎么做......谢大家帮我看看..
还有想我想问下谁有 关于<DB2通用数据库API开发人员指南>的电子书.提供下再.....非常感谢....

大梦 发表于 2007-05-10 21:01

老大,直接看db2自带的例子就能搞定的!

就在你的实例目录下面的sqllib\samples\c或是cli下面应该都有,自己找下!

或在那个管理API里面也有函数头的描述

x521 发表于 2007-05-14 22:07

大梦大哥 ..可以帮下 弄弄吗?这个我没用弄过.一点头绪都没有.....


   谢    了...

Law 发表于 2007-05-18 17:44

db2 v8 load API,db2load810封装的例子程序,核心函数是调用db2的db2Load(..),db2load 主要是初始化参数很麻烦



int db2load810(char *sTabName, char *sSourceFile,char *sColDel,char *sLoadMegFile)
{
      char dataFileName;
      char msgFileName;
      struct sqldcol dataDescriptor;
      char actionString;

      db2LoadStruct loadParms;
      char pActionString;
      char pFileTypeModString;
      sqlu_media_list loadMediaList;
      sqlu_location_entry inputLocationEntry;
      db2LoadIn loadInfoIn;
      db2LoadOut loadInfoOut;
      db2PartLoadIn partLoadInfoIn;
      db2PartLoadOut partLoadInfoOut;
      db2LoadNodeList partitioningDbPartNums;
      db2Uint16 mode;
      db2Uint16 isolatePartErrs;
      



        sprintf(dataFileName,"%s",sSourceFile);
        sprintf(msgFileName,"%s",sLoadMegFile);
        sprintf(pFileTypeModString,"%s coldel%s ","ANYORDER ",sColDel);
        printf("%s\n",sTabName);
        sprintf(pActionString," insert into%s",sTabName);
        printf("%s\n",pActionString);
       
      printf("\n--------------------------------------------------------\n");
      printf("\nUSE THE DB2 API:\n");
      printf("db2Load -- Load\n");
      printf("TO LOAD DATA TO A PARTITIONED DATABASE TABLE.\n");
      memset(&loadParms, '\0', sizeof(db2LoadStruct));

      /* Set up the list of input source files. We are using just one */
      /* which will be called "tbload.DEL"                            */
      loadParms.piSourceList = &loadMediaList;
      loadParms.piSourceList->media_type = SQLU_SERVER_LOCATION;
      loadParms.piSourceList->sessions = 1;
      loadParms.piSourceList->target.location = &inputLocationEntry;
      strcpy(loadParms.piSourceList->target.location->location_entry, dataFileName);

      /* Set up the load action string to "INSERT INTO TABLE1" */
      loadParms.piActionString = (struct sqlchar*)malloc(sizeof(short) + strlen(pActionString) + 1);
      strcpy(loadParms.piActionString->data, pActionString);
      loadParms.piActionString->length = strlen(pActionString);

      /* Set the file type to DEL (i.e., an ASCII delimited file) */
      loadParms.piFileType = (char*)SQL_DEL;

      /* Specify the ANYORDER file type modifier which indicates to the*/
      /* load utility that it is not necessary to load the rows of data*/
      /* into the table in the same order they appear in the input file. */
      /* This can result in better load performance and permits the use*/
      /* of multiple partitioning agents as well.                        */
      loadParms.piFileTypeMod = (struct sqlchar*)malloc(sizeof(short) + strlen(pFileTypeModString) + 1);
      strcpy(loadParms.piFileTypeMod->data, pFileTypeModString);
      loadParms.piFileTypeMod->length = strlen(pFileTypeModString);

      /* Set up the name that will serve as a prefix for the*/
      /* message files retrieved from each partition that is*/
      /* participating in the load operation.               */
      loadParms.piLocalMsgFileName = msgFileName;

      /* Set up and initialize the load input structure */
      memset(&loadInfoIn, '\0', sizeof(db2LoadIn));
      loadInfoIn.iNonrecoverable = SQLU_NON_RECOVERABLE_LOAD;
      loadInfoIn.iIndexingMode = SQLU_INX_AUTOSELECT;
      loadInfoIn.iAccessLevel = SQLU_ALLOW_NO_ACCESS;
      loadInfoIn.iLockWithForce = SQLU_NO_FORCE;
      loadInfoIn.iCheckPending = SQLU_CHECK_PENDING_CASCADE_DEFERRED;
      loadInfoIn.iRestartphase = ' ';
      loadInfoIn.iStatsOpt = SQLU_STATS_NONE;
      loadParms.piLoadInfoIn = (db2LoadIn*) &loadInfoIn;

      /* Set up and initialize the load output structure */
      memset(&loadInfoOut, '\0', sizeof(db2LoadOut));
      loadParms.poLoadInfoOut = (db2LoadOut*) &loadInfoOut;

      /* Set up the callerac to indicate this is an initial load operation */
      loadParms.iCallerAction = SQLU_INITIAL;

      /**********************************************************************
         * Set up the partitioning load input structure.
         *
         * NOTE: A value of NULL for any field in this structure will
         *       result in the default value for the option being used.
         *
         *       It is recommended that callers zero out the entire structure
         *       and then set up only those parameters that have non-default
         *       values.
         **********************************************************************/
      memset(&partLoadInfoIn, '\0', sizeof(db2PartLoadIn));

      /* Set the mode to PARTITION_AND_LOAD -- this is the default value */
      /* but we do it anyway just to show how it would be set up for   */
      /* non-default values                                              */
      mode = DB2LOAD_PARTITION_AND_LOAD;
      partLoadInfoIn.piMode = &mode;

      /* By setting piOutputNodes to NULL we are indicating that we      */
      /* want loading to take place on all nodes the table is defined    */
      /* on.Again, this is the default value, but we do it anyway for*/
      /* instructional purposes.                                       */
      partLoadInfoIn.piOutputNodes = NULL;

      /* Set up the piPartitioningNodes parameter to indicate that       */
      /* we want a partitioning agent on node 0.We will just show      */
      /* how to do this in a comment.For the real code we will use the */
      /* the default value, NULL, which will indicate to LOAD that it    */
      /* should try to select the best node(s) for partitioning.         */

      /* partitioningDbPartNums.iNumNodes = 1;
      partitioningDbPartNums.piNodeList =
      (SQL_PDB_NODE_TYPE *)malloc(1 * sizeof(SQL_PDB_NODE_TYPE));
      partitioningDbPartNums.piNodeList = 0;
      partLoadInfoIn.piPartitioningNodes = &partitioningDbPartNums; */

      partLoadInfoIn.piPartitioningNodes = NULL;

      /* Set up the error isolation mode to SETUP_AND_LOAD_ERRS */
      isolatePartErrs = DB2LOAD_SETUP_AND_LOAD_ERRS;
      partLoadInfoIn.piIsolatePartErrs = &isolatePartErrs;

      loadParms.piPartLoadInfoIn = &partLoadInfoIn;

      /**********************************************************************
         * Set up the partitioned load output structure
         **********************************************************************/
      memset(&partLoadInfoOut, '\0', sizeof(db2PartLoadOut));

      /* Reserve space for 100 agent info entries. In general, setting */
      /* iMaxAgentInfoEntries to 3 * <number of nodes> in cluster      */
      /* should be sufficient.                                       */
      partLoadInfoOut.iMaxAgentInfoEntries = 100;
      partLoadInfoOut.poAgentInfoList = (db2LoadAgentInfo*)malloc(sizeof(db2LoadAgentInfo) *100);

      loadParms.poPartLoadInfoOut = &partLoadInfoOut;

      /*********************************************************************
         * Call the db2Load API
         *********************************************************************/
      printf("\nLoad data.\n");
      printf("    client destination file name: %s\n", dataFileName);
      printf("    action                      : %s\n", pActionString);
      printf("    client message file name    : %s\n", msgFileName);

      db2Load(db2Version810,&loadParms,&sqlca);

      /* Display and warnings or errors */
      if (sqlca.sqlcode != 0)
      {
                printf("\nThe following error is expected for non-partitioned");
                printf(" database environments.\n");
                SqlInfoPrint("table -- load", &sqlca, __LINE__, __FILE__);
      }
      else
      {
                /* Display a partition-level summary of the load operation */
                PrintLoadSummary(loadParms.poLoadInfoOut, loadParms.poPartLoadInfoOut,&sqlca);
      }
      if (loadParms.piActionString != NULL)
      {
                free(loadParms.piActionString);
                loadParms.piActionString = NULL;
      }

      if (loadParms.piFileTypeMod != NULL)
      {
                free(loadParms.piFileTypeMod);
                loadParms.piFileTypeMod = NULL;
      }

      if (partitioningDbPartNums.piNodeList != NULL)
      {
                free(partitioningDbPartNums.piNodeList);
                loadParms.piFileTypeMod = NULL;
      }

      if (partLoadInfoOut.poAgentInfoList != NULL)
      {
                free(partLoadInfoOut.poAgentInfoList);
                partLoadInfoOut.poAgentInfoList = NULL;
      }
}




[ 本帖最后由 Law 于 2007-5-18 17:50 编辑 ]

goooole 发表于 2010-01-19 21:32

学习了
页: [1]
查看完整版本: DB2的API编程问题...(基于DB2数据库的应用开发研究)