コード例 #1
0
ファイル: xoidkey.c プロジェクト: RicardoVivas/oracle-scripts
/*---------------------------------------------------------------------
 * print_pos - Print CSCN and SCN for this LCR
 *---------------------------------------------------------------------*/
static void print_pos(oci_t *ocip, ub1 *pos, ub2 poslen, char *comm)
{
  sword        ret;
  OCINumber    scn;
  OCINumber    cscn;
  ub4          numval;

  printf("%s=", comm);
  print_raw(pos, poslen);
  printf("\n");
  ret = OCILCRSCNsFromPosition(ocip->svcp, ocip->errp,
                               pos, poslen, &scn, &cscn, OCI_DEFAULT);
  if (ret != OCI_SUCCESS)
    printf ("OCILCRNumberFromPosition ERROR %d\n", ret);

  ret = OCINumberToInt(ocip->errp, (const OCINumber *)&cscn,
                       sizeof(numval), OCI_NUMBER_UNSIGNED, &numval);

  printf("  Position CSCN=%d ", numval);

  ret = OCINumberToInt(ocip->errp, (const OCINumber *)&scn,
                       sizeof(numval), OCI_NUMBER_UNSIGNED, &numval);

  printf("  SCN=%d\n", numval);
}
sword _fetchDataIntoLongintArray(ORACLE_SQL_CURSOR *cursor, PA_Variable variable, unsigned int pos)
{		
	if(cursor->rowsFetched)
	{			
		unsigned int itemCount = cursor->rowsFetched < cursor->itemCount ? cursor->rowsFetched : cursor->itemCount;
		
		//to clear the content of element #0, if any
		PA_ResizeArray(&variable, 0);
		PA_ResizeArray(&variable, itemCount);
		
		int intValue;
		
		for(unsigned int i = 0; i < itemCount; ++i)
		{	
			PA_YieldAbsolute();

			if(cursor->indicatorLists.at(pos).at(i) != -1)
			{		
				OCINumberToInt(cursor->errhp, &cursor->arrayOfNumbers.at(pos).at(i), sizeof(int), OCI_NUMBER_SIGNED, &intValue);
				PA_SetLongintInArray(variable, i + 1, intValue);
									
			}else{
				setLongintArrayValueNull(variable, i + 1);
			}
			
		}
		
		PA_SetPointerValue(&cursor->pointers.at(pos), variable);	
		
	}
		
	return cursor->rowsFetched;	
}
コード例 #3
0
ファイル: oci_wrapper.cpp プロジェクト: AsherBond/MondocosmOS
int OWStatement::GetElement( OCIArray** ppoData, int nIndex, int* pnResult )
{
    boolean        exists;
    OCINumber      *oci_number;
    ub4            element_type;

    *pnResult = 0;

    if( CheckError( OCICollGetElem(
        poConnection->hEnv,
        hError,
        (OCIColl*) *ppoData,
        (sb4) nIndex,
        (boolean*) &exists,
        (dvoid**) (dvoid*) &oci_number,
        (dvoid**) NULL ), hError ) )
    {
        return *pnResult;
    }

    if( CheckError( OCINumberToInt(
        hError,
        oci_number,
        (uword) sizeof(ub4),
        OCI_NUMBER_UNSIGNED,
        (dvoid *) &element_type ), hError ) )
    {
        return *pnResult;
    }

    *pnResult = (int) element_type;

    return *pnResult;
}
コード例 #4
0
ファイル: NumberVar.c プロジェクト: amansubhan/pysms
//-----------------------------------------------------------------------------
// NumberVar_GetValue()
//   Returns the value stored at the given array position.
//-----------------------------------------------------------------------------
static PyObject *NumberVar_GetValue(
    udt_NumberVar *var,                 // variable to determine value for
    unsigned pos)                       // array position
{
    PyObject *result, *stringObj;
    char stringValue[200];
    long integerValue;
    ub4 stringLength;
    sword status;

    if (var->type == &vt_Boolean || var->type == &vt_Integer) {
        status = OCINumberToInt(var->environment->errorHandle, &var->data[pos],
                sizeof(long), OCI_NUMBER_SIGNED, (dvoid*) &integerValue);
        if (Environment_CheckForError(var->environment, status,
                "NumberVar_GetValue(): as integer") < 0)
            return NULL;

        if (var->type == &vt_Boolean)
            return PyBool_FromLong(integerValue);
#if PY_MAJOR_VERSION >= 3
        return PyLong_FromLong(integerValue);
#else
        return PyInt_FromLong(integerValue);
#endif
    }

    if (var->type == &vt_NumberAsString || var->type == &vt_LongInteger) {
        stringLength = sizeof(stringValue);
        status = OCINumberToText(var->environment->errorHandle,
                &var->data[pos],
                (text*) var->environment->numberToStringFormatBuffer.ptr,
                var->environment->numberToStringFormatBuffer.size, NULL, 0,
                &stringLength, (unsigned char*) stringValue);
        if (Environment_CheckForError(var->environment, status,
                "NumberVar_GetValue(): as string") < 0)
            return NULL;
        stringObj = cxString_FromEncodedString(stringValue, stringLength,
                var->environment->encoding);
        if (!stringObj)
            return NULL;
        if (var->type == &vt_NumberAsString)
            return stringObj;
#if PY_MAJOR_VERSION >= 3
        result = PyNumber_Long(stringObj);
#else
        result = PyNumber_Int(stringObj);
#endif
        Py_DECREF(stringObj);
        if (result || !PyErr_ExceptionMatches(PyExc_ValueError))
            return result;
        PyErr_Clear();
    }

    return OracleNumberToPythonFloat(var->environment, &var->data[pos]);
}
コード例 #5
0
ファイル: oci_wrapper.cpp プロジェクト: AsherBond/MondocosmOS
int OWStatement::GetInteger( OCINumber* ppoData )
{
    sb4 nRetVal;

    CheckError( OCINumberToInt(
        hError,
        ppoData,
        (uword) sizeof(sb4),
        OCI_NUMBER_SIGNED,
        (dvoid *) &nRetVal ),
        hError );

    return nRetVal;
}
コード例 #6
0
ファイル: oci_types.c プロジェクト: metasyntax/ociml
value caml_oci_get_int(value handles, value defs) {
  CAMLparam2(handles, defs);
  oci_define_t d = Oci_defhandle_val(defs);
  oci_handles_t h = Oci_handles_val(handles);

  int r;

  sword x = OCINumberToInt(h.err, d.ptr, sizeof(int), OCI_NUMBER_SIGNED, &r);
  CHECK_OCI(x, h);

#ifdef DEBUG
  char dbuf[256]; snprintf(dbuf, 255, "caml_oci_get_int: returning %d", r); debug(dbuf);
#endif

  CAMLreturn(Val_int(r));
}
コード例 #7
0
ファイル: ocinumber.c プロジェクト: ashleysharpe/ruby-oci8
VALUE oci8_make_integer(OCINumber *s, OCIError *errhp)
{
    signed long sl;
    char buf[512];
    sword rv;

    if (OCINumberToInt(errhp, s, sizeof(sl), OCI_NUMBER_SIGNED, &sl) == OCI_SUCCESS) {
        return LONG2NUM(sl);
    }
    /* convert to Integer via String */
    rv = oranumber_to_str(s, buf, sizeof(buf));
    if (rv > 0) {
        return rb_cstr2inum(buf, 10);
    }
    oranumber_dump(s, buf);
    rb_raise(eOCIException, "Invalid internal number format: %s", buf);
}
sword _fetchDataIntoBooleanField(ORACLE_SQL_CURSOR *cursor, PA_Variable variable, unsigned int pos)
{		
	if(cursor->rowsFetched)
	{
		short intValue = 0;
		
		if(cursor->indicators.at(pos) != -1)
		{		
			OCINumberToInt(cursor->errhp, &cursor->numbers.at(pos), sizeof(short), OCI_NUMBER_SIGNED, &intValue);
			PA_SetBooleanField(variable.uValue.fTableFieldDefinition.fTableNumber, variable.uValue.fTableFieldDefinition.fFieldNumber, intValue);	
			
		}else{
			setBooleanFieldValueNull(variable);
		}
			
	}
		
	return cursor->rowsFetched;	
}
sword _fetchDataIntoBooleanVariable(ORACLE_SQL_CURSOR *cursor, PA_Variable variable, unsigned int pos)
{		
	if(cursor->rowsFetched)
	{
		int intValue = 0;
		
		if(cursor->indicators.at(pos) != -1)
		{		
			OCINumberToInt(cursor->errhp, &cursor->numbers.at(pos), sizeof(int), OCI_NUMBER_UNSIGNED, &intValue);
			PA_SetBooleanVariable(&variable, intValue);	
			
		}else{
			setBooleanVariableValueNull(variable);
		}
		
		PA_SetPointerValue(&cursor->pointers.at(pos), variable);		
	}
		
	return cursor->rowsFetched;
}
コード例 #10
0
/* ODCIIndexFetch function */
OCINumber *qxiqtbspf(
OCIExtProcContext *ctx,
qxiqtim           *self,
qxiqtin           *self_ind,
OCINumber         *nrows,
short             nrows_ind,
OCIArray          **rids,
short             *rids_ind,
ODCIEnv           *env,
ODCIEnv_ind       *env_ind)
{
  sword status;
  OCIEnv *envhp = (OCIEnv *) 0;                               /* env. handle */
  OCISvcCtx *svchp = (OCISvcCtx *) 0;                      /* service handle */
  OCIError *errhp = (OCIError *) 0;                          /* error handle */
  OCISession *usrhp = (OCISession *) 0;                       /* user handle */
  qxiqtcx *icx = (qxiqtcx *) 0;         /* state to be saved for later calls */

  int idx = 1;
  int nrowsval;

  OCIArray *ridarrp = *rids;                  /* rowid collection */
  OCIString *ridstr = (OCIString *)0;

  int done = 0;
  int retval = (int)ODCI_SUCCESS;
  OCINumber *rval = (OCINumber *)0;

  ub1 *key;                                   /* key to retrieve context */
  ub4 keylen;                                 /* length of key */

  /*******************/
  /* Get OCI handles */
  /*******************/
  if (qxiqtce(ctx, errhp, OCIExtProcGetEnv(ctx, &envhp, &svchp, &errhp)))
      return(rval);

  /* set up return code */
  rval = (OCINumber *)OCIExtProcAllocCallMemory(ctx, sizeof(OCINumber));
  if (qxiqtce(ctx, errhp,
              OCINumberFromInt(errhp, (dvoid *)&retval, sizeof(retval),
                                           OCI_NUMBER_SIGNED, rval)))
    return(rval);

  /* get the user handle */
  if (qxiqtce(ctx, errhp, OCIAttrGet((dvoid *)svchp, (ub4)OCI_HTYPE_SVCCTX,
                                     (dvoid *)&usrhp, (ub4 *)0,
                                     (ub4)OCI_ATTR_SESSION, errhp)))
    return(rval);

  /********************************/
  /* Retrieve context from key    */
  /********************************/
  key = OCIRawPtr(envhp, self->sctx_qxiqtim);
  keylen = OCIRawSize(envhp, self->sctx_qxiqtim);

  if (qxiqtce(ctx, errhp, OCIContextGetValue((dvoid *)usrhp, errhp,
                                             key, (ub1)keylen,
                                             (dvoid **)&(icx))))
    return(rval);

  /* get value of nrows */
  if (qxiqtce(ctx, errhp, OCINumberToInt(errhp, nrows, 
                                         sizeof(nrowsval),
                                         OCI_NUMBER_SIGNED, 
                                         (dvoid *)&nrowsval)))
    return(rval);

  /****************/
  /* Fetch rowids */
  /****************/
  while (!done)
  {
    if (idx > nrowsval)
      done = 1;
    else
    {
      status = OCIStmtFetch(icx->stmthp, errhp, (ub4)1, (ub2) 0,
                            (ub4)OCI_DEFAULT);
      if (status == OCI_NO_DATA)
      {
        short col_ind = OCI_IND_NULL;
        /* have to create dummy oci string */
        OCIStringAssignText(envhp, errhp, (text *)"dummy",
                            (ub2)5, &ridstr);
        /* append null element to collection */
        if (qxiqtce(ctx, errhp, OCICollAppend(envhp, errhp,
                                              (dvoid *)ridstr,
                                              (dvoid *)&col_ind,
                                              (OCIColl *)ridarrp)))
          return(rval);
        done = 1;
      }
      else if (status == OCI_SUCCESS)
      {
        OCIStringAssignText(envhp, errhp, (text *)icx->ridp,
                            (ub2)18, (OCIString **)&ridstr);
        /* append rowid to collection */
        if (qxiqtce(ctx, errhp, OCICollAppend(envhp, errhp, 
                                              (dvoid *)ridstr,
                                              (dvoid *)0, 
                                              (OCIColl *)ridarrp)))
          return(rval);
        idx++;
      }
      else if (qxiqtce(ctx, errhp, status))
        return(rval);
    }
  }

  /* free ridstr finally */
  if (ridstr &&
      (qxiqtce(ctx, errhp, OCIStringResize(envhp, errhp, (ub4)0,
                                           &ridstr))))
    return(rval);

  *rids_ind = OCI_IND_NOTNULL;

  return(rval);
}
コード例 #11
0
/* ODCIIndexInsert function */
OCINumber *qxiqtbspi(
OCIExtProcContext *ctx,
ODCIIndexInfo     *ix,
ODCIIndexInfo_ind *ix_ind,
char              *rid,
short             rid_ind,
char              *newval,
short             newval_ind,
ODCIEnv           *env,
ODCIEnv_ind       *env_ind)
{
  OCIEnv *envhp = (OCIEnv *) 0;             /* env. handle */
  OCISvcCtx *svchp = (OCISvcCtx *) 0;       /* service handle */
  OCIError *errhp = (OCIError *) 0;         /* error handle */
  OCIStmt *stmthp = (OCIStmt *) 0;          /* statement handle */
  OCIBind *bndp = (OCIBind *) 0;            /* bind handle */

  int retval = (int)ODCI_SUCCESS;           /* return from this function */
  OCINumber *rval = (OCINumber *)0;
  
  char insstmt[2000];                       /* sql insert statement */
  ODCIColInfo  *colinfo;                    /* column info */
  ODCIColInfo_ind  *colinfo_ind;
  boolean exists = TRUE;
  int partiden;                             /* table partition iden */ 


  /* allocate memory for OCINumber first */
  rval = (OCINumber *)OCIExtProcAllocCallMemory(ctx, sizeof(OCINumber));

  /* Get oci handles */
  if (qxiqtce(ctx, errhp, OCIExtProcGetEnv(ctx, &envhp, &svchp, &errhp)))
    return(rval);

  /* set up return code */
  if (qxiqtce(ctx, errhp, OCINumberFromInt(errhp, (dvoid *)&retval,
                                           sizeof(retval),
                                           OCI_NUMBER_SIGNED, rval)))
    return(rval);

  /******************************
   * Construct insert Statement *
   ******************************/
  if ( ix_ind->IndexPartitionIden == OCI_IND_NULL )
    (void)sprintf(insstmt,
                  "INSERT into %s.%s_sbtree values (:newval, :mrid)",
                  OCIStringPtr(envhp, ix->IndexSchema),
                  OCIStringPtr(envhp, ix->IndexName));
  else
  {
    if (qxiqtce(ctx, errhp, OCICollGetElem(envhp, errhp,
                           (OCIColl *)ix->IndexCols, (sb4)0, &exists, 
                           (void **) &colinfo, (void **) &colinfo_ind)))
      return(rval);

    (void)sprintf(insstmt,
                  "INSERT into %s.%s_sbtree partition (DATAOBJ_TO_PARTITION(%s, :partiden)) values (:newval, :mrid)",
                  OCIStringPtr(envhp, ix->IndexSchema),
                  OCIStringPtr(envhp, ix->IndexName),
                  OCIStringPtr(envhp, colinfo->TableName));
  }

  /****************************************
   * Parse and Execute Create Statement   *
   ****************************************/

  /* allocate stmt handle */
  if (qxiqtce(ctx, errhp, OCIHandleAlloc((dvoid *)envhp,
                                         (dvoid **)&stmthp,
                                         (ub4)OCI_HTYPE_STMT, (size_t)0,
                                         (dvoid **)0)))
    return(rval);

  /* prepare the statement */
  if (qxiqtce(ctx, errhp, OCIStmtPrepare(stmthp, errhp, 
                                         (text *)insstmt,
                                         (ub4)strlen(insstmt), 
                                         OCI_NTV_SYNTAX,
                                         OCI_DEFAULT)))
    return(rval);

  if (ix_ind->IndexPartitionIden != OCI_IND_NULL)
  {
    /* Convert partiden to integer from OCINumber */
    if (qxiqtce(ctx, errhp, OCINumberToInt(errhp, 
                                           &(colinfo->TablePartitionIden),
                                           sizeof(partiden),
                                           OCI_NUMBER_SIGNED,
                                           ( void *)&partiden)))
      return(rval);

    /* Set up bind for partiden */
    if (qxiqtce(ctx, errhp, OCIBindByName(stmthp, &bndp, errhp, 
                                          (text *)":partiden",
                                          sizeof(":partiden")-1,
                                          (dvoid *)&partiden,
                                          (sb4)(sizeof(partiden)),
                                          (ub2)SQLT_INT, 
                                          (dvoid *)0, (ub2 *)0,
                                          (ub2 *)0, (ub4)0, (ub4 *)0,
                                          (ub4)OCI_DEFAULT)))
      return(rval);
  }

  /* Set up bind for newval */
  if (qxiqtce(ctx, errhp, OCIBindByName(stmthp, &bndp, errhp, 
                                        (text *)":newval",
                                        sizeof(":newval")-1,
                                        (dvoid *)newval,
                                        (sb4)(strlen(newval)+1),
                                        (ub2)SQLT_STR, 
                                        (dvoid *)0, (ub2 *)0,
                                        (ub2 *)0, (ub4)0, (ub4 *)0,
                                        (ub4)OCI_DEFAULT)))
    return(rval);

  /* Set up bind for rid */
  if (qxiqtce(ctx, errhp, OCIBindByName(stmthp, &bndp, errhp,  
                                        (text *)":mrid",
                                        sizeof(":mrid")-1,
                                        (dvoid *)rid,
                                        (sb4)(strlen(rid)+1),
                                        (ub2)SQLT_STR, 
                                        (dvoid *)0, (ub2 *)0,
                                        (ub2 *)0, (ub4)0, (ub4 *)0,
                                        (ub4)OCI_DEFAULT)))
    return(rval);

  /* Execute statement */
  if (qxiqtce(ctx, errhp, OCIStmtExecute(svchp, stmthp, errhp, (ub4)1,
                                         (ub4)0, (OCISnapshot *)NULL,
                                         (OCISnapshot *)NULL,
                                         (ub4)OCI_DEFAULT)))
    return(rval);

  /* free stmt handle */
  if (qxiqtce(ctx, errhp, OCIHandleFree((dvoid *)stmthp,
                                        (ub4)OCI_HTYPE_STMT)))
    return(rval);

  return(rval);
}
コード例 #12
0
/* ODCIIndexStart function */
OCINumber *qxiqtbsps(
OCIExtProcContext *ctx,
qxiqtim           *sctx,
qxiqtin           *sctx_ind,
ODCIIndexInfo     *ix,
ODCIIndexInfo_ind *ix_ind,
ODCIPredInfo      *pr,
ODCIPredInfo_ind  *pr_ind,
ODCIQueryInfo     *qy,
ODCIQueryInfo_ind *qy_ind,
OCINumber         *strt,
short             strt_ind,
OCINumber         *stop,
short             stop_ind,
char              *cmpval,
short             cmpval_ind,
ODCIEnv           *env,
ODCIEnv_ind       *env_ind)
{
  sword status;
  OCIEnv *envhp = (OCIEnv *) 0;                               /* env. handle */
  OCISvcCtx *svchp = (OCISvcCtx *) 0;                      /* service handle */
  OCIError *errhp = (OCIError *) 0;                          /* error handle */
  OCISession *usrhp = (OCISession *) 0;                       /* user handle */
  qxiqtcx *icx = (qxiqtcx *) 0;         /* state to be saved for later calls */

  int strtval;                   /* start bound */
  int stopval;                   /* stop bound */

  int errnum = 29400;            /* choose some oracle error number */
  char errmsg[512];              /* error message buffer */
  size_t errmsglen;              /* Length of error message */

  char relop[3];                 /* relational operator used in sql stmt */
  char selstmt[2000];            /* sql select statement */

  int retval = (int)ODCI_SUCCESS;       /* return from this function */
  OCINumber *rval = (OCINumber *)0;
  ub4 key;                              /* key value set in "sctx" */

  ub1 *rkey;                            /* key to retrieve context */
  ub4 rkeylen;                          /* length of key */
  ODCIColInfo  *colinfo;                /* column info */
  ODCIColInfo_ind  *colinfo_ind;
  boolean exists = TRUE;
  int partiden;                         /* table partition iden */ 

  /* Get oci handles */
  if (qxiqtce(ctx, errhp, OCIExtProcGetEnv(ctx, &envhp, &svchp, &errhp)))
    return(rval);

  /* set up return code */
  rval = (OCINumber *)OCIExtProcAllocCallMemory(ctx, sizeof(OCINumber));
  if (qxiqtce(ctx, errhp, OCINumberFromInt(errhp, (dvoid *)&retval,
                                           sizeof(retval),
                                           OCI_NUMBER_SIGNED, rval)))
    return(rval);

  /* get the user handle */
  if (qxiqtce(ctx, errhp, OCIAttrGet((dvoid *)svchp, (ub4)OCI_HTYPE_SVCCTX,
                                     (dvoid *)&usrhp, (ub4 *)0,
                                     (ub4)OCI_ATTR_SESSION,
                                     errhp)))
    return(rval);

  /**********************************************/
  /* Allocate memory to hold index scan context */
  /**********************************************/
  if (sctx_ind ->atomic_qxiqtin == OCI_IND_NULL ||
      sctx_ind ->scind_qxiqtin == OCI_IND_NULL)
  {
   if (qxiqtce(ctx, errhp, OCIMemoryAlloc((dvoid *)usrhp, errhp,
                                          (dvoid **)&icx,
                                          OCI_DURATION_STATEMENT,
                                          (ub4)(sizeof(qxiqtcx)),
                                          OCI_MEMORY_CLEARED)))
     return(rval);

   icx->stmthp = (OCIStmt *)0;
   icx->defnp = (OCIDefine *)0;
   icx->bndp = (OCIBind *)0;
  }
  else
  {
   /*************************/
   /* Retrieve scan context */
   /*************************/
   rkey = OCIRawPtr(envhp, sctx->sctx_qxiqtim);
   rkeylen = OCIRawSize(envhp, sctx->sctx_qxiqtim);

   if (qxiqtce(ctx, errhp, OCIContextGetValue((dvoid *)usrhp, errhp,
                                              rkey, (ub1)rkeylen,
                                              (dvoid **)&(icx))))
    return(rval);
  }

  /***********************************/
  /* Check that the bounds are valid */
  /***********************************/
  /* convert from oci numbers to native numbers */
  if (qxiqtce(ctx, errhp, OCINumberToInt(errhp, strt,
                                         sizeof(strtval), 
                                         OCI_NUMBER_SIGNED,
                                         (dvoid *)&strtval)))
    return(rval);

  if (qxiqtce(ctx, errhp, OCINumberToInt(errhp, stop,
                                        sizeof(stopval),
                                        OCI_NUMBER_SIGNED, 
                                        (dvoid *)&stopval)))
    return(rval);

  /* verify that strtval/stopval are both either 0 or 1 */
  if (!(((strtval == 0) && (stopval == 0)) ||
        ((strtval == 1) && (stopval == 1))))
    {
      strcpy(errmsg, (char *)"Incorrect predicate for sbtree operator");
      errmsglen = (size_t)strlen(errmsg);
      if (OCIExtProcRaiseExcpWithMsg(ctx, errnum, (text *)errmsg, errmsglen)
          != OCIEXTPROC_SUCCESS)
        /* Use cartridge error services here */;
      return(rval);
    }

  /*********************************************/
  /* Generate the SQL statement to be executed */
  /*********************************************/
  if (memcmp((dvoid *)OCIStringPtr(envhp, pr->ObjectName), (dvoid *)"EQ", 2)
      == 0)
    if (strtval == 1)
      strcpy(relop, (char *)"=");
    else
      strcpy(relop, (char *)"!=");
  else if (memcmp((dvoid *)OCIStringPtr(envhp, pr->ObjectName), (dvoid *)"LT",
                  2) == 0)
    if (strtval == 1)
      strcpy(relop, (char *)"<");
    else
      strcpy(relop, (char *)">=");
  else
    if (strtval == 1)
      strcpy(relop, (char *)">");
    else
      strcpy(relop, (char *)"<=");

  if (ix_ind->IndexPartitionIden == OCI_IND_NULL)
    (void)sprintf(selstmt, "select f2 from %s.%s_sbtree where f1 %s :val",
                  OCIStringPtr(envhp, ix->IndexSchema),
                  OCIStringPtr(envhp, ix->IndexName), relop);
  else
  {
    
    if (qxiqtce(ctx, errhp, OCICollGetElem(envhp, errhp,
                           (OCIColl *)ix->IndexCols, (sb4)0, &exists, 
                           (void **) &colinfo, (void **) &colinfo_ind)))
      return(rval);
    (void)sprintf(selstmt, "select f2 from %s.%s_sbtree partition (DATAOBJ_TO_PARTITION(%s, :partiden)) where f1 %s :val",
                  OCIStringPtr(envhp, ix->IndexSchema),
                  OCIStringPtr(envhp, ix->IndexName),
                   OCIStringPtr(envhp, colinfo->TableName), relop);
  }

  /***********************************/
  /* Parse, bind, define and execute */
  /***********************************/
  if (sctx_ind ->atomic_qxiqtin == OCI_IND_NULL ||
      sctx_ind ->scind_qxiqtin == OCI_IND_NULL)
  {
    /* allocate stmt handle */
    if (qxiqtce(ctx, errhp, OCIHandleAlloc((dvoid *)envhp,  
                                           (dvoid **)&(icx->stmthp),
                                           (ub4)OCI_HTYPE_STMT, 
                                           (size_t)0, (dvoid **)0)))  
      return(rval);
  }

  /* prepare the statement */
  if (qxiqtce(ctx, errhp, OCIStmtPrepare(icx->stmthp, errhp, 
                                         (text *)selstmt,
                                         (ub4)strlen(selstmt), 
                                         OCI_NTV_SYNTAX,
                                          OCI_DEFAULT)))
    return(rval);


  if (ix_ind->IndexPartitionIden != OCI_IND_NULL)
  {
    /* Convert partiden to integer from OCINumber */
    if (qxiqtce(ctx, errhp, OCINumberToInt(errhp, 
                                           &(colinfo->TablePartitionIden),
                                           sizeof(partiden),
                                           OCI_NUMBER_SIGNED,
                                           ( void *)&partiden)))
      return(rval);

    /* Set up bind for partiden */
    if (qxiqtce(ctx, errhp, OCIBindByName(icx->stmthp, &(icx->bndp), errhp, 
                                          (text *)":partiden",
                                          sizeof(":partiden")-1,
                                          (dvoid *)&partiden,
                                          (sb4)(sizeof(partiden)),
                                          (ub2)SQLT_INT, 
                                          (dvoid *)0, (ub2 *)0,
                                          (ub2 *)0, (ub4)0, (ub4 *)0,
                                          (ub4)OCI_DEFAULT)))
      return(rval);
  }

  /* Set up bind for compare value */
  if (qxiqtce(ctx, errhp, OCIBindByName(icx->stmthp, &(icx->bndp),errhp, 
                                        (text *)":val",
                                        sizeof(":val")-1,
                                       (dvoid *)cmpval,
                                       (sb4)(strlen(cmpval)+1),
                                       (ub2)SQLT_STR, 
                                       (dvoid *)0, (ub2 *)0,
                                       (ub2 *)0, (ub4)0, (ub4 *)0,
                                       (ub4)OCI_DEFAULT)))
    return(rval);

  /* Set up define */
  if (qxiqtce(ctx, errhp, OCIDefineByPos(icx->stmthp, &(icx->defnp), 
                                         errhp, (ub4)1,  
                                         (dvoid *)(icx->ridp),
                                         (sb4) sizeof(icx->ridp),
                                         (ub2)SQLT_STR, 
                                         (dvoid *)0, (ub2 *)0,
                                         (ub2 *)0, (ub4)OCI_DEFAULT)))
    return(rval);

  /* execute */
  if (qxiqtce(ctx, errhp, OCIStmtExecute(svchp, icx->stmthp, 
                                         errhp, (ub4)0,
                                         (ub4)0, (OCISnapshot *)NULL,
                                         (OCISnapshot *)NULL,
                                         (ub4)OCI_DEFAULT)))
    return(rval);

  /************************************/
  /* Set index context to be returned */
  /************************************/
  if (sctx_ind ->atomic_qxiqtin == OCI_IND_NULL ||
      sctx_ind ->scind_qxiqtin == OCI_IND_NULL)
   {
    /* generate a key */
    if (qxiqtce(ctx, errhp, OCIContextGenerateKey((dvoid *)usrhp, 
                                                  errhp, &key)))
      return(rval);

    /* set the memory address of the struct to be saved in the context */
    if (qxiqtce(ctx, errhp, OCIContextSetValue((dvoid *)usrhp, errhp,
                                               OCI_DURATION_STATEMENT,
                                               (ub1 *)&key, 
                                               (ub1)sizeof(key),
                                               (dvoid *)icx)))
      return(rval);

    /* set the key as the member of "sctx" */
    if (qxiqtce(ctx, errhp, OCIRawAssignBytes(envhp, errhp, 
                                              (ub1 *)&key,
                                              (ub4)sizeof(key),
                                              &(sctx->sctx_qxiqtim))))
      return(rval);

    sctx_ind->atomic_qxiqtin = OCI_IND_NOTNULL;
    sctx_ind->scind_qxiqtin = OCI_IND_NOTNULL;

    return(rval);
   }

  return(rval);
}
コード例 #13
0
ファイル: NumberVar.c プロジェクト: 15580056814/hue
//-----------------------------------------------------------------------------
// NumberVar_GetValue()
//   Returns the value stored at the given array position.
//-----------------------------------------------------------------------------
static PyObject *NumberVar_GetValue(
    udt_NumberVar *var,                 // variable to determine value for
    unsigned pos)                       // array position
{
    PyObject *result, *stringObj;
    char stringValue[200];
    long integerValue;
    ub4 stringLength;
    sword status;

#if PY_MAJOR_VERSION < 3
    if (var->type == &vt_Integer || var->type == &vt_Boolean) {
#else
    if (var->type == &vt_Boolean) {
#endif
        status = OCINumberToInt(var->environment->errorHandle, &var->data[pos],
                sizeof(long), OCI_NUMBER_SIGNED, (dvoid*) &integerValue);
        if (Environment_CheckForError(var->environment, status,
                "NumberVar_GetValue(): as integer") < 0)
            return NULL;
#if PY_MAJOR_VERSION < 3
        if (var->type == &vt_Integer)
            return PyInt_FromLong(integerValue);
#endif
        return PyBool_FromLong(integerValue);
    }

    if (var->type == &vt_NumberAsString || var->type == &vt_LongInteger) {
        stringLength = sizeof(stringValue);
        status = OCINumberToText(var->environment->errorHandle,
                &var->data[pos],
                (text*) var->environment->numberToStringFormatBuffer.ptr,
                var->environment->numberToStringFormatBuffer.size, NULL, 0,
                &stringLength, (unsigned char*) stringValue);
        if (Environment_CheckForError(var->environment, status,
                "NumberVar_GetValue(): as string") < 0)
            return NULL;
        stringObj = cxString_FromEncodedString(stringValue, stringLength,
                var->environment->encoding);
        if (!stringObj)
            return NULL;
        if (var->type == &vt_NumberAsString)
            return stringObj;
#if PY_MAJOR_VERSION >= 3
        result = PyNumber_Long(stringObj);
#else
        result = PyNumber_Int(stringObj);
#endif
        Py_DECREF(stringObj);
        if (result || !PyErr_ExceptionMatches(PyExc_ValueError))
            return result;
        PyErr_Clear();
    }

    return OracleNumberToPythonFloat(var->environment, &var->data[pos]);
}


#ifdef SQLT_BFLOAT
//-----------------------------------------------------------------------------
// NativeFloatVar_GetValue()
//   Returns the value stored at the given array position as a float.
//-----------------------------------------------------------------------------
static PyObject *NativeFloatVar_GetValue(
    udt_NativeFloatVar *var,            // variable to determine value for
    unsigned pos)                       // array position
{
    return PyFloat_FromDouble(var->data[pos]);
}


//-----------------------------------------------------------------------------
// NativeFloatVar_SetValue()
//   Set the value of the variable which should be a native double.
//-----------------------------------------------------------------------------
static int NativeFloatVar_SetValue(
    udt_NativeFloatVar *var,            // variable to set value for
    unsigned pos,                       // array position to set
    PyObject *value)                    // value to set
{
    if (!PyFloat_Check(value)) {
        PyErr_SetString(PyExc_TypeError, "expecting float");
        return -1;
    }
    var->data[pos] = PyFloat_AS_DOUBLE(value);
    return 0;
}
コード例 #14
0
/* Function to display the attributes of the object */
static void display (i_manager *sub_obj)
{
  ub4 sizeUB4 = sizeof (ub4);
  ub4 ssn = 0; /* Variable to fetch ssn */
  ub4 addr_hno = 0; /*Variable to fetch hno of addr */
  text *name; /*Variable to fetch name */
  ub4 name_len = 0;
  text *addr_street; /*Variable to fetch street of addr */
  ub4 addr_streetLen = 0;
  ub4 altadrs_hno = 0; /*Variable to fetch hno of altadrs */
  text *altadrs_street; /*Variable to fetch street of altadrs */
  ub4 altadrs_streetLen = 0;
  ub4 empno = 0; /* Variable to fetch empno */
  ub4 workadd_hno = 0; /*Variable to fetch hno of workadd */
  text *workadd_street; /*Variable to fetch street of workadd */
  ub4 workadd_streetLen = 0;

  sb4 size = 111;
  sb4 index1 = 0; /* Index for the starting point of the scan */
  sb4 index2 = 0; /* Index of the next existing element */
  boolean eoc = TRUE; /* For getting the status for the availability of
                         the next index */
  ub4 count = 0;
  i_residence *elem = (i_residence *)0; /* To get the element from the 
                                           nested table */
  i_residence_ref *elemref = (i_residence_ref *)0;
  i_residence *objptr = (i_residence *)0;

  name = OCIStringPtr(envhp, sub_obj->_super.name);
  name_len =  OCIStringSize (envhp, sub_obj->_super.name);
  printf("name is : %.*s\n", name_len, name);
  OCINumberToInt (errhp, &(sub_obj->_super.ssn), sizeof(ub4),
    OCI_NUMBER_UNSIGNED, (dvoid *)&ssn);
  printf("SSN: %d\n", ssn);
  OCINumberToInt (errhp, &(sub_obj->_super.addr.hno), sizeof(ub4),
    OCI_NUMBER_UNSIGNED, (dvoid *)&addr_hno);
  addr_street = OCIStringPtr(envhp, sub_obj->_super.addr.street);
  addr_streetLen =  OCIStringSize (envhp, sub_obj->_super.addr.street);
  printf("Primary address:   %d %.*s\n", addr_hno,addr_streetLen, addr_street);

  OCITableSize(envhp, errhp, (CONST OCITable*)(sub_obj->_super.altadrs), &size);
  OCITableFirst(envhp, errhp,(CONST OCITable*)sub_obj->_super.altadrs, &index1);
  status = OCICollGetElem(envhp, errhp, (OCIColl *)sub_obj->_super.altadrs, 
    index1, (boolean *)&eoc, (dvoid **)&elem, (dvoid **)0);
  OCINumberToInt (errhp, &(elem->hno), sizeof(ub4),
    OCI_NUMBER_UNSIGNED, (dvoid *)&altadrs_hno);
  altadrs_street = OCIStringPtr(envhp, elem->street);
  altadrs_streetLen = OCIStringSize (envhp, elem->street);
  printf("Other addresses:\n");
  printf("   %d %.*s\n", altadrs_hno, altadrs_streetLen, 
           altadrs_street);
  for (count = 1; count < size; count++)
  {
     OCITableNext(envhp, errhp, index1, 
      (CONST OCITable*)sub_obj->_super.altadrs, &index2, &eoc);
     OCICollGetElem(envhp, errhp,(OCIColl *)sub_obj->_super.altadrs, index2,
       (boolean *)&eoc, (dvoid **)&elem, (dvoid **)0);
     OCINumberToInt (errhp, &(elem->hno), sizeof(ub4), OCI_NUMBER_UNSIGNED, 
       (dvoid *)&altadrs_hno);
     altadrs_street = OCIStringPtr(envhp, elem->street);
     altadrs_streetLen = OCIStringSize (envhp, elem->street);
     printf("   %d %.*s\n", altadrs_hno, altadrs_streetLen, 
           altadrs_street);
     index1 = index2;
  }

  OCINumberToInt (errhp, &(sub_obj->empno), sizeof(ub4),
    OCI_NUMBER_UNSIGNED, (dvoid *)&empno);
  printf("EMPNO: %d\n", empno);

  index1 = 1;
  eoc = TRUE;
  OCITableSize(envhp, errhp, (CONST OCITable*) sub_obj->workadd, &size);
  OCITableFirst(envhp, errhp,(CONST OCITable*) sub_obj->workadd, &index1);
  status = OCICollGetElem(envhp, errhp, (OCIColl *)(sub_obj->workadd),
    index1, (boolean *)&eoc, (dvoid **)&elemref, (dvoid **)0);
  if (status != OCI_SUCCESS)
  {
    printf("OCICollGetElem - Failure \n");
  }
  elemref = *( OCIRef **)elemref;
  
  if ((status = OCIObjectPin(envhp, errhp, elemref, 
    (OCIComplexObject *)0,
    OCI_PIN_ANY, OCI_DURATION_SESSION, OCI_LOCK_NONE, 
    (dvoid **) &objptr)) != OCI_SUCCESS)
  {
    printf("OCIObjectPin - Failure \n");
  }

  OCINumberToInt (errhp, &(objptr->hno), sizeof(ub4), OCI_NUMBER_UNSIGNED,
       (dvoid *)&workadd_hno);

  workadd_street = OCIStringPtr(envhp, objptr->street);
  workadd_streetLen = OCIStringSize (envhp, objptr->street);
  printf("Work Addresses:\n");
  printf("   %d %.*s\n", workadd_hno,workadd_streetLen,
              workadd_street);
  for (count = 1; count < size; count++)
  {
    OCITableNext(envhp, errhp, index1, 
       (CONST OCITable*)sub_obj->workadd, &index2, &eoc);
    status = OCICollGetElem(envhp, errhp, (OCIColl *)(sub_obj->workadd),
    index2, (boolean *)&eoc, (dvoid **)&elemref, (dvoid **)0);
    if (status != OCI_SUCCESS)
    {
      printf("OCICollGetElem - Failure \n");
    }
    elemref = *( OCIRef **)elemref;
    
    if ((status = OCIObjectPin(envhp, errhp, elemref, 
      (OCIComplexObject *)0,
      OCI_PIN_ANY, OCI_DURATION_SESSION, OCI_LOCK_NONE,
      (dvoid **) &objptr)) != OCI_SUCCESS)
    {
      printf("OCIObjectPin - Failure \n");
    }
    OCINumberToInt (errhp, &(objptr->hno), sizeof(ub4), OCI_NUMBER_UNSIGNED,
       (dvoid *)&workadd_hno);

    workadd_street = OCIStringPtr(envhp, objptr->street);
    workadd_streetLen = OCIStringSize (envhp, objptr->street);
    printf("   %d %.*s\n", workadd_hno,workadd_streetLen,
              workadd_street);
    index1 = index2;
  } 
} /* end of display ((i_manager *) */