Beispiel #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);
}
Beispiel #2
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 *) */