Ejemplo n.º 1
0
void BindParXML::init(SqlStatement &stmt)
{
	sword res;
	xmltdo = 0;

	_xmlvaluep = (OCIXMLType**) calloc(_cnt, sizeof(OCIXMLType*));
	_xmlindp = (OCIInd*) calloc(_cnt, sizeof(OCIInd));

//	xmlsize = new ub4 [_cnt];

//	std::cout << "BindParXML::init\n";

	res = OCICALL(OCITypeByName(_stmt._env, _stmt._errh, _stmt._conn._svc_ctx,
	                            (const oratext*)"SYS", strlen("SYS"),
	                            (const oratext*)"XMLTYPE", strlen("XMLTYPE"),
	                            0, 0,
	                            OCI_DURATION_SESSION, OCI_TYPEGET_HEADER,
	                            (OCIType**) &xmltdo
	                           ));
	oci_check_error(__TROTL_HERE__, _stmt._errh, res);

	if(xmltdo == NULL)
		throw OciException(__TROTL_HERE__, "Unknown datatype in the database: SYS.XMLTYPE");

	for(int i=0; i<g_OCIPL_BULK_ROWS; i++)
	{
		_xmlvaluep[i] = NULL;
		_xmlindp[i] = OCI_IND_NULL;
	}
//	for(int i=0; i<_cnt; i++)
//	{
////		xmlsize[i] = 0;
//		res = OCICALL(OCIObjectNew(conn._env,
//				conn._env._errh,
//				conn._svc_ctx,
//				OCI_TYPECODE_OPAQUE,
//				xmltdo,
//				0,
//				OCI_DURATION_SESSION,
//				FALSE,
//				(dvoid **) &xml[i]
//		));
//		oci_check_error(__TROTL_HERE__, conn._env._errh, res);
//	}
}
Ejemplo n.º 2
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() */
Ejemplo n.º 3
0
OCI_TypeInfo * OCI_API OCI_TypeInfoGet2(OCI_Library *pOCILib, OCI_Connection *con, const mtext *name, 
					unsigned int type, ExceptionSink* xsink)
{
    OCI_TypeInfo *typinf = NULL;
    OCI_Item     *item   = NULL;
    OCIDescribe *dschp   = NULL;
    OCIParam *parmh1     = NULL;
    OCIParam *parmh2     = NULL;
    mtext *str           = NULL;
    //int etype            = OCI_DESC_COLUMN;
    int ptype            = 0;
    ub1 item_type        = 0;
    ub4 attr_type        = 0;
    ub4 num_type         = 0;
    boolean res          = TRUE;
    boolean found        = FALSE;
    ub2 i;
    
    mtext obj_schema[OCI_SIZE_OBJ_NAME+1];
    mtext obj_name[OCI_SIZE_OBJ_NAME+1];

    OCI_CHECK_INITIALIZED2(pOCILib, NULL);

    OCI_CHECK_PTRQ(pOCILib, OCI_IPC_CONNECTION, con, NULL, xsink);
    OCI_CHECK_PTRQ(pOCILib, OCI_IPC_STRING, name, NULL, xsink);

    if (type == OCI_TIF_TABLE)
        item_type = OCI_PTYPE_TABLE;
    else if (type == OCI_TIF_VIEW)
        item_type = OCI_PTYPE_VIEW;
    else if (type == OCI_TIF_TYPE)
        item_type = OCI_PTYPE_TYPE;
    else
        return NULL;

    obj_schema[0] = 0;
    obj_name[0] = 0;

    /* is the schema provided in the object name ? */

    for (str = (mtext *) name; *str != 0; str++)
    {
        if (*str == MT('.'))
        {
            mtsncat(obj_schema, name, str-name);
            mtsncat(obj_name, ++str, (size_t) OCI_SIZE_OBJ_NAME);
            break;
        }
    }

    /* if the schema is not provided, we just copy the object name */

    if (obj_name[0] == 0)
    {
        mtsncat(obj_name, name, (size_t) OCI_SIZE_OBJ_NAME);
    }

    /* type name must be uppercase */

    for (str = obj_name; *str != 0; str++)
        *str = (mtext) mttoupper(*str);

    /* schema name must be uppercase */

    for (str = obj_schema; *str != 0; str++)
        *str = (mtext) mttoupper(*str);

    /* first try to find it in list */

    item = con->tinfs->head;

    /* walk along the list to find the type */

    while (item != NULL)
    {
        typinf = (OCI_TypeInfo *) item->data;
     
        if ((typinf != NULL) && (typinf->type == type))
        {
            if ((mtscasecmp(typinf->name,   obj_name  ) == 0) &&
                (mtscasecmp(typinf->schema, obj_schema) == 0))
            {
                found = TRUE;
                break;
            }
        }

        item = item->next;
    } 

    /* Not found, so create type object */

    if (found == FALSE)
    {
        item = OCI_ListAppend(pOCILib, con->tinfs, sizeof(OCI_TypeInfo));

        res = (item != NULL);

        if (res == TRUE)
        {
            typinf = (OCI_TypeInfo *) item->data;

            typinf->type        = type;
            typinf->con         = con;
            typinf->name        = mtsdup(pOCILib, obj_name);
            typinf->schema      = mtsdup(pOCILib, obj_schema);
            typinf->struct_size = 0;

            res = (OCI_SUCCESS == OCI_HandleAlloc2(pOCILib, pOCILib->env,
                                                  (dvoid **) (void *) &dschp, 
                                                  OCI_HTYPE_DESCRIBE, (size_t) 0, 
                                                  (dvoid **) NULL));
        }

        if (res == TRUE)
        {
            if (type == OCI_TIF_TYPE)
            {            
                void *ostr1 = NULL;
                void *ostr2 = NULL;
                int osize1  = -1;
                int osize2  = -1;
               
                attr_type = OCI_ATTR_LIST_TYPE_ATTRS;
                num_type  = OCI_ATTR_NUM_TYPE_ATTRS;
                ptype     = OCI_DESC_TYPE;

                ostr1 = OCI_GetInputMetaString(pOCILib, typinf->schema, &osize1);
                ostr2 = OCI_GetInputMetaString(pOCILib, typinf->name,   &osize2);

                OCI_CALL2Q
                (
		   pOCILib, res, con, 
                   
		   OCITypeByName(pOCILib->env, con->err, con->cxt,
                                 (text *) ostr1, (ub4) osize1, 
                                 (text *) ostr2, (ub4) osize2, 
                                 (text *) NULL, (ub4) 0, 
                                 OCI_DURATION_SESSION, OCI_TYPEGET_ALL,
                                 &typinf->tdo),

		   xsink
                )

                OCI_CALL2Q
                (
                    pOCILib, res, con, 
                    
                    OCIDescribeAny(con->cxt, con->err, (void *) typinf->tdo,
                                   0, OCI_OTYPE_PTR, OCI_DEFAULT, 
                                   OCI_PTYPE_TYPE, dschp),

		    xsink
                )
                
                OCI_ReleaseMetaString(ostr1);
                OCI_ReleaseMetaString(ostr2);
            }
            else
            {
                mtext buffer[(OCI_SIZE_OBJ_NAME*2) + 2];
                
                size_t size = sizeof(buffer)/sizeof(mtext);
                void *ostr1 = NULL;
                int osize1  = -1;

                attr_type = OCI_ATTR_LIST_COLUMNS;
                num_type  = OCI_ATTR_NUM_COLS;
                ptype     = OCI_DESC_TABLE;
                str       = buffer;

                str[0] = 0;                

                if ((typinf->schema != NULL) && (typinf->schema[0] != 0))
                {
                    str = mtsncat(buffer, typinf->schema, size);
                    size -= mtslen(typinf->schema);
                    str = mtsncat(str, MT("."), size);
                    size -= (size_t) 1;
                }

                mtsncat(str, typinf->name, size);

                ostr1 = OCI_GetInputMetaString(pOCILib, str, &osize1);

                OCI_CALL2Q
                (
                    pOCILib, res, con, 
                    
                    OCIDescribeAny(con->cxt, con->err, (dvoid *) ostr1, 
                                   (ub4) osize1, OCI_OTYPE_NAME, 
                                   OCI_DEFAULT, item_type, dschp),

		    xsink
                )

                OCI_ReleaseMetaString(ostr1);
            }
                  
            OCI_CALL2Q
            (
                pOCILib, res, con, 
                
                OCIAttrGet(dschp, OCI_HTYPE_DESCRIBE, &parmh1, 
                           NULL, OCI_ATTR_PARAM, con->err),

		xsink
            )

            /* do we need get more attributes for collections ? */

            if (type == OCI_TIF_TYPE)
            {
                OCI_CALL2Q
                (
                    pOCILib, res, con, 
                    
                    OCIAttrGet(parmh1, OCI_DTYPE_PARAM, &typinf->tcode, 
                               NULL, OCI_ATTR_TYPECODE, con->err),

		    xsink
                )

            }

            if (typinf->tcode == SQLT_NCO)
            {      
                typinf->nb_cols = 1;
                
                ptype  = OCI_DESC_COLLECTION;
                //etype  = OCI_DESC_TYPE;
                parmh2 = parmh1;

                OCI_CALL2Q
                (
                    pOCILib, res, con, 
                    
                    OCIAttrGet(parmh1, OCI_DTYPE_PARAM, &typinf->ccode, 
                               NULL, OCI_ATTR_COLLECTION_TYPECODE, con->err),

		    xsink
                )
            }
            else
            {