Ejemplo n.º 1
0
static VALUE
to_ruby_value(plruby_context_t *ctx, char type, void *arg, int pos)
{
    OCIString *str;
    OCINumber *num;
    double *d;
    char *cstr;
    ub4 size;
    double dbl;

    switch (type) {
    case ' ':
        trace(ctx, 1, "arg[%d]: nil", pos);
        return Qnil;
    case 'v':
        str = (OCIString *)arg;
        cstr = (char*)OCIStringPtr(ctx->envhp, str);
        size = OCIStringSize(ctx->envhp, str);
        trace(ctx, 1, "arg[%d]: %.*s", pos, size, cstr);
        return rb_enc_str_new(cstr, size, oracle_encoding);
    case 'n':
        num = (OCINumber *)arg;
        chk(OCINumberToReal(ctx->errhp, num, sizeof(dbl), &dbl));
        trace(ctx, 1, "arg[%d]: %f", pos, dbl);
        return rb_float_new(dbl);
    case 'd':
        d = (double *)arg;
        trace(ctx, 1, "arg[%d]: %f", pos, *d);
        return rb_float_new(*d);
    }
    rb_raise(rb_eRuntimeError, "Unsupported type %d", type);
}
sword _fetchDataIntoRealArray(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);
		
		double realValue;
		
		for(unsigned int i = 0; i < itemCount; ++i)
		{	
			PA_YieldAbsolute();
			
			if(cursor->indicatorLists.at(pos).at(i) != -1)
			{		
				OCINumberToReal(cursor->errhp, &cursor->arrayOfNumbers.at(pos).at(i), sizeof(double), &realValue);
				PA_SetRealInArray(variable, i + 1, realValue);
				
			}else{
				setRealArrayValueNull(variable, i + 1);
			}
			
		}
		
		PA_SetPointerValue(&cursor->pointers.at(pos), variable);	
		
	}
	
	return cursor->rowsFetched;	
}
Ejemplo n.º 3
0
double oci8_onum_to_dbl(OCINumber *s, OCIError *errhp)
{
    if (oci8_float_conversion_type_is_ruby) {
        char buf[256];
        sword rv;

        rv = oranumber_to_str(s, buf, sizeof(buf));
        if (rv <= 0) {
            char buf[ORANUMBER_DUMP_BUF_SIZ];

            oranumber_dump(s, buf);
            rb_raise(eOCIException, "Invalid internal number format: %s", buf);
        }
        if (strcmp(buf, "~") == 0) {
            return INFINITY;
        } else if (strcmp(buf, "-~") == 0) {
            return -INFINITY;
        }
        return rb_cstr_to_dbl(buf, Qtrue);
    } else {
        double dbl;

        chkerr(OCINumberToReal(errhp, s, sizeof(double), &dbl));
        return dbl;
    }
}
Ejemplo n.º 4
0
VALUE oci8_make_float(OCINumber *s, OCIError *errhp)
{
    double dbl;

    oci_lc(OCINumberToReal(errhp, s, sizeof(double), &dbl));
    return rb_float_new(dbl);
}
Ejemplo n.º 5
0
double OWStatement::GetElement( OCIArray** ppoData,
                               int nIndex, double* pdfResult )
{
    boolean        exists;
    OCINumber      *oci_number;
    double         element_type;

    *pdfResult = 0.0;

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

    if( CheckError( OCINumberToReal(
        hError,
        oci_number,
        (uword) sizeof(double),
        (dvoid *) &element_type ), hError ) )
    {
        return *pdfResult;
    }

    *pdfResult = (double) element_type;

    return *pdfResult;
}
Ejemplo n.º 6
0
/*
 *  call-seq:
 *     onum.to_f -> float
 *
 *  Return the value as a <code>Float</code>.
 *
 */
static VALUE onum_to_f(VALUE self)
{
    OCIError *errhp = oci8_errhp;
    double dbl;

    oci_lc(OCINumberToReal(errhp, _NUMBER(self), sizeof(dbl), &dbl));
    return rb_float_new(dbl);
}
Ejemplo n.º 7
0
value caml_oci_get_double(value handles, value defs) {
  CAMLparam2(handles, defs);
  oci_define_t d = Oci_defhandle_val(defs);
  oci_handles_t h = Oci_handles_val(handles);

  double r;

  sword x = OCINumberToReal(h.err, d.ptr, sizeof(double), &r);
  CHECK_OCI(x, h);

  CAMLreturn(caml_copy_double(r));
}
Ejemplo n.º 8
0
double OWStatement::GetDouble( OCINumber* ppoData )
{
    double dfRetVal = 0.0;

    CheckError( OCINumberToReal(
        hError,
        ppoData,
        (uword) sizeof(dfRetVal),
        (dvoid*) &dfRetVal ),
        hError );

    return dfRetVal;
}
sword _fetchDataIntoRealField(ORACLE_SQL_CURSOR *cursor, PA_Variable variable, unsigned int pos)
{		
	if(cursor->rowsFetched)
	{
		double realValue;
		
		if(cursor->indicators.at(pos) != -1)
		{	
			OCINumberToReal(cursor->errhp, &cursor->numbers.at(pos), sizeof(double), &realValue);
			PA_SetRealField(variable.uValue.fTableFieldDefinition.fTableNumber, variable.uValue.fTableFieldDefinition.fFieldNumber, realValue);	
			
		}else{
			setRealFieldValueNull(variable);
		}
			
	}
	
	return cursor->rowsFetched;
}
sword _fetchDataIntoRealVariable(ORACLE_SQL_CURSOR *cursor, PA_Variable variable, unsigned int pos)
{		
	if(cursor->rowsFetched)
	{
		double realValue;
		
		if(cursor->indicators.at(pos) != -1)
		{	
			OCINumberToReal(cursor->errhp, &cursor->numbers.at(pos), sizeof(double), &realValue);
			PA_SetRealVariable(&variable, realValue);	
			
		}else{
			setRealVariableValueNull(variable);
		}
		
		PA_SetPointerValue(&cursor->pointers.at(pos), variable);		
	}
	
	return cursor->rowsFetched;
}
Ejemplo n.º 11
0
boolean OCI_NumberGet
(
    OCI_Connection *con,
    void           *number,
    uword           size,
    uword           type,
    int             sqlcode,
    void           *out_value
)
{
    boolean res = TRUE;

    OCI_CHECK(con       == NULL, FALSE);
    OCI_CHECK(number    == NULL, FALSE);
    OCI_CHECK(out_value == NULL, FALSE);

#if OCI_VERSION_COMPILE < OCI_10_1

    OCI_NOT_USED(sqlcode);

#endif

    if (type == OCI_NUM_NUMBER)
    {
        memcpy(out_value, number, size);
    }
    else if (type & OCI_NUM_DOUBLE || type & OCI_NUM_FLOAT)
    {

    #if OCI_VERSION_COMPILE >= OCI_10_1

        if ((OCILib.version_runtime >= OCI_10_1) && ((sqlcode != SQLT_VNU)))
        {
            if (((type & OCI_NUM_DOUBLE) && (sqlcode == SQLT_BDOUBLE)) ||
                ((type & OCI_NUM_FLOAT ) && (sqlcode == SQLT_BFLOAT )))
            {
                memcpy(out_value, number, size);
            }
            else if (type & OCI_NUM_DOUBLE && sqlcode == SQLT_BFLOAT)
            {
                *((double *) out_value) = (double) *((float *) number);
            }
            else if (type & OCI_NUM_FLOAT && sqlcode == SQLT_BDOUBLE)
            {
                 *((float *) out_value) = (float) *((double *) number);
            }
        }
        else

    #endif

        {
            OCI_CALL2
            (
                res, con,

                OCINumberToReal(con->err, (OCINumber *) number, size, out_value)
            )
        }
    }  
    else
    {