免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5853 | 回复: 4
打印 上一主题 下一主题

DB2的API编程问题...(基于DB2数据库的应用开发研究) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-05-09 21:53 |只看该作者 |倒序浏览
请教下关于DB2的API编程.
要求我用数据处理API:EXPORT(凋出数据)、IMPORT(调入数据)、LOAD(调入数据)三个函数实现数据的整块调入调出.

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

论坛徽章:
11
数据库技术版块每日发帖之星
日期:2016-06-25 06:20:00数据库技术版块每日发帖之星
日期:2016-06-24 06:20:00数据库技术版块每日发帖之星
日期:2016-05-03 06:20:00数据库技术版块每日发帖之星
日期:2016-04-21 06:20:00数据库技术版块每日发帖之星
日期:2016-01-23 06:20:00数据库技术版块每日发帖之星
日期:2015-12-03 06:20:00综合交流区版块每周发帖之星
日期:2015-12-02 15:03:53数据库技术版块每日发帖之星
日期:2015-10-19 06:20:00数据库技术版块每日发帖之星
日期:2015-08-20 06:20:002015年辞旧岁徽章
日期:2015-03-03 16:54:15数据库技术版块每日发帖之星
日期:2016-07-30 06:20:00
2 [报告]
发表于 2007-05-10 21:01 |只看该作者
老大,直接看db2自带的例子就能搞定的!

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

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

论坛徽章:
0
3 [报告]
发表于 2007-05-14 22:07 |只看该作者
大梦大哥 ..可以帮下 弄弄吗?这个我没用弄过.一点头绪都没有.....


     谢    了...

论坛徽章:
0
4 [报告]
发表于 2007-05-18 17:44 |只看该作者
db2 v8 load API,db2load810封装的例子程序,核心函数是调用db2的db2Load(..),db2load 主要是初始化参数很麻烦



  1. int db2load810(char *sTabName, char *sSourceFile,char *sColDel,char *sLoadMegFile)
  2. {
  3.         char dataFileName[256];
  4.         char msgFileName[128];
  5.         struct sqldcol dataDescriptor;
  6.         char actionString[256];

  7.         db2LoadStruct loadParms;
  8.         char pActionString[128];
  9.         char pFileTypeModString[128];
  10.         sqlu_media_list loadMediaList;
  11.         sqlu_location_entry inputLocationEntry;
  12.         db2LoadIn loadInfoIn;
  13.         db2LoadOut loadInfoOut;
  14.         db2PartLoadIn partLoadInfoIn;
  15.         db2PartLoadOut partLoadInfoOut;
  16.         db2LoadNodeList partitioningDbPartNums;
  17.         db2Uint16 mode;
  18.         db2Uint16 isolatePartErrs;
  19.         



  20.         sprintf(dataFileName,"%s",sSourceFile);
  21.         sprintf(msgFileName,"%s",sLoadMegFile);
  22.         sprintf(pFileTypeModString,"%s coldel%s ","ANYORDER ",sColDel);
  23.         printf("%s\n",sTabName);
  24.         sprintf(pActionString," insert into  %s",sTabName);
  25.         printf("%s\n",pActionString);
  26.        
  27.         printf("\n--------------------------------------------------------\n");
  28.         printf("\nUSE THE DB2 API:\n");
  29.         printf("  db2Load -- Load\n");
  30.         printf("TO LOAD DATA TO A PARTITIONED DATABASE TABLE.\n");
  31.         memset(&loadParms, '\0', sizeof(db2LoadStruct));

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

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

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

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

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

  57.         /* Set up and initialize the load input structure */
  58.         memset(&loadInfoIn, '\0', sizeof(db2LoadIn));
  59.         loadInfoIn.iNonrecoverable = SQLU_NON_RECOVERABLE_LOAD;
  60.         loadInfoIn.iIndexingMode = SQLU_INX_AUTOSELECT;
  61.         loadInfoIn.iAccessLevel = SQLU_ALLOW_NO_ACCESS;
  62.         loadInfoIn.iLockWithForce = SQLU_NO_FORCE;
  63.         loadInfoIn.iCheckPending = SQLU_CHECK_PENDING_CASCADE_DEFERRED;
  64.         loadInfoIn.iRestartphase = ' ';
  65.         loadInfoIn.iStatsOpt = SQLU_STATS_NONE;
  66.         loadParms.piLoadInfoIn = (db2LoadIn*) &loadInfoIn;

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

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

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

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

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

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

  98.         /* partitioningDbPartNums.iNumNodes = 1;
  99.         partitioningDbPartNums.piNodeList =
  100.         (SQL_PDB_NODE_TYPE *)malloc(1 * sizeof(SQL_PDB_NODE_TYPE));
  101.         partitioningDbPartNums.piNodeList[0] = 0;
  102.         partLoadInfoIn.piPartitioningNodes = &partitioningDbPartNums; */

  103.         partLoadInfoIn.piPartitioningNodes = NULL;

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

  107.         loadParms.piPartLoadInfoIn = &partLoadInfoIn;

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

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

  117.         loadParms.poPartLoadInfoOut = &partLoadInfoOut;

  118.         /*********************************************************************
  119.          * Call the db2Load API
  120.          *********************************************************************/
  121.         printf("\n  Load data.\n");
  122.         printf("    client destination file name: %s\n", dataFileName);
  123.         printf("    action                      : %s\n", pActionString);
  124.         printf("    client message file name    : %s\n", msgFileName);

  125.         db2Load(db2Version810,  &loadParms,  &sqlca);

  126.         /* Display and warnings or errors */
  127.         if (sqlca.sqlcode != 0)
  128.         {
  129.                 printf("\nThe following error is expected for non-partitioned");
  130.                 printf(" database environments.\n");
  131.                 SqlInfoPrint("table -- load", &sqlca, __LINE__, __FILE__);
  132.         }
  133.         else
  134.         {
  135.                 /* Display a partition-level summary of the load operation */
  136.                 PrintLoadSummary(loadParms.poLoadInfoOut, loadParms.poPartLoadInfoOut,  &sqlca);
  137.         }
  138.         if (loadParms.piActionString != NULL)
  139.         {
  140.                 free(loadParms.piActionString);
  141.                 loadParms.piActionString = NULL;
  142.         }

  143.         if (loadParms.piFileTypeMod != NULL)
  144.         {
  145.                 free(loadParms.piFileTypeMod);
  146.                 loadParms.piFileTypeMod = NULL;
  147.         }

  148.         if (partitioningDbPartNums.piNodeList != NULL)
  149.         {
  150.                 free(partitioningDbPartNums.piNodeList);
  151.                 loadParms.piFileTypeMod = NULL;
  152.         }

  153.         if (partLoadInfoOut.poAgentInfoList != NULL)
  154.         {
  155.                 free(partLoadInfoOut.poAgentInfoList);
  156.                 partLoadInfoOut.poAgentInfoList = NULL;
  157.         }
  158. }


复制代码

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

论坛徽章:
0
5 [报告]
发表于 2010-01-19 21:32 |只看该作者
学习了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP