示例#1
0
文件: attr.c 项目: Vachman/STMT
static VALUE get_rowid_attr(rowid_arg_t *arg)
{
    oci8_base_t *base = arg->base;
    ub4 attrtype = arg->attrtype;
    char buf[MAX_ROWID_LEN];
    ub2 buflen;
    sword rv;

    /* get a rowid descriptor from OCIHandle */
    rv = OCIDescriptorAlloc(oci8_envhp, (dvoid*)&arg->ridp, OCI_DTYPE_ROWID, 0, NULL);
    if (rv != OCI_SUCCESS)
        oci8_env_raise(oci8_envhp, rv);
    rv = OCIAttrGet(base->hp.ptr, base->type, arg->ridp, 0, attrtype, oci8_errhp);
    if (rv != OCI_SUCCESS) {
        oci8_raise(oci8_errhp, rv, NULL);
    }
    /* convert the rowid descriptor to a string. */
    if (have_OCIRowidToChar) {
        /* If OCIRowidToChar is available, use it. */
        buflen = MAX_ROWID_LEN;
        rv = OCIRowidToChar(arg->ridp, TO_ORATEXT(buf), &buflen, oci8_errhp);
        if (rv != OCI_SUCCESS) {
            oci8_raise(oci8_errhp, rv, NULL);
        }
    } else {
        /* If OCIRowidToChar is not available, convert it on
         * Oracle Server.
         */
        oci8_base_t *svc;
        oci8_exec_sql_var_t define_var;
        oci8_exec_sql_var_t bind_var;

        /* search a connection from the handle */
        svc = base;
        while (svc->type != OCI_HTYPE_SVCCTX) {
            svc = svc->parent;
            if (svc == NULL) {
                rb_raise(rb_eRuntimeError, "No connection is found!!");
            }
        }
        /* :strval */
        define_var.valuep = buf;
        define_var.value_sz = sizeof(buf);
        define_var.dty = SQLT_CHR;
        define_var.indp = NULL;
        define_var.alenp = &buflen;
        /* :rowid */
        bind_var.valuep = &arg->ridp;
        bind_var.value_sz = sizeof(void *);
        bind_var.dty = SQLT_RDD;
        bind_var.indp = NULL;
        bind_var.alenp = NULL;
        /* convert the rowid descriptor to a string value by querying Oracle server. */
        oci8_exec_sql((oci8_svcctx_t*)svc, "SELECT :rid FROM dual", 1, &define_var, 1, &bind_var, 1);
        if (buflen == 0) {
            return Qnil;
        }
    }
    return rb_external_str_new_with_enc(buf, buflen, rb_usascii_encoding());
}
示例#2
0
tstring BindParRid::get_string(unsigned int i) const
{
	if(indp[i] == OCI_IND_NULL)
		return "";
	OraText buffer[4001];
	ub2 outbfl = sizeof(buffer);
	sword res = OCICALL(OCIRowidToChar(((OCIRowid**)valuep)[i], buffer, &outbfl, _stmt._errh));
	oci_check_error(__TROTL_HERE__, _stmt._errh, res);
	return tstring((char*)buffer, outbfl);
}
示例#3
0
/*---------------------------------------------------------------------
 * getRowID - Get RowID of this ID Key LCR
 *---------------------------------------------------------------------*/
static sword getRowID (myctx_t* ctxp, void* lcrp, oratext* rowid, ub2* len)
{
  oci_t   *ocip = ctxp->outbound_ocip;
  ub2      i = 0;      
  ub2      num_attrs = 0;
  void    *attr_value[OCI_LCR_MAX_ATTRIBUTES];
  oratext *attr_name [OCI_LCR_MAX_ATTRIBUTES];
  ub2      attr_namel[OCI_LCR_MAX_ATTRIBUTES];
  ub2      attr_dty[OCI_LCR_MAX_ATTRIBUTES];
  OCIInd   attr_ind[OCI_LCR_MAX_ATTRIBUTES];
  ub2      attr_len[OCI_LCR_MAX_ATTRIBUTES];

  if (rowid == NULL)
    return OCI_ERROR;

  /* get the attributes for this lcr */
  OCICALL(ocip, OCILCRAttributesGet(ocip->svcp, ocip->errp,
                                &num_attrs, attr_name, attr_namel, attr_dty,
                                attr_value, attr_ind, attr_len, lcrp,
                                OCI_LCR_MAX_ATTRIBUTES, OCI_DEFAULT));

  if (num_attrs == 0)
    return OCI_ERROR;

  for (i = 0; i < num_attrs; i++)
  {
    /* filter out Row_ID for this LCR */
    if ((attr_ind[i] != OCI_IND_NULL) &&
        !strncmp ((const char*)attr_name[i], OCI_LCR_ATTR_ROW_ID,
                  attr_namel[i]) &&
        (attr_dty[i] == SQLT_RDD))
    {
          OCIRowid  *rid = attr_value[i];
          oratext    rid_buf[80];
          ub2        reslen = (ub2)sizeof(rid_buf);

          OCICALL(ocip,
                  OCIRowidToChar(rid, rid_buf, &reslen, ocip->errp));

          memcpy (rowid, rid_buf, reslen);
          *len = reslen;
          return OCI_SUCCESS;
    }
  }
  return OCI_ERROR;
}
示例#4
0
/*---------------------------------------------------------------------
 * print_lcr_data - Print all the columns include ADT in this ROW LCR
 *---------------------------------------------------------------------*/
static sb4 process_lcr_data(myctx_t *ctxp, void *lcrp, ub2 col_value_type,
                            boolean seqlcr)
{
  ub2        collist_type;
  ub2        num_cols;
  oratext   *colname[MAX_COLUMNS]; 
  ub2        colnamel[MAX_COLUMNS]; 
  ub2        coldty[MAX_COLUMNS]; 
  void      *colval[MAX_COLUMNS]; 
  ub2        collen[MAX_COLUMNS]; 
  OCIInd     colind[MAX_COLUMNS]; 
  ub1        colcsf[MAX_COLUMNS]; 
  oraub8     colflg[MAX_COLUMNS]; 
  ub2        colcsid[MAX_COLUMNS]; 
  sword      ret;
  ub2        idx;
  oci_t     *ocip = ctxp->outbound_ocip;
  oratext    buf[80];
  ub4        mode;
  
  printf ("process_lcr_data col_value_type=%s\n",
          col_value_type == OCI_LCR_ROW_COLVAL_OLD ? "OLD" : "NEW");

  if (OCI_LCR_ROW_COLVAL_OLD == col_value_type)
  {
    mode = OCI_DEFAULT;
  }
  else
  {
    /* Only want new columns */
    mode = OCI_DEFAULT | OCILCR_NEW_ONLY_MODE;
  }
  
  ret = OCILCRRowColumnInfoGet(ocip->svcp, ocip->errp, col_value_type, 
                               &num_cols, (oratext **)&colname, 
                               (ub2 *)&colnamel,
                               (ub2 *)&coldty, (void **)&colval, 
                               (OCIInd *)&colind, (ub2 *)&collen, 
                               (ub1 *)&colcsf, (oraub8*)colflg, (ub2 *)colcsid,
                               lcrp, MAX_COLUMNS, mode);
  
  if (ret != OCI_SUCCESS)
  {
    ocierror(ocip, (char *)"OCILCRRowColumnInfoGet failed ", FALSE);
    return ret;
  }
  printf ("num_columns=%d \n", num_cols); 

  /* if num_colums = 0, we need to check if the data is unsupported type */
  if (num_cols == 0) return OCI_STILL_EXECUTING;

  for (idx = 0; idx < num_cols; idx++)
  {
    printf ("Column[%d](name,dty,ind,len,csf): %.*s %d %d %d %d", idx+1,
             colnamel[idx], colname[idx], coldty[idx], colind[idx],
             collen[idx], colcsf[idx]);

    if (colind[idx] == OCI_IND_NULL)
      printf(" value=NULL");
    else
    {
      ub2  printlen;

      switch (coldty[idx])
      {
        case SQLT_AFC:
        case SQLT_CHR:
          /* print out max of MAX_PRINT_BYTES bytes of data */
          if (collen[idx] > MAX_PRINT_BYTES)
            printlen = MAX_PRINT_BYTES;
          else
            printlen = collen[idx];
          printf (" value=%.*s", printlen, colval[idx]);
          break;
        case SQLT_VNU:
        {
          OCINumber  *rawnum = colval[idx];

          printf (" value=");
          print_number(ocip, rawnum, seqlcr);
          break;
        }
        case SQLT_ODT:
        {
          OCIDate    *datevalue = colval[idx];

          printf (" value(mm/dd/yyyy hh:mi:ss)=%d/%d/%d %d:%d:%d", 
                  datevalue->OCIDateMM, datevalue->OCIDateDD, 
                  datevalue->OCIDateYYYY, datevalue->OCIDateTime.OCITimeHH,
                  datevalue->OCIDateTime.OCITimeMI,
                  datevalue->OCIDateTime.OCITimeSS);
          break;
        }
        case SQLT_BFLOAT:
        {
          float      *fltvalue = colval[idx];

          printf (" value=%f ", *fltvalue);
          break;
        }
        case SQLT_BDOUBLE:
        {
          double     *dblvalue = colval[idx];

          printf (" value=%f ", *dblvalue);
          break;
        }
        case SQLT_TIMESTAMP:
        case SQLT_TIMESTAMP_LTZ:
        {
          OCIDateTime  *dtvalue = colval[idx];
          ub4           bufsize = sizeof(buf);
          sword         ret = OCI_SUCCESS;
          
          ret = OCIDateTimeToText(ocip->envp, ocip->errp,
                                  dtvalue, TS_FORMAT,
                                  (ub1) strlen((const char *)TS_FORMAT),
                                  (ub1) 6, (const oratext*)0, (size_t) 0,
                                  &bufsize, buf);
          if (!ret)
          {
            printf (" value=%.*s ", bufsize, buf);
          }
          else
          {
            /* tklmqa02t.sql was having issues printing C_TS for update 2.4.1.
             * The column data itself looks good, unclear why it failed. For
             * now, if we get an error converting, just print this out.
             */
            printf (" cannot convert timestamp ");
          }
          break;
        }
        case SQLT_TIMESTAMP_TZ:
        {
          OCIDateTime  *dtvalue = colval[idx];
          ub4           bufsize = sizeof(buf);

          OCICALL(ocip,
                  OCIDateTimeToText(ocip->envp, ocip->errp,
                                    dtvalue, TSZ_FORMAT,
                                    (ub1) strlen((const char *)TSZ_FORMAT),
                                    (ub1) 6, (const oratext*)0, (size_t) 0,
                                    &bufsize, buf)); 
          printf (" value=%.*s ", bufsize, buf);
          
          break;
        }
        case SQLT_INTERVAL_YM:
        case SQLT_INTERVAL_DS:
        {
          OCIInterval  *intv = colval[idx];
          size_t        reslen;

          OCICALL(ocip,
                  OCIIntervalToText(ocip->envp, ocip->errp,
                                    intv, 9, 6, buf, sizeof(buf), &reslen)); 
          printf (" value=%.*s ", reslen, buf);
          
          break;
        }
        case SQLT_RDD:
        {
          OCIRowid     *rid = colval[idx];
          ub2           reslen = (ub2)sizeof(buf);

          OCICALL(ocip,
                  OCIRowidToChar(rid, buf, &reslen, ocip->errp)); 
          printf (" value=%.*s ", reslen, buf);
          
          break;
        }
        default:
        {
          ub2  idx2; 
          ub1 *byteptr = (ub1 *)colval[idx];

          /* dump out raw bytes */
          printf (" dty=%d collen=%d\n", coldty[idx], collen[idx]);
          /* print out max of MAX_PRINT_BYTES bytes of data */
          if (collen[idx] > MAX_PRINT_BYTES)
            printlen = MAX_PRINT_BYTES;
          else
            printlen = collen[idx];
          for (idx2 = 0; idx2 < printlen; idx2++)
            printf("%02x ", byteptr[idx2]); 
          printf("\n");
          break;
        }
      }
    }
    printf ("\n");
  }
  return ret;
}