Example #1
0
static VALUE onum_coerce(VALUE self, VALUE other)
{
    signed long sl;
    OCINumber n;

    switch(rboci8_type(other)) {
    case T_FIXNUM:
        sl = NUM2LONG(other);
        chkerr(OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &n));
        return rb_assoc_new(oci8_make_ocinumber(&n, oci8_errhp), self);
    case T_BIGNUM:
        /* change via string. */
        other = rb_big2str(other, 10);
        set_oci_number_from_str(&n, other, Qnil, Qnil, oci8_errhp);
        return rb_assoc_new(oci8_make_ocinumber(&n, oci8_errhp), self);
    case T_FLOAT:
        return rb_assoc_new(other, onum_to_f(self));
    case RBOCI8_T_RATIONAL:
        return rb_assoc_new(other, onum_to_r(self));
    case RBOCI8_T_BIGDECIMAL:
        return rb_assoc_new(other, onum_to_d(self));
    }
    rb_raise(rb_eTypeError, "Can't coerce %s to %s",
             rb_class2name(CLASS_OF(other)), rb_class2name(cOCINumber));
}
ORAEXT OCINumber * oraConfigGetInt (OCIExtProcContext *ctx, int context_id, char *key_name, short key_name_indicator, 
                             short *return_indicator)
{
   OCINumber *result = NULL;

   ORABLOCK_BEGIN
   {
      *return_indicator = OCI_IND_NULL;

      OracleEnv env(ctx, logger);

      if (key_name_indicator != OCI_IND_NOTNULL)
         throw BingoError("Null key is given");

      int value;
      BingoOracleContext &context = BingoOracleContext::get(env, context_id, false, 0);
      if (!context.configGetInt(env, key_name, value))
         throw BingoError("Key wasn't found");

      result = (OCINumber *)OCIExtProcAllocCallMemory(ctx, sizeof(OCINumber));

      if (result == NULL)
         throw BingoError("can't allocate memory for number");

      env.callOCI(OCINumberFromInt(env.errhp(), &value, sizeof(int), OCI_NUMBER_SIGNED, result));

      *return_indicator = OCI_IND_NOTNULL;
   }
   ORABLOCK_END

   return result;
}
Example #3
0
/* ODCIIndexClose function */
OCINumber *qxiqtbspc(
OCIExtProcContext *ctx,
qxiqtim           *self,
qxiqtin           *self_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 retval = (int) ODCI_SUCCESS;
  OCINumber *rval = (OCINumber *)0;

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

  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 using 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);

  /* Free handles and memory */
  if (qxiqtce(ctx, errhp, OCIHandleFree((dvoid *)icx->stmthp,
                                        (ub4)OCI_HTYPE_STMT)))
    return(rval);

  if (qxiqtce(ctx, errhp, OCIMemoryFree((dvoid *)usrhp, errhp, (dvoid *)icx)))
    return(rval);

  return(rval);
}
void OraclePreparedStatement_setLLong(T P, int parameterIndex, long long int x) {
        TEST_INDEX
        P->params[i].length = sizeof(P->params[i].type.number);
        P->lastError = OCINumberFromInt(P->err, &x, sizeof(x), OCI_NUMBER_SIGNED, &P->params[i].type.number);
        if (P->lastError != OCI_SUCCESS)
                THROW(SQLException, "%s", OraclePreparedStatement_getLastError(P->lastError, P->err));
        P->lastError = OCIBindByPos(P->stmt, &P->params[i].bind, P->err, parameterIndex, &P->params[i].type.number, 
                                    (int)P->params[i].length, SQLT_VNU, 0, 0, 0, 0, 0, OCI_DEFAULT);
        if (P->lastError != OCI_SUCCESS && P->lastError != OCI_SUCCESS_WITH_INFO)
                THROW(SQLException, "%s", OraclePreparedStatement_getLastError(P->lastError, P->err));
}
Example #5
0
//-----------------------------------------------------------------------------
// NumberVar_SetValueFromInteger()
//   Set the value of the variable from a Python integer.
//-----------------------------------------------------------------------------
static int NumberVar_SetValueFromInteger(
    udt_NumberVar *var,                 // variable to set value for
    unsigned pos,                       // array position to set
    PyObject *value)                    // value to set
{
    long integerValue;
    sword status;

    integerValue = PyInt_AS_LONG(value);
    status = OCINumberFromInt(var->environment->errorHandle, &integerValue,
            sizeof(long), OCI_NUMBER_SIGNED, &var->data[pos]);
    return Environment_CheckForError(var->environment, status,
            "NumberVar_SetValueFromInteger()");
}
Example #6
0
void OWStatement::AddElement( OCIArray* poData,
                              int nValue )
{
    OCINumber      oci_number;

    CheckError(OCINumberFromInt(hError,
        (dvoid*) &nValue,
        (uword) sizeof(ub4),
        OCI_NUMBER_UNSIGNED,
        (OCINumber*) &oci_number), hError);

    CheckError(OCICollAppend(poConnection->hEnv,
        hError,
        (OCINumber*) &oci_number,
        (dvoid*) 0,
        (OCIColl*) poData), hError);
}
Example #7
0
File: version.c Project: NOX73/ora
sword
numberFromIntSlice(
	OCIError *err,
	void *inum,
	uword inum_length,
	uword inum_s_flag,
	OCINumber *numbers,
	ub4 arr_length
) {
	sword rc;
	int i;
	for(i=0; i < arr_length; i++) {
		rc = OCINumberFromInt(err, inum + (i * inum_length), inum_length, inum_s_flag, &(numbers[i]));
		if(rc == OCI_ERROR) {
			return rc;
	    }
	}
	return OCI_SUCCESS;
}
Example #8
0
ORAEXT OCINumber * oraProfilingGetCount (OCIExtProcContext *ctx, char *key_name, short key_name_indicator, 
                                       short *return_indicator)
{
   OCINumber *result = NULL;

   ORABLOCK_BEGIN
   {
      *return_indicator = OCI_IND_NULL;

      OracleEnv env(ctx, logger);

      if (key_name_indicator != OCI_IND_NOTNULL)
         throw BingoError("Null key is given");

      qword value;

      // Try to find in profiling data
      ProfilingSystem &inst = ProfilingSystem::getInstance();
      if (inst.hasLabel(key_name))
         //throw BingoError("Key wasn't found");
         value = inst.getLabelCallCount(key_name);
      else
         value = 0;

      result = (OCINumber *)OCIExtProcAllocCallMemory(ctx, sizeof(OCINumber));

      if (result == NULL)
         throw BingoError("can't allocate memory for number");

      env.callOCI(OCINumberFromInt(env.errhp(), &value, sizeof(qword), OCI_NUMBER_SIGNED, result));

      *return_indicator = OCI_IND_NOTNULL;
   }
   ORABLOCK_END

   return result;
}
Example #9
0
/* 1 - success, 0 - error */
static int set_oci_number_from_num(OCINumber *result, VALUE num, int force, OCIError *errhp)
{
    signed long sl;

    if (!RTEST(rb_obj_is_kind_of(num, rb_cNumeric)))
        rb_raise(rb_eTypeError, "expect Numeric but %s", rb_class2name(CLASS_OF(num)));
    if (rb_respond_to(num, id_finite_p) && !RTEST(rb_funcall(num, id_finite_p, 0))) {
        rb_raise(rb_eTypeError, "cannot accept number which isn't finite.");
    }
    switch (rb_type(num)) {
    case T_FIXNUM:
        /* set from long. */
        sl = NUM2LONG(num);
        chkerr(OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, result));
        return 1;
    case T_FLOAT:
        /* set from double. */
        oci8_dbl_to_onum(result, NUM2DBL(num), errhp);
        return 1;
    case T_BIGNUM:
        /* change via string. */
        num = rb_big2str(num, 10);
        set_oci_number_from_str(result, num, Qnil, Qnil, errhp);
        return 1;
    }
    if (RTEST(rb_obj_is_instance_of(num, cOCINumber))) {
        /* OCI::Number */
        chkerr(OCINumberAssign(errhp, DATA_PTR(num), result));
        return 1;
    }
    if (rb_respond_to(num, id_split)) {
        /* BigDecimal */
        VALUE split = rb_funcall(num, id_split, 0);

        if (TYPE(split) == T_ARRAY && RARRAY_LEN(split) == 4) {
            /*
             * sign, significant_digits, base, exponent = num.split
             * onum = sign * "0.#{significant_digits}".to_f * (base ** exponent)
             */
            VALUE *ary = RARRAY_PTR(split);
            int sign;
            OCINumber digits;
            int exponent;
            int digits_len;
            OCINumber work;

            /* check sign */
            if (TYPE(ary[0]) != T_FIXNUM) {
                goto is_not_big_decimal;
            }
            sign = FIX2INT(ary[0]);
            /* check digits */
            StringValue(ary[1]);
            digits_len = RSTRING_LEN(ary[1]);
            set_oci_number_from_str(&digits, ary[1], Qnil, Qnil, errhp);
            /* check base */
            if (TYPE(ary[2]) != T_FIXNUM || FIX2LONG(ary[2]) != 10) {
                goto is_not_big_decimal;
            }
            /* check exponent */
            if (TYPE(ary[3]) != T_FIXNUM) {
                goto is_not_big_decimal;
            }
            exponent = FIX2INT(ary[3]);

            chkerr(OCINumberShift(errhp, &digits, exponent - digits_len, &work));
            if (sign >= 0) {
                chkerr(OCINumberAssign(errhp, &work, result));
            } else {
                chkerr(OCINumberNeg(errhp, &work, result));
            }
            return 1;
        }
    }
is_not_big_decimal:
    if (rb_respond_to(num, id_numerator) && rb_respond_to(num, id_denominator)) {
        /* Rational */
        OCINumber numerator;
        OCINumber denominator;

        if (set_oci_number_from_num(&numerator, rb_funcall(num, id_numerator, 0), 0, errhp) &&
            set_oci_number_from_num(&denominator, rb_funcall(num, id_denominator, 0), 0, errhp)) {
            chkerr(OCINumberDiv(errhp, &numerator, &denominator, result));
            return 1;
        }
    }
    if (force) {
        /* change via string as a last resort. */
        /* TODO: if error, raise TypeError instead of OCI::Error */
        set_oci_number_from_str(result, num, Qnil, Qnil, errhp);
        return 1;
    }
    return 0;
}
Example #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);
}
Example #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);
}
Example #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);
}
Example #13
0
/*
 * Add a new message to the database.
 *  session    - session name
 *  sender_uid -
 *  rcpts      -
 *  content    -
 *  recv_time  - time of arrival
 *  quiet      - print error messages?
 * Returns 0 on success
 */
int oralog_db_new_msg(char *session, char *sender_uid, char **rcpts, char *content, time_t recv_time, int quiet)
{
	int i;

	/* There will be at least 2 INSERTs - 1 into 'messages' table and 1 (at least)
	   into the 'recipients' table. */
	text	*sqlstmt_msg  = (text *)"INSERT INTO messages VALUES(messages_seq.nextval, :session_uid, :sender_uid, :content, :recv_time) RETURNING id INTO :msg_id";
	text	*sqlstmt_rcp  = (text *)"INSERT INTO recipients VALUES(recipients_seq.nextval, :recipient_uid, :msg_id)";

	/* Statement & bind handles */
	OCIStmt *hp_stmt_msg = NULL;
	OCIStmt *hp_stmt_rcp = NULL;
	OCIBind *bind_msg[5] = { NULL };
	OCIBind *bind_rcp[2] = { NULL };

	/* Control vars */
	sword	 retstat  = 0;
	int	 errors   = 0;
	int	 print_errors = (quiet) ? 0 : 1;
	OCIError *hp_error = NULL;

	/* Date handling */
	uword	  invalid = 0;
	OCIDate   oci_recvtime;
	struct tm *tm_recvtime = NULL;		
	
	/* ID of inserted message will be put here */
	OCINumber msg_id;
	int	  init_val = 0;	/* this variable is needed for initialization only */
	

	pthread_mutex_lock(&oralog_oper_lock);
	
	if (!oralog_is_connected()) {
		debug("[logsoracle] can't log msg - not connected\n");
		
		pthread_mutex_unlock(&oralog_oper_lock);
		return 1;
	}


	check_string_len(session);
	check_string_len(sender_uid);
	check_string_len(content);

	/* Create local handles (OCIBind's are created automaticly) */
	OCIHandleAlloc( (dvoid *)hp_env, (dvoid **)&hp_stmt_msg, OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0);
	OCIHandleAlloc( (dvoid *)hp_env, (dvoid **)&hp_stmt_rcp, OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0);
	OCIHandleAlloc( (dvoid *)hp_env, (dvoid **)&hp_error, OCI_HTYPE_ERROR, 0, (dvoid **) 0);	
	
	/* Create DATE in Oracle format */
	tm_recvtime = localtime(&recv_time);
		
	memset(&oci_recvtime, 0, sizeof(OCIDate));
	OCIDateSetTime( &oci_recvtime, (ub1)tm_recvtime->tm_hour, (ub1)tm_recvtime->tm_min, (ub1)tm_recvtime->tm_sec );
	OCIDateSetDate( &oci_recvtime, (sb2)tm_recvtime->tm_year+1900, (ub1)tm_recvtime->tm_mon+1, (ub1)tm_recvtime->tm_mday );

	/* check if provided 'recv_time' was mapped correctly  */
	retstat = OCIDateCheck(hp_error, &oci_recvtime, &invalid);
	if(oralog_is_error(hp_error, retstat, print_errors))
	 errors++;

	/* prepare SQL statements */
	debug("[logsoracle] preparing new messages insert statement\n");
	retstat = OCIStmtPrepare(hp_stmt_msg, hp_error, (text *)sqlstmt_msg, (ub4)ora_strlen((char *)sqlstmt_msg), (ub4)OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT);
	if(oralog_is_error(hp_error, retstat, print_errors))
	 errors++;	 

	debug("[logsoracle] preparing new recipients insert statement\n");
	retstat = OCIStmtPrepare(hp_stmt_rcp, hp_error, (text *)sqlstmt_rcp, (ub4)ora_strlen((char *)sqlstmt_rcp), (ub4)OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT);
	if(oralog_is_error(hp_error, retstat, print_errors))
	 errors++;
 

	/* bind the placeholders */
	debug("[logsoracle] binding messages insert..\n");
	   
	retstat = OCIBindByName(hp_stmt_msg, &bind_msg[0], hp_error, (text *) ":session_uid", -1, (dvoid *)session,
				ora_strlen(session)+1, SQLT_STR, (dvoid *) 0,
				(ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
	if(oralog_is_error(hp_error, retstat, print_errors))
	 errors++;

	retstat = OCIBindByName(hp_stmt_msg, &bind_msg[1], hp_error, (text *) ":sender_uid", -1, (dvoid *)sender_uid,
				ora_strlen(sender_uid)+1, SQLT_STR, (dvoid *) 0,
				(ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
	if(oralog_is_error(hp_error, retstat, print_errors))
	 errors++;									    

	retstat = OCIBindByName(hp_stmt_msg, &bind_msg[2], hp_error, (text *) ":content", -1, (dvoid *)content,
				ora_strlen(content)+1, SQLT_STR, (dvoid *) 0,
				(ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
	if(oralog_is_error(hp_error, retstat, print_errors))
	 errors++;
	 
	retstat = OCIBindByName(hp_stmt_msg, &bind_msg[3], hp_error, (text *) ":recv_time",
				-1, (dvoid *) &oci_recvtime,
				(sword) sizeof(OCIDate), SQLT_ODT, (dvoid *) 0,
				(ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
	if(oralog_is_error(hp_error, retstat, print_errors))
	 errors++;	 
	

	/* Create a new OCINumber - will be under msg_id */
	retstat = OCINumberFromInt(hp_error, &init_val, sizeof(init_val), OCI_NUMBER_SIGNED, &msg_id);
	if(oralog_is_error(hp_error, retstat, print_errors))
	 errors++;
		
	
	/* bind the OCINumber */
	retstat = OCIBindByName(hp_stmt_msg, &bind_msg[4], hp_error, (text *) ":msg_id",
				-1, (dvoid *) &msg_id,
				(sword) sizeof(msg_id), SQLT_VNU, (dvoid *) 0,
				(ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
	if(oralog_is_error(hp_error, retstat, print_errors))
	 errors++;
															 

	/* Statement ready - execute */
	debug("[logsoracle] executing insert on messages\n");
	retstat = OCIStmtExecute(hp_service, hp_stmt_msg, hp_error, (ub4) 1, (ub4) 0,
				(CONST OCISnapshot *) NULL, (OCISnapshot *) NULL, OCI_DEFAULT);
	if(oralog_is_error(hp_error, retstat, print_errors))
	 errors++;

	/* You can check recieved message ID like this:
	retstat = OCINumberToInt(hp_error, &msg_id, sizeof(int), OCI_NUMBER_SIGNED, &tmpval);
	if(oralog_is_error(hp_error, retstat, print_errors))
	 errors++;	
	debug("[logsoracle] recieved message id: %d\n", tmpval);
	*/
	
	/* Insert into recipients table */
	if(rcpts) {
	    for(i=0; rcpts[i] != NULL; i++) {
		
		check_string_len(rcpts[i]);
		
		debug("[logsoracle] binding recipients\n");
		retstat = OCIBindByName(hp_stmt_rcp, &bind_rcp[0], hp_error, (text *) ":recipient_uid", -1, (dvoid *)rcpts[i],
					ora_strlen(rcpts[i])+1, SQLT_STR, (dvoid *) 0,
					(ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
		if(oralog_is_error(hp_error, retstat, print_errors))
		 errors++;	    
	    
	    
		retstat = OCIBindByName(hp_stmt_rcp, &bind_rcp[1], hp_error, (text *) ":msg_id",
					-1, (dvoid *) &msg_id,
					(sword) sizeof(msg_id), SQLT_VNU, (dvoid *) 0,
					(ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
		if(oralog_is_error(hp_error, retstat, print_errors))
		 errors++;
		
		debug("[logsoracle] executing insert on recipients\n");
		retstat = OCIStmtExecute(hp_service, hp_stmt_rcp, hp_error, (ub4) 1, (ub4) 0,
					(CONST OCISnapshot *) NULL, (OCISnapshot *) NULL, OCI_DEFAULT);
		if(oralog_is_error(hp_error, retstat, print_errors))
		 errors++;
	    }
	}
				    

	/* Commit transaction */
	if(!errors) {
	    debug("[logsoracle] commit\n");
	    OCITransCommit(hp_service, hp_error, (ub4) 0);
	}
	else {
	    debug("[logsoracle] errors present - aborting transaction\n");
	    OCITransRollback(hp_service, hp_error, (ub4) OCI_DEFAULT);
	}


	/* Cleanup (bind handles should be removed as a part of statement) */
	if(hp_stmt_msg)
	    OCIHandleFree(hp_stmt_msg, OCI_HTYPE_STMT);
	if(hp_stmt_rcp)
	    OCIHandleFree(hp_stmt_rcp, OCI_HTYPE_STMT);
	if(hp_error)
	    OCIHandleFree(hp_error, OCI_HTYPE_ERROR);

	pthread_mutex_unlock(&oralog_oper_lock);
	return 0;
}
Example #14
0
void
Init_oci_number(VALUE cOCI8, OCIError *errhp)
{
    VALUE mMath;
    OCINumber num1, num2;
    VALUE obj_PI;
    signed long sl;

    id_power = rb_intern("**");
    id_cmp = rb_intern("<=>");
    id_finite_p = rb_intern("finite?");
    id_split = rb_intern("split");
    id_numerator = rb_intern("numerator");
    id_denominator = rb_intern("denominator");
    id_Rational = rb_intern("Rational");
    id_BigDecimal = rb_intern("BigDecimal");

    cOCINumber = rb_define_class("OraNumber", rb_cNumeric);
    mMath = rb_define_module_under(cOCI8, "Math");

    /* constants for internal use. */
    /* set const_p1 */
    sl = 1;
    OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_p1);
    /* set const_p10 */
    sl = 10;
    OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_p10);
    /* set const_m1 */
    sl = -1;
    OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_m1);
    /* set const_PI2 */
    sl = 2;
    OCINumberSetPi(errhp, &num1);
    OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &num2);
    OCINumberDiv(errhp, &num1 /* PI */, &num2 /* 2 */, &const_PI2);
    /* set const_mPI2 */
    OCINumberNeg(errhp, &const_PI2 /* PI/2 */, &const_mPI2);

    /* PI */
    OCINumberSetPi(errhp, &num1);
    obj_PI = oci8_make_ocinumber(&num1, errhp);

    /* The ratio of the circumference of a circle to its diameter. */
    rb_define_const(mMath, "PI", obj_PI);

    /*
     * module functions of OCI::Math.
     */
    rb_define_module_function(mMath, "atan2", omath_atan2, 2);

    rb_define_module_function(mMath, "cos", omath_cos, 1);
    rb_define_module_function(mMath, "sin", omath_sin, 1);
    rb_define_module_function(mMath, "tan", omath_tan, 1);

    rb_define_module_function(mMath, "acos", omath_acos, 1);
    rb_define_module_function(mMath, "asin", omath_asin, 1);
    rb_define_module_function(mMath, "atan", omath_atan, 1);

    rb_define_module_function(mMath, "cosh", omath_cosh, 1);
    rb_define_module_function(mMath, "sinh", omath_sinh, 1);
    rb_define_module_function(mMath, "tanh", omath_tanh, 1);

    rb_define_module_function(mMath, "exp", omath_exp, 1);
    rb_define_module_function(mMath, "log", omath_log, -1);
    rb_define_module_function(mMath, "log10", omath_log10, 1);
    rb_define_module_function(mMath, "sqrt", omath_sqrt, 1);

    rb_define_alloc_func(cOCINumber, onum_s_alloc);

    /* methods of OCI::Number */
    rb_define_method(rb_cObject, "OraNumber", onum_f_new, -1);
    rb_define_method_nodoc(cOCINumber, "initialize", onum_initialize, -1);
    rb_define_method_nodoc(cOCINumber, "initialize_copy", onum_initialize_copy, 1);
    rb_define_method_nodoc(cOCINumber, "coerce", onum_coerce, 1);

    rb_include_module(cOCINumber, rb_mComparable);

    rb_define_method(cOCINumber, "-@", onum_neg, 0);
    rb_define_method(cOCINumber, "+", onum_add, 1);
    rb_define_method(cOCINumber, "-", onum_sub, 1);
    rb_define_method(cOCINumber, "*", onum_mul, 1);
    rb_define_method(cOCINumber, "/", onum_div, 1);
    rb_define_method(cOCINumber, "%", onum_mod, 1);
    rb_define_method(cOCINumber, "**", onum_power, 1);
    rb_define_method(cOCINumber, "<=>", onum_cmp, 1);

    rb_define_method(cOCINumber, "floor", onum_floor, 0);
    rb_define_method(cOCINumber, "ceil", onum_ceil, 0);
    rb_define_method(cOCINumber, "round", onum_round, -1);
    rb_define_method(cOCINumber, "truncate", onum_trunc, -1);
    rb_define_method(cOCINumber, "round_prec", onum_round_prec, 1);

    rb_define_method(cOCINumber, "to_s", onum_to_s, 0);
    rb_define_method(cOCINumber, "to_char", onum_to_char, -1);
    rb_define_method(cOCINumber, "to_i", onum_to_i, 0);
    rb_define_method(cOCINumber, "to_f", onum_to_f, 0);
    rb_define_method(cOCINumber, "to_r", onum_to_r, 0);
    rb_define_method(cOCINumber, "to_d", onum_to_d, 0);
    rb_define_method(cOCINumber, "has_decimal_part?", onum_has_decimal_part_p, 0);
    rb_define_method_nodoc(cOCINumber, "to_onum", onum_to_onum, 0);

    rb_define_method(cOCINumber, "zero?", onum_zero_p, 0);
    rb_define_method(cOCINumber, "abs", onum_abs, 0);
    rb_define_method(cOCINumber, "shift", onum_shift, 1);
    rb_define_method(cOCINumber, "dump", onum_dump, 0);

    rb_define_method_nodoc(cOCINumber, "hash", onum_hash, 0);
    rb_define_method_nodoc(cOCINumber, "inspect", onum_inspect, 0);

    /* methods for marshaling */
    rb_define_method(cOCINumber, "_dump", onum__dump, -1);
    rb_define_singleton_method(cOCINumber, "_load", onum_s_load, 1);

    oci8_define_bind_class("OraNumber", &bind_ocinumber_vtable);
    oci8_define_bind_class("Integer", &bind_integer_vtable);
    oci8_define_bind_class("Float", &bind_float_vtable);
}
Example #15
0
int main()

{
    OGROCISession oSession;

    if( !oSession.EstablishSession( "warmerda", "LetoKing", 
                                    "gdal800.dreadfest.com" ) )
    {
        exit( 1 );
    }

    printf( "Session established.\n" );

    OGROCIStatement oStatement( &oSession );

    oStatement.Execute( "DROP TABLE fasttest" );
    oStatement.Execute( "CREATE TABLE fasttest (ifld INTEGER, cfld VARCHAR(4000), shape mdsys.sdo_geometry)" );
//    oStatement.Execute( "CREATE TABLE fasttest (ifld INTEGER, cfld VARCHAR(4000))" );

/* -------------------------------------------------------------------- */
/*      Prepare insert statement.                                       */
/* -------------------------------------------------------------------- */
    
    oStatement.Prepare( "INSERT INTO fasttest VALUES "
                        "(:field_1, :field_2, :field_3)" );
//    oStatement.Prepare( "INSERT INTO fasttest VALUES "
//                        "(:field_1, :field_2)" );
    
/* -------------------------------------------------------------------- */
/*      Do a conventional bind.                                         */
/* -------------------------------------------------------------------- */
    int anField1[100];
    char szField2[100*4];
    int anGType[100];
    int anSRID[100];
    OCIArray *aphElemInfos[100];
    OCIArray *aphOrdinates[100];
    SDO_GEOMETRY_TYPE  aoGeometries[100];
    SDO_GEOMETRY_ind   aoGeometryIndicators[100];
    SDO_GEOMETRY_TYPE *apoGeomMap[100];
    SDO_GEOMETRY_ind  *apoGeomIndMap[100];
    double adfX[100], adfY[100];

    memset( aphElemInfos, 0, sizeof(OCIArray*) * 100 );
    memset( aphOrdinates, 0, sizeof(OCIArray*) * 100 );
    memset( aoGeometries, 0, sizeof(SDO_GEOMETRY) * 100 );
    memset( aoGeometryIndicators, 0, sizeof(SDO_GEOMETRY_ind) * 100 );

    if( oStatement.BindScalar( ":field_1", anField1, 
                              sizeof(int), SQLT_INT ) != CE_None )
        exit( 1 );
    
    if( oStatement.BindScalar( ":field_2", szField2, 4, SQLT_STR ) != CE_None )
        exit( 1 );

    if( oStatement.BindObject( ":field_3", apoGeomMap, oSession.hGeometryTDO, 
                               (void**)apoGeomIndMap ) != CE_None )
        exit( 1 );

/* -------------------------------------------------------------------- */
/*      Create array of arrays for elem_info and ordinates.             */
/* -------------------------------------------------------------------- */
    int iBindRow;
    for( iBindRow = 0; iBindRow < 100; iBindRow++ )
    {
        if( oSession.Failed(
                OCIObjectNew( oSession.hEnv, oSession.hError, 
                              oSession.hSvcCtx, OCI_TYPECODE_VARRAY,
                              oSession.hElemInfoTDO, (dvoid *)NULL, 
                              OCI_DURATION_SESSION,
                              FALSE, (dvoid **) (aphElemInfos + iBindRow)),
                "OCIObjectNew()") )
            exit( 1 );

        if( oSession.Failed(
                OCIObjectNew( oSession.hEnv, oSession.hError, 
                              oSession.hSvcCtx, OCI_TYPECODE_VARRAY,
                              oSession.hOrdinatesTDO, (dvoid *)NULL, 
                              OCI_DURATION_SESSION,
                              FALSE, (dvoid **) (aphOrdinates + iBindRow)),
                "OCIObjectNew()") )
            exit( 1 );
    }

/* -------------------------------------------------------------------- */
/*      Populate VARRAYs                                                */
/* -------------------------------------------------------------------- */
    int iRow;

    for( iRow = 0; iRow < 100; iRow++ )
    {
        anField1[iRow] = iRow;                                         
        sprintf( szField2 + iRow*4, "%3d", iRow );
        anGType[iRow] = 3001;
        anSRID[iRow] = -1;
        adfX[iRow] = 100.0 + iRow;
        adfY[iRow] = 100.0 - iRow;

        //---------------------------------------------------------------
        int anElemInfo[3], nElemInfoCount;
        OCINumber oci_number; 
        int i;
        
        nElemInfoCount = 3;
        anElemInfo[0] = 1;
        anElemInfo[1] = 1;
        anElemInfo[2] = 1;

        // Prepare the VARRAY of ordinate values. 
        for (i = 0; i < nElemInfoCount; i++)
        {
            if( oSession.Failed( 
                OCINumberFromInt( oSession.hError, 
                                  (dvoid *) (anElemInfo + i),
                                  (uword)sizeof(int),
                                  OCI_NUMBER_SIGNED,
                                  &oci_number),
                "OCINumberFromInt") )
                exit( 1 );

            if( oSession.Failed( 
                OCICollAppend( oSession.hEnv, oSession.hError,
                               (dvoid *) &oci_number,
                               (dvoid *)0, aphElemInfos[iRow]),
                "OCICollAppend") )
                exit( 1 );
        }

        //---------------------------------------------------------------
        double adfOrdinates[6];
        int    nOrdCount;

        nOrdCount = 3;
        adfOrdinates[0] = iRow + 100;
        adfOrdinates[1] = iRow - 100;
        adfOrdinates[2] = 0.0;
        adfOrdinates[3] = iRow + 100;
        adfOrdinates[4] = iRow - 100;
        adfOrdinates[5] = 0.0;

        // Prepare the VARRAY of ordinate values. 
        for (i = 0; i < nOrdCount; i++)
        {
            if( oSession.Failed( 
                OCINumberFromReal( oSession.hError, 
                                  (dvoid *) (adfOrdinates + i),
                                  (uword)sizeof(double),
                                  &oci_number),
                "OCINumberFromReal") )
                exit( 1 );

            if( oSession.Failed( 
                OCICollAppend( oSession.hEnv, oSession.hError,
                               (dvoid *) &oci_number,
                               (dvoid *)0, aphOrdinates[iRow]),
                "OCICollAppend") )
                exit( 1 );
        }

        // -------------------------------------------------------------
        SDO_GEOMETRY_TYPE *poGeom = aoGeometries + iRow;
        SDO_GEOMETRY_ind  *poInd = aoGeometryIndicators + iRow;

        poInd->sdo_point._atomic = OCI_IND_NULL;

        if( oSession.Failed( 
                OCINumberFromInt( oSession.hError, 
                                  (dvoid *) (anGType + iRow),
                                  (uword)sizeof(int),
                                  OCI_NUMBER_SIGNED,
                                  &(poGeom->sdo_gtype)),
                "OCINumberFromInt" ) )
            exit( 1 );

        if( oSession.Failed( 
                OCINumberFromInt( oSession.hError, 
                                  (dvoid *) (anSRID + iRow),
                                  (uword)sizeof(int),
                                  OCI_NUMBER_SIGNED,
                                  &(poGeom->sdo_srid)),
                "OCINumberFromInt" ) )
            exit( 1 );

        poGeom->sdo_elem_info = aphElemInfos[iRow];
        poGeom->sdo_ordinates = aphOrdinates[iRow];

        apoGeomMap[iRow] = poGeom;
        apoGeomIndMap[iRow] = poInd;
    }

/* -------------------------------------------------------------------- */
/*      Execute the statement.                                          */
/* -------------------------------------------------------------------- */
    int iGroup;

    for( iGroup = 0; iGroup < 2; iGroup++ )
    {
        if( oSession.Failed( 
                OCIStmtExecute( oSession.hSvcCtx, oStatement.GetStatement(), 
                                oSession.hError, (ub4) 100, (ub4)0, 
                                (OCISnapshot *)NULL, (OCISnapshot *)NULL, 
                                (ub4) OCI_COMMIT_ON_SUCCESS ),
                "OCIStmtExecute" ) )
            exit( 1 );
    }

    printf( "Successful completion\n" );
    exit( 0 );
}
Example #16
0
/* Function to modify the data of an inherited object */
static void modifyFunction ()
{ 
  OCIDefine *defhp = (OCIDefine *)0; 
  OCIRef *sub_ref = (OCIRef *)0;
  i_residence elem;
  i_residence *elemptr = (i_residence *)0;
  i_manager *sub_obj = (i_manager *)0;
  ub4 subSize = 0;
  ub4 sizeUB4 = sizeof (ub4);
  OCIType *mtype = (OCIType *)0;

  text *name = (text*)"JENNY";
  ub4 name_len=(ub4)strlen( (char * ) name);
  ub4 ssn = 808; /* Data for ssn */
  ub4 addr_hno = 800; /*Data for  hno of addr */
  text *addr_street = (text *)"Laurel Road"; /*Data for street of addr */
  ub4 addr_streetLen = (ub4)strlen( (char *)addr_street);
  ub4 altadrs_hno = 800; /*data for hno of altadrs */
  text *altadrs_street = (text *)"Shoreline Street"; /*Data for street of altadrs */
  ub4 altadrs_streetLen = (ub4)strlen( (char *)altadrs_street);
  ub4 empno = 8888; /* data for empno */

  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; /* Loop counter */
  OCIHandleAlloc (envhp, (dvoid **)&stmthp, OCI_HTYPE_STMT, (size_t)0,
    (dvoid **)0);

  if ((status = OCIStmtPrepare (stmthp, errhp, (text *)updateSql, 
    (ub4)strlen((char *)updateSql),OCI_NTV_SYNTAX, OCI_DEFAULT)) != OCI_SUCCESS)
  {
    printf ("OCIStmtPrepare - Fail\n");
  }

  if (( status = OCIObjectNew(envhp, errhp, svchp, OCI_TYPECODE_REF,
    (OCIType *)0, (dvoid *)0, OCI_DURATION_DEFAULT, FALSE, 
    (dvoid **) &sub_ref)) != OCI_SUCCESS)
  {
    printf ("OCIObjectNew - Failure\n");
  }

  if ((status = OCIDefineByPos(stmthp, &defhp, errhp, (ub4) 1,
    (dvoid *) 0, (sb4) 0, SQLT_REF, (dvoid *) 0,
    (ub2 *)0, (ub2 *)0, (ub4) OCI_DEFAULT)) != OCI_SUCCESS)
  {
    printf ("OCIDefineByPos - Failure \n");
  }

  if ((status = OCIDefineObject(defhp, errhp, (OCIType *)0,
    (dvoid **)&sub_ref, (ub4 *)&subSize, (dvoid **) 0, (ub4 *) 0))
    != OCI_SUCCESS)
  {
    printf ("OCIDefineObject - Failure \n");
  }
 
  printf ("\nExecuting the statement:%s\n", updateSql); 
  if (OCIStmtExecute (svchp, stmthp, errhp, (ub4)1, (ub4)0,
    (OCISnapshot *)0, (OCISnapshot *)0, OCI_COMMIT_ON_SUCCESS ) != OCI_SUCCESS)
  {
    printf("OCIStmtExecute - Failure \n");
  }
  else
  {
    printf("OCIStmtExecute - Success\n");
    if ((status = OCIObjectPin(envhp, errhp, sub_ref, (OCIComplexObject *)0,
      OCI_PIN_ANY, OCI_DURATION_SESSION, OCI_LOCK_NONE, 
      (dvoid **) &sub_obj)) != OCI_SUCCESS)
    {
      printf("OCIObjectPin - Failure \n");
    }
    else
    {
      printf ("\nDisplaying the original data from the employee table \n");
      display (sub_obj);
      printf ("\nModifying the data present in the object\n");
      if ((status = OCIObjectMarkUpdate (envhp, errhp, (dvoid *)sub_obj))
        != OCI_SUCCESS)
      {
        printf ("OCIObjectMarkUpdate - Fail\n");
      }
      else
      {
        printf ("OCIObjectMarkUpdate - Success\n");
      } 
      OCINumberFromInt (errhp, (dvoid *)&ssn, sizeof(ssn), OCI_NUMBER_UNSIGNED,
        &(sub_obj->_super.ssn));
      OCINumberFromInt (errhp, (dvoid *)&empno, sizeof(empno), 
                       OCI_NUMBER_UNSIGNED, &(sub_obj->empno));
      OCINumberFromInt (errhp, (dvoid *)&addr_hno, sizeof(addr_hno),
               OCI_NUMBER_UNSIGNED, &(sub_obj->_super.addr.hno));
      OCIStringAssignText (envhp, errhp, (text *)name, (ub2)name_len,
        &(sub_obj->_super.name));
      OCIStringAssignText (envhp, errhp, (text *)addr_street, (ub2)addr_streetLen,
        &(sub_obj->_super.addr.street));
      OCITableFirst(envhp, errhp, (CONST OCITable*)sub_obj->_super.altadrs, 
         &index1);
      OCICollGetElem(envhp, errhp, (OCIColl *)sub_obj->_super.altadrs, 
        index1, (boolean *)&eoc, (dvoid **)&elemptr, (dvoid **)0);
      OCINumberFromInt (errhp, (dvoid *)&altadrs_hno, sizeof(altadrs_hno),
        OCI_NUMBER_UNSIGNED, &(elemptr->hno));
      OCIStringAssignText (envhp, errhp, (text *)altadrs_street, (ub2)altadrs_streetLen,
        &(elemptr->street));
      for (count = 0; count < NUMREC-1; ++count)
      {
        altadrs_hno += 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 **)&elemptr, (dvoid **)0);
        OCINumberFromInt (errhp, (dvoid *)&altadrs_hno, sizeof(altadrs_hno),
          OCI_NUMBER_UNSIGNED, &(elemptr->hno));
        OCIStringAssignText (envhp, errhp, (text *)altadrs_street, (ub2)altadrs_streetLen,
          &(elemptr->street));
        index1 = index2;
      } 
      index1 = 0;
      index2 = 0;
      
      OCITableFirst(envhp, errhp, (CONST OCITable*)sub_obj->workadd, &index1);
      OCICollAssignElem (envhp, errhp, index1, (dvoid *)workadd[count],
       (dvoid *)0, (OCIColl *)sub_obj->workadd);
      for (count = 0; count < NUMREC; ++count)
      {
        OCITableNext(envhp, errhp, index1,(CONST OCITable*) sub_obj->workadd,
          &index2, &eoc);
        OCICollAssignElem (envhp, errhp, index1, (dvoid *)workadd[count],
          (dvoid *)0, (OCIColl *)sub_obj->workadd);
        index1 = index2;
      } 
      
      if ((status = OCIObjectFlush(envhp, errhp, sub_obj)) != OCI_SUCCESS)
      {
        printf ("OCIObjectFlush - Fail\n");
      }
      else
      {
        printf ("OCIObjectFlush - Success\n");
      }
      printf ("Refreshing the object\n");
      if ((status = OCIObjectRefresh(envhp, errhp, (dvoid *)sub_obj))
        != OCI_SUCCESS)
      {
        printf ("OCIObjectRefresh - Fail\n");
      }
      else
      {
        printf ("OCIObjectRefresh - Success\n");
      }
      printf ("\nDisplaying the data in the employee table after the refresh\n");
      display (sub_obj);

      printf ("\nModifying the data present in the object once again\n");
      ssn = 606; /* Data for ssn */
      addr_hno = 200; /*Data for  hno of addr */
      addr_street = (text *)"Main Street"; /*Data for street of addr */
      addr_streetLen = (ub4)strlen( (char *)addr_street);
      altadrs_hno = 600; /*data for hno of altadrs */
      altadrs_street = (text *)"Shell Blvd";/*Data for street of altadrs*/
      altadrs_streetLen = (ub4)strlen( (char *)altadrs_street);
      empno = 6666; /* data for empno */

      if ((status = OCIObjectMarkUpdate (envhp, errhp, (dvoid *)sub_obj))
        != OCI_SUCCESS)
      {
        printf ("OCIObjectMarkUpdate - Fail\n");
      }
      else
      {
        printf ("OCIObjectMarkUpdate - Success\n");
      }
      index1 = 0;
      index2 = 0;
      OCINumberFromInt (errhp, (dvoid *)&ssn, sizeof(ssn), OCI_NUMBER_UNSIGNED,
        &(sub_obj->_super.ssn));
      OCINumberFromInt (errhp, (dvoid *)&empno, sizeof(empno), OCI_NUMBER_UNSIGNED,
        &(sub_obj->empno));
      OCINumberFromInt (errhp, (dvoid *)&addr_hno, sizeof(addr_hno),
        OCI_NUMBER_UNSIGNED, &(sub_obj->_super.addr.hno));
      OCIStringAssignText (envhp, errhp, (text *)addr_street, 
         (ub2)addr_streetLen, &(sub_obj->_super.addr.street));
      OCITableFirst(envhp, errhp,(CONST OCITable*)sub_obj->_super.altadrs,
          &index1);
      OCICollGetElem(envhp, errhp, (OCIColl *)sub_obj->_super.altadrs, 
        index1, (boolean *)&eoc, (dvoid **)&elemptr, (dvoid **)0);
      OCINumberFromInt (errhp, (dvoid *)&altadrs_hno, sizeof(altadrs_hno),
        OCI_NUMBER_UNSIGNED, &(elemptr->hno));
      OCIStringAssignText (envhp, errhp, (text *)altadrs_street, (ub2)altadrs_streetLen,
        &(elemptr->street));
      for (count = 0; count < NUMREC-1; ++count)
      {
        altadrs_hno += 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 **)&elemptr, (dvoid **)0);
        OCINumberFromInt (errhp, (dvoid *)&altadrs_hno, sizeof(altadrs_hno),
          OCI_NUMBER_UNSIGNED, &(elemptr->hno));
        OCIStringAssignText (envhp, errhp, (text *)altadrs_street, (ub2)altadrs_streetLen,
          &(elemptr->street));
        index1 = index2;
      } 
      index1 = 0;
      index2 = 0;
      
      OCITableFirst(envhp, errhp, (CONST OCITable*)sub_obj->workadd, &index1);
      OCICollAssignElem (envhp, errhp, index1, (dvoid *)workadd[count],
       (dvoid *)0, (OCIColl *)sub_obj->workadd);
      for (count = 0; count < NUMREC; ++count)
      {
        OCITableNext(envhp, errhp, index1, (CONST OCITable*)sub_obj->workadd,
          &index2, &eoc);
        OCICollAssignElem (envhp, errhp, index1, (dvoid *)workadd[count],
          (dvoid *)0, (OCIColl *)sub_obj->workadd);
        index1 = index2;
      } 
      if ((status = OCICacheFlush (envhp, errhp, svchp, NULL, NULL, &sub_ref))
        != OCI_SUCCESS)
      {
        printf ("OCICacheFlush - Fail\n");
      }
      else
      {
        printf ("OCICacheFlush - Success\n");
      }
    }
        
    if ((status = OCITransCommit (svchp, errhp, OCI_DEFAULT)) != OCI_SUCCESS)
    {
      printf ("OCITransCommit - Fail\n");
    }
    else
      printf ("OCITransCommit - Success\n");
  }
  OCIHandleFree((dvoid *) stmthp, OCI_HTYPE_STMT);

} /* end of modifyFunction() */
Example #17
0
/* Function to insert an instance of the subtype into a supertype table */
static void insertFunction()
{
  OCIBind *bindhp = (OCIBind *)0;
  i_residence elem;
  i_residence *elemptr = &elem;
  i_manager *sub_obj = (i_manager *)0;
  i_manager_ind ind;
  OCIType *i_manager_tdo = (OCIType *)0;

  ub4 subSize = 0;
  ub4 sizeUB4 = sizeof (ub4);
  sb4 size = 0;
  text *name = (text*)"JENNY";
  ub4 name_len =(ub4)( strlen( (char * ) name));
  ub4 ssn = 303; /* Data for ssn */
  ub4 addr_hno = 33; /*Data for  hno of addr */
  text *addr_street = (text *)"T33"; /*Data for street of addr */
  ub4 addr_streetLen = (ub4)(strlen( (char *)addr_street));
  ub4 altadrs_hno = 333; /*data for hno of altadrs */
  text *altadrs_street = (text *)"T333"; /*Data for street of altadrs */
  ub4 altadrs_streetLen = (ub4)(strlen( (char *)altadrs_street));
  ub4 empno = 3333; /* data for empno */

  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; /* Loop counter */

  memset(&ind, 0, sizeof(ind));
  memset(elemptr, 0, sizeof(elem));
  OCIHandleAlloc (envhp, (dvoid **)&stmthp, OCI_HTYPE_STMT, (size_t)0,
    (dvoid **)0);

  if ((status = OCIStmtPrepare (stmthp, errhp, (text *)insertSql, 
    (ub4)strlen((char *)insertSql),OCI_NTV_SYNTAX, OCI_DEFAULT)) != OCI_SUCCESS)
  {
    printf ("OCIStmtPrepare - Fail\n");
  }

  if ((status = OCIBindByName(stmthp, &bindhp, errhp, (text *)":v1",
      (sb4) -1, (dvoid *)0, (sb4)0, SQLT_NTY, (dvoid *)0, (ub2 *)0, (ub2 *)0,
      (ub4)0, (ub4 *)0, OCI_DEFAULT)) != OCI_SUCCESS)
  {
    printf ("OCIBindByName - Failure \n");
  }

  if ((status = OCITypeByName (envhp, errhp, svchp, (CONST text *)0, (ub4)0,
    (CONST text *)"I_MANAGER", (ub4)strlen ((char *)"I_MANAGER"),
    (CONST text *)0, (ub4)0, OCI_DURATION_SESSION, OCI_TYPEGET_HEADER,
    &i_manager_tdo)) != OCI_SUCCESS)
  {
    printf ("OCITypeByName - Fail\n");
  }

  if (( status = OCIObjectNew(envhp, errhp, svchp, OCI_TYPECODE_OBJECT,
    (OCIType *)i_manager_tdo, (dvoid *)0, OCI_DURATION_SESSION, TRUE,
    (dvoid **) &sub_obj)) != OCI_SUCCESS)
  {
    printf ("OCIObjectNew - Failure\n");
  }
  OCINumberFromInt (errhp, (dvoid *)&ssn, sizeof(ssn), OCI_NUMBER_UNSIGNED,
    &(sub_obj->_super.ssn));
  OCINumberFromInt (errhp, (dvoid *)&empno, sizeof(empno), OCI_NUMBER_UNSIGNED,
    &(sub_obj->empno));
  
  OCINumberFromInt (errhp, (dvoid *)&addr_hno, sizeof(addr_hno),OCI_NUMBER_UNSIGNED,
    &(sub_obj->_super.addr.hno));
      
  OCIStringAssignText (envhp, errhp, (text *)name, (ub2)name_len,
    &(sub_obj->_super.name));
  OCIStringAssignText (envhp, errhp, (text *)addr_street, (ub2)addr_streetLen,
    &(sub_obj->_super.addr.street));
  for (count = 0; count < NUMREC; ++count)
  {
    OCIStringAssignText (envhp, errhp, (text *)altadrs_street, (ub2)altadrs_streetLen,
      &(elemptr->street));  
    OCINumberFromInt (errhp, (dvoid *)&altadrs_hno, sizeof(altadrs_hno),
      OCI_NUMBER_UNSIGNED, &(elemptr->hno));
    if (( status = OCICollAppend (envhp, errhp, (dvoid *)elemptr, (dvoid *)&ind,
      (OCIColl *)sub_obj->_super.altadrs)) != OCI_SUCCESS)
    {
      printf ("OCICollAppend - Fail\n");
    }
    altadrs_hno ++;
  } 
  for (count = 0; count < NUMREC; ++count)
  {
    if (( status = OCICollAppend (envhp, errhp, (dvoid *)workadd[count], 
      (dvoid *)&ind, (OCIColl *)sub_obj->workadd)) != OCI_SUCCESS)
    {
      printf ("OCICollAppend - Fail\n");
    }
  } 
  OCITableSize(envhp, errhp,(CONST OCITable*) (sub_obj->_super.altadrs), &size);
  OCITableSize(envhp, errhp,(CONST OCITable*) (sub_obj->workadd), &size);

  if (OCIBindObject(bindhp, errhp, i_manager_tdo,
    (dvoid **) &sub_obj, (ub4 *)0, (dvoid **)&ind , (ub4 *) 0) != OCI_SUCCESS)
  {
    printf("OCIBindObject - Failure \n");
  }

  printf ("\nExecuting the statement:%s\n", insertSql); 
  if (OCIStmtExecute (svchp, stmthp, errhp, (ub4)1, (ub4)0,
    (OCISnapshot *)0, (OCISnapshot *)0, OCI_COMMIT_ON_SUCCESS ) != OCI_SUCCESS)
  {
    printf("OCIStmtExecute - Failure \n");
  }
  else
    printf("OCIStmtExecute - Success\n");

  OCIHandleFree((dvoid *) stmthp, OCI_HTYPE_STMT);
}/* End on insertFunction() */