⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cdemodp.c

📁 调用OCI的C++类
💻 C
📖 第 1 页 / 共 5 页
字号:
STATICF void init_obj_load(ctlp, tblp, objp)struct loadctl *ctlp;struct tbl     *tblp;struct obj     *objp;{  struct  col   *colp;  struct  fld   *fldp;  sword          ociret;                       /* return code from OCI calls*/  ub2            i;  ub4            pos;  ub2            numCols;  ub4            len;  ub2            type;  ub1            exprtype;  ub1            parmtyp;  OCIParam      *colDesc;                     /* column parameter descriptor*/  OCIParam      *objColLstDesc;               /* obj col's list param handle*/  /*   * create a context for this object type and describe the attributes   * that will be loaded for this object.   */  OCI_CHECK(ctlp->envhp_ctl, OCI_HTYPE_ENV, ociret, ctlp,            OCIHandleAlloc((dvoid *)ctlp->dpctx_ctl,                           (dvoid **)&(objp->ctx_obj),                           (ub4)OCI_HTYPE_DIRPATH_FN_CTX,                           (size_t)0, (dvoid **)0));  /* If col is an obj, then its constructor is the type name. (req.)   * If col is an opaque/sql function, then use the expression given. (req.)   * If col is a ref, then can set a fixed tbl name.  (optional)    */ if (objp->name_obj)             /* if expression is available */ {  OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,            OCIAttrSet((dvoid *)(objp->ctx_obj),                       (ub4)OCI_HTYPE_DIRPATH_FN_CTX,                       (dvoid *) objp->name_obj,                       (ub4)strlen((const char *) objp->name_obj),                       (ub4)OCI_ATTR_NAME, ctlp->errhp_ctl));  /* Set the expression type to obj constructor, opaque/sql function, or ref   * table name.   */  if (bit(objp->flag_obj, OBJ_OBJ))    exprtype = OCI_DIRPATH_EXPR_OBJ_CONSTR;   /* expr is an obj constructor */  else if (bit(objp->flag_obj, OBJ_OPQ))    exprtype = OCI_DIRPATH_EXPR_SQL;          /* expr is an opaque/sql func */  else if (bit(objp->flag_obj, OBJ_REF))    exprtype = OCI_DIRPATH_EXPR_REF_TBLNAME;   /* expr is a ref table name  */  OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,            OCIAttrSet((dvoid *)(objp->ctx_obj),                       (ub4)OCI_HTYPE_DIRPATH_FN_CTX,                       (dvoid *) &exprtype,                       (ub4) 0,                       (ub4)OCI_ATTR_DIRPATH_EXPR_TYPE, ctlp->errhp_ctl)); }  /* set number of columns to be loaded */  numCols = objp->ncol_obj;  OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,            OCIAttrSet((dvoid *)(objp->ctx_obj),                       (ub4)OCI_HTYPE_DIRPATH_FN_CTX,                       (dvoid *)&numCols,                       (ub4)0, (ub4)OCI_ATTR_NUM_COLS, ctlp->errhp_ctl));  /* get the column parameter list */  OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,            OCIAttrGet((dvoid *)(objp->ctx_obj),                       OCI_HTYPE_DIRPATH_FN_CTX,                       (dvoid *)&objColLstDesc, (ub4 *)0,                       OCI_ATTR_LIST_COLUMNS, ctlp->errhp_ctl));  /* get attributes of the column parameter list */  OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,            OCIAttrGet((CONST dvoid *)objColLstDesc,                       OCI_DTYPE_PARAM,                       (dvoid *)&parmtyp, (ub4 *)0,                       OCI_ATTR_PTYPE, ctlp->errhp_ctl));  if (parmtyp != OCI_PTYPE_LIST)  {    fprintf(output_fp,            "ERROR: expected parmtyp of OCI_PTYPE_LIST, got %d\n",            (int)parmtyp);  }  /* Now set the attributes of each column by getting a parameter   * handle on each column, then setting attributes on the parameter   * handle for the column.   * Note that positions within a column list descriptor are 1-based.   */  for (i = 0, pos = 1, colp = objp->col_obj, fldp = objp->fld_obj;       i < objp->ncol_obj;       i++, pos++, colp++, fldp++)  {    /* get parameter handle on the column */    OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,              OCIParamGet((CONST dvoid *)objColLstDesc,                          (ub4)OCI_DTYPE_PARAM, ctlp->errhp_ctl,                          (dvoid **)&colDesc, pos));    colp->id_col = i;                            /* position in column array*/    /* set external attributes on the column */    /* column name */    OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,              OCIAttrSet((dvoid *)colDesc, (ub4)OCI_DTYPE_PARAM,                         (dvoid *)colp->name_col,                         (ub4)strlen((const char *)colp->name_col),                         (ub4)OCI_ATTR_NAME, ctlp->errhp_ctl));    /* column type */    OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,              OCIAttrSet((dvoid *)colDesc, (ub4)OCI_DTYPE_PARAM,                         (dvoid *)&colp->exttyp_col, (ub4)0,                         (ub4)OCI_ATTR_DATA_TYPE, ctlp->errhp_ctl));    /* max data size */    OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,              OCIAttrSet((dvoid *)colDesc, (ub4)OCI_DTYPE_PARAM,                         (dvoid *)&fldp->maxlen_fld, (ub4)0,                         (ub4)OCI_ATTR_DATA_SIZE, ctlp->errhp_ctl));    /* If column is chrdate or date, set column (input field) date mask     * to trigger client library to check string for a valid date.     * Note: OCIAttrSet() may be called here w/ a null ptr or null string.     */    if (colp->date_col)    {      OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,                OCIAttrSet((dvoid *)colDesc, (ub4)OCI_DTYPE_PARAM,                         (dvoid *)colp->datemask_col,                         (colp->datemask_col) ?                           (ub4)strlen((const char *)colp->datemask_col) :0,                         (ub4)OCI_ATTR_DATEFORMAT, ctlp->errhp_ctl));    }    if (colp->prec_col)    {      OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,                OCIAttrSet((dvoid *)colDesc, (ub4)OCI_DTYPE_PARAM,                         (dvoid *)&colp->prec_col, (ub4)0,                         (ub4)OCI_ATTR_PRECISION, ctlp->errhp_ctl));    }    if (colp->scale_col)    {      OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,                OCIAttrSet((dvoid *)colDesc, (ub4)OCI_DTYPE_PARAM,                         (dvoid *)&colp->scale_col, (ub4)0,                         (ub4)OCI_ATTR_SCALE, ctlp->errhp_ctl));    }    if (colp->csid_col)    {      OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,                OCIAttrSet((dvoid *)colDesc, (ub4)OCI_DTYPE_PARAM,                         (dvoid *)&colp->csid_col, (ub4)0,                         (ub4)OCI_ATTR_CHARSET_ID, ctlp->errhp_ctl));    }    /* If this is an object, opaque or ref then recurse */    if (colp->exttyp_col == SQLT_NTY || colp->exttyp_col == SQLT_REF)    {      init_obj_load(ctlp, tblp, colp->obj_col);      /* set the object function context into the param handle */      OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,                OCIAttrSet((dvoid *)colDesc, (ub4)OCI_DTYPE_PARAM,                           (dvoid *)(colp->obj_col->ctx_obj), (ub4)0,                           (ub4)OCI_ATTR_DIRPATH_FN_CTX, ctlp->errhp_ctl));    }    /* free the parameter handle to the column descriptor */    OCI_CHECK((dvoid *)0, 0, ociret, ctlp,              OCIDescriptorFree((dvoid *)colDesc, OCI_DTYPE_PARAM));  }}/***++++++++++++++++++++++++++++++ init_load +++++++++++++++++++++++++++++++++****  Description:****   Function which prepares for a direct path load using the direct**   path API on the table described by 'tblp'.****  Assumptions:****  The loadctl structure given by 'ctlp' has an appropriately initialized**  environment, and service context handles (already connected to**  the server) prior to calling this function.****  Parameters:****  ctlp                           load control structure pointer**  tblp                           table pointer **  sessp                          session pointer****  Returns:****-------------------------------------------------------------------------*/STATICF void init_load(ctlp, tblp, sessp)struct loadctl *ctlp;                      /* load control structure pointer */struct tbl     *tblp;                      /* table pointer   */struct sess    *sessp;                     /* session pointer */{  struct  col   *colp;  struct  fld   *fldp;  sword         ociret;                    /* return code from OCI calls */  OCIDirPathCtx *dpctx;                    /* direct path context */  OCIParam      *objAttrDesc;              /* attribute parameter descriptor */  OCIParam      *colDesc;                  /* column parameter descriptor */  ub1            parmtyp;  ub1           *timestamp = (ub1 *)0;  ub4            size;  ub2            i;  ub4            pos;  ub1            dirpathinput = OCI_DIRPATH_INPUT_TEXT;  /* allocate and initialize a direct path context */  OCI_CHECK(ctlp->envhp_ctl, OCI_HTYPE_ENV, ociret, ctlp,            OCIHandleAlloc((dvoid *)ctlp->envhp_ctl,                           (dvoid **)&ctlp->dpctx_ctl,                           (ub4)OCI_HTYPE_DIRPATH_CTX,                           (size_t)0, (dvoid **)0));  dpctx = ctlp->dpctx_ctl;                                      /* shorthand*/  OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,            OCIAttrSet((dvoid *)dpctx, (ub4)OCI_HTYPE_DIRPATH_CTX,                       (dvoid *)tblp->name_tbl,                       (ub4)strlen((const char *)tblp->name_tbl),                       (ub4)OCI_ATTR_NAME, ctlp->errhp_ctl));  if (tblp->subname_tbl && *tblp->subname_tbl)    /* set (sub)partition name*/  {    OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,              OCIAttrSet((dvoid *)dpctx, (ub4)OCI_HTYPE_DIRPATH_CTX,                         (dvoid *)tblp->subname_tbl,                         (ub4)strlen((const char *)tblp->subname_tbl),                         (ub4)OCI_ATTR_SUB_NAME, ctlp->errhp_ctl));  }  if (tblp->owner_tbl)                            /* set schema (owner) name*/  {    OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,              OCIAttrSet((dvoid *)dpctx, (ub4)OCI_HTYPE_DIRPATH_CTX,                         (dvoid *)tblp->owner_tbl,                         (ub4)strlen((const char *)tblp->owner_tbl),                         (ub4)OCI_ATTR_SCHEMA_NAME, ctlp->errhp_ctl));  }  /* Note: setting tbl default datemask will not trigger client library   * to check strings for dates - only setting column datemask will.   */  if (tblp->dfltdatemask_tbl)  {    OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,              OCIAttrSet((dvoid *)dpctx, (ub4)OCI_HTYPE_DIRPATH_CTX,                         (dvoid *)tblp->dfltdatemask_tbl,                         (ub4)strlen((const char *)tblp->dfltdatemask_tbl),                         (ub4)OCI_ATTR_DATEFORMAT, ctlp->errhp_ctl));  }  /* set the data input type to be text */  OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,            OCIAttrSet ((dvoid *)dpctx, OCI_HTYPE_DIRPATH_CTX,                        (dvoid *)&dirpathinput, (ub4)0,                        OCI_ATTR_DIRPATH_INPUT, ctlp->errhp_ctl));  if (tblp->parallel_tbl)                 /* set table level parallel option*/  {    OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,              OCIAttrSet((dvoid *)dpctx, (ub4)OCI_HTYPE_DIRPATH_CTX,                         (dvoid *)&tblp->parallel_tbl,                         (ub4)0, (ub4)OCI_ATTR_DIRPATH_PARALLEL,                         ctlp->errhp_ctl));  }  if (tblp->nolog_tbl)                       /* set table level nolog option*/  {    OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,              OCIAttrSet((dvoid *)dpctx, (ub4)OCI_HTYPE_DIRPATH_CTX,                         (dvoid *)&tblp->nolog_tbl, (ub4)0,                         (ub4)OCI_ATTR_DIRPATH_NOLOG, ctlp->errhp_ctl));  }  if (tblp->objconstr_tbl)         /* set obj type of tbl to load if exists */    OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,              OCIAttrSet((dvoid *)dpctx,                         (ub4)OCI_HTYPE_DIRPATH_CTX,                         (dvoid *) tblp->objconstr_tbl,                         (ub4)strlen((const char *) tblp->objconstr_tbl),                         (ub4)OCI_ATTR_DIRPATH_OBJ_CONSTR, ctlp->errhp_ctl));  /* set number of columns to be loaded */  OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,            OCIAttrSet((dvoid *)dpctx, (ub4)OCI_HTYPE_DIRPATH_CTX,                       (dvoid *)&tblp->ncol_tbl,                       (ub4)0, (ub4)OCI_ATTR_NUM_COLS, ctlp->errhp_ctl));  /* get the column parameter list */  OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,            OCIAttrGet((dvoid *)dpctx,                       OCI_HTYPE_DIRPATH_CTX,                       (dvoid *)&ctlp->colLstDesc_ctl, (ub4 *)0,                       OCI_ATTR_LIST_COLUMNS, ctlp->errhp_ctl));  /* get attributes of the column parameter list */  OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,            OCIAttrGet((CONST dvoid *)ctlp->colLstDesc_ctl,                       OCI_DTYPE_PARAM,                       (dvoid *)&parmtyp, (ub4 *)0,                       OCI_ATTR_PTYPE, ctlp->errhp_ctl));  if (parmtyp != OCI_PTYPE_LIST)  {    fprintf(output_fp, "ERROR: expected parmtyp of OCI_PTYPE_LIST, got%d\n",            (int)parmtyp);  }  /* Now set the attributes of each column by getting a parameter   * handle on each column, then setting attributes on the parameter   * handle for the column.   * Note that positions within a column list descriptor are 1-based.   */  for (i = 0, pos = 1, colp = tblp->col_tbl, fldp = tblp->fld_tbl;       i < tblp->ncol_tbl;       i++, pos++, colp++, fldp++)  {    /* get parameter handle on the column */    OCI_CHECK(ctlp->errhp_ctl, OCI_HTYPE_ERROR, ociret, ctlp,              OCIParamGet((CONST dvoid *)ctlp->colLstDesc_ctl,                          (ub4)OCI_DTYPE_PARAM, ctlp->errhp_ctl,                          (dvoid **)&colDesc, pos));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -