Ejemplo n.º 1
0
void PrepareDbTime()
{
   OCIBind *bndv1 = 0;
   OCIBind *bndv2 = 0;

   static text *stmt_cputime = (text *) "begin :cpu_time_value := dbms_utility.get_cpu_time(); end;" ;
   static text *stmt_elptime = (text *) "begin :elp_time_value := dbms_utility.get_time(); end;" ;

   /* Allocate cpu time handle */ 
   CheckErr(errhp, OCIHandleAlloc(envhp, (dvoid **) &stmt_cputimehp,
                                     OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0));

   /* Allocate elapsed time handle */ 
   CheckErr(errhp, OCIHandleAlloc(envhp, (dvoid **) &stmt_elptimehp,
                                     OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0));

   /* Prepare cpu time statement */
   CheckErr(errhp, OCIStmtPrepare(stmt_cputimehp, errhp, (CONST text *) stmt_cputime,
                                     strlen((char *) stmt_cputime), OCI_NTV_SYNTAX, OCI_DEFAULT));

   /* Prepare elapsed time statement */
   CheckErr(errhp, OCIStmtPrepare(stmt_elptimehp, errhp, (CONST text *) stmt_elptime,
                                     strlen((char *) stmt_elptime), OCI_NTV_SYNTAX, OCI_DEFAULT));

   /* Bind cpu_time_value variable */
   CheckErr(errhp, OCIBindByName(stmt_cputimehp, (OCIBind **) &bndv1, errhp,
                         (text *)":cpu_time_value", (sb4) 15, &cpu_time_value, (sb4) sizeof(ub4), SQLT_INT,
                         (dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT));

   /* Bind elp_time_value variable */
   CheckErr(errhp, OCIBindByName(stmt_elptimehp, (OCIBind **) &bndv2, errhp,
                         (text *)":elp_time_value", (sb4) 15, &elp_time_value, (sb4) sizeof(ub4), SQLT_INT,
                         (dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT));
}
Ejemplo n.º 2
0
/*  Set Bind Values */
int _ltDbSetBindValue_o(ltDbConn *pConn,DB_CURSOR *pCursor,int iSumBind,va_list *ap)
{
    int i,iType,lMaxLen;
    OCIBind* pBind=NULL;
    char caVarName[32];
    static  int ind;
    long *lValue;
    char *pValue;
    double *dValue;
    int status;
    char *pName;
    for(i=0;i<iSumBind;i++) {
        pName = va_arg(*ap,char *);
        iType = va_arg(*ap,int);
        lMaxLen = va_arg(*ap,int);
        switch(iType) {
            case LT_TYPE_STRING:
                pValue = va_arg(*ap,char *);
                sprintf(caVarName,":%s",pName);
                status = OCIBindByName(pCursor->pStmt, &pBind, pCursor->pConn->pErr,
                        (text *) caVarName,strlen(caVarName), (ub1 *) pValue, lMaxLen, SQLT_STR, 
                        (dvoid *)&ind, (ub2 *) 0, (ub2) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
                if(status != OCI_SUCCESS) {
                    return ltDbErrorCode(pConn);
                }
                break;
            case LT_TYPE_SHORT:
            case LT_TYPE_LONG:
                lValue = va_arg(*ap,long *);
                sprintf(caVarName,":%s",pName);
                status = OCIBindByName(pCursor->pStmt, &pBind, pCursor->pConn->pErr,
                        (text *) caVarName,strlen(caVarName), (ub1 *) lValue, sizeof(long), SQLT_INT, 
                        (dvoid *)&ind, (ub2 *) 0, (ub2) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
                if(status != OCI_SUCCESS) {
                    return ltDbErrorCode(pConn);
                }
                break;
            case LT_TYPE_FLOAT:
                dValue = va_arg(*ap,double *);
                sprintf(caVarName,":%s",pName);
                status = OCIBindByName(pCursor->pStmt, &pBind, pCursor->pConn->pErr,
                        (text *) caVarName,strlen(caVarName), (ub1 *) dValue, sizeof(double), SQLT_FLT, 
                        (dvoid *)&ind, (ub2 *) 0, (ub2) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
                if(status != OCI_SUCCESS) {
                    return ltDbErrorCode(pConn);
                }
                break;
            default:
                return -1;
        }
    }
    return 0;
}
Ejemplo n.º 3
0
int FC_FUNC_(oraclesim_getanahead, ORACLESIM_GETANAHEAD)
     (OracleDbConnection **fdbconnid, int *net) {
  OracleDbConnection *dbconnid = *fdbconnid;

  int ostatid;
  float oqs, oqp;
  double olon, olat;
  char oname[NAMELEN], onet[NAMELEN];
  
  /* Preparo l'estrazione anagrafica */
  checkerr(dbconnid, OCIStmtPrepare(dbconnid->stmthp, dbconnid->errhp,
				    (text *) anaquery,
				    (ub4) strlen(anaquery),
				    (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT));


  checkerr(dbconnid, OCIBindByName(dbconnid->stmthp, &dbconnid->bnd1p,
				   dbconnid->errhp, (text *) ":net",
				   -1, (dvoid *) net,
				   (sword) sizeof(*net), SQLT_INT, (dvoid *) NULL,
				   (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0,
				   OCI_DEFAULT));

  /* definisco l'uscita */
  anadefine(dbconnid, &ostatid, &olon, &olat, &oqs, &oqp, oname, onet, NAMELEN);
  return countrows(dbconnid);
}
Ejemplo n.º 4
0
void OWStatement::BindName( const char* pszName, OCILobLocator** pphLocator )
{
    OCIBind* hBind = NULL;

    CheckError( OCIDescriptorAlloc(
        poConnection->hEnv,
        (void**) pphLocator,
        OCI_DTYPE_LOB,
        0,
        0),
        hError );

    CheckError( OCIBindByName(
        (OCIStmt*) hStmt,
        (OCIBind**) &hBind,
        (OCIError*) hError,
        (text*) pszName,
        (sb4) -1,
        (dvoid*) pphLocator,
        (sb4) -1,
        (ub2) SQLT_CLOB,
        (dvoid*) NULL,
        (ub2*) NULL,
        (ub2*) NULL,
        (ub4) 0,
        (ub4*) NULL,
        (ub4) OCI_DEFAULT ),
        hError );
}
Ejemplo n.º 5
0
CPLErr OGROCIStatement::BindObject( const char *pszPlaceName, 
                                    void *pahObjects, OCIType *hTDO,
                                    void **papIndicators )

{
    OCIBind *hBindOrd = NULL;

    if( poSession->Failed( 
            OCIBindByName( hStatement, &hBindOrd, poSession->hError,
                           (text *) pszPlaceName, (sb4) strlen(pszPlaceName), 
                           (dvoid *) 0, (sb4) 0, SQLT_NTY, (dvoid *)0, 
                           (ub2 *)0, (ub2 *)0, (ub4)0, (ub4 *)0, 
                           (ub4)OCI_DEFAULT),
            "OCIBindByName()") )
        return CE_Failure;
    
    if( poSession->Failed(
            OCIBindObject( hBindOrd, poSession->hError, hTDO,
                           (dvoid **) pahObjects, (ub4 *)0, 
                           (dvoid **)papIndicators, (ub4 *)0),
            "OCIBindObject()" ) )
        return CE_Failure;

    return CE_None;
}
Ejemplo n.º 6
0
                           from regions where region_id = :regionID";
void query_salary(OCISvcCtx *svchp, OCIError *errhp, thdata *pthdata)
{
  OCIBind *bndp1;
  OCIDefine *defhp1, *defhp2, *defhp3;
  OCIStmt *stmthp;            
  ub4 region_id;
  char region_name[100];
  ub4 num_rows = 1;
  
  if (verbose_flag)
    printf ("demonstrating single row select\n"); 
  
   checkerr(errhp,
           OCIStmtPrepare2 (svchp, &stmthp,          /* returned stmt handle */
                        errhp,                               /* error handle */
                        (const OraText *) MY_SELECT,   /*input statement text*/
                        strlen((char *) MY_SELECT),        /* length of text */
                        NULL, 0,             /* tagging parameters: optional */
                        OCI_NTV_SYNTAX, OCI_DEFAULT));

  /* bind input parameters */
  checkerr(errhp, OCIBindByName(stmthp, &bndp1, errhp, (text *) ":regionID",
                                -1, (void *) &(pthdata->region_id),
                                sizeof(pthdata->region_id),
                                SQLT_INT, (void *) NULL,
                                (ub2 *) NULL, (ub2 *) NULL, 0, (ub4 *) NULL,
                                OCI_DEFAULT));

  /* execute the statement */
  checkerr(errhp, OCIStmtExecute(svchp, stmthp, errhp, 0, 0,
                                 (OCISnapshot *) NULL, (OCISnapshot *) NULL,
                                 OCI_DEFAULT));
    
  /* Define output buffers */
  checkerr(errhp, OCIDefineByPos (stmthp, &defhp1, errhp, 1, 
                                  (void *) &region_id, (sb4) sizeof(region_id),
                                  SQLT_INT, (void *) NULL, (ub2 *) NULL,
                                  (ub2 *) NULL, OCI_DEFAULT));

  checkerr(errhp, OCIDefineByPos (stmthp, &defhp2, errhp, 2,
                                  (void *)region_name,(sb4)sizeof(region_name),
                                  SQLT_STR, (void *) NULL, (ub2 *) NULL,
                                  (ub2 *) NULL, OCI_DEFAULT));

  /* Fetch one row */
  checkerr(errhp, OCIStmtFetch(stmthp, errhp, num_rows, OCI_FETCH_NEXT,
                        OCI_DEFAULT));
  if (verbose_flag) 
    printf("fetched results: region_id=%d, region_name=%s, \n",
              region_id, region_name);

  /* release the statement handle */
  checkerr(errhp, OCIStmtRelease(stmthp, errhp,
                                 (OraText *) NULL, 0, OCI_DEFAULT)); 
   
}
Ejemplo n.º 7
0
int gettab(OracleDbConnection *dbconnid, int *var, int nvar, int *net) {
  sword status;

  checkerr(dbconnid,
	   OCIStmtPrepare(dbconnid->stmthp, dbconnid->errhp,
			  (text *) tabquery,
			  (ub4) strlen(tabquery),
			  (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT));

  /*  checkerr(dbconnid,
	   OCIBindByName(dbconnid->stmthp, &dbconnid->bnd1p,
			 dbconnid->errhp, (text *) ":var",
			 -1, (dvoid *) var,
			 (sword) sizeof(*var), SQLT_INT, (dvoid *) NULL,
			 (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0,
			 OCI_DEFAULT)); */

  checkerr(dbconnid,
	   OCIBindByName(dbconnid->stmthp, &dbconnid->bnd1p,
			 dbconnid->errhp, (text *) ":net",
			 -1, (dvoid *) net,
			 (sword) sizeof(*net), SQLT_INT, (dvoid *) NULL,
			 (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0,
			 OCI_DEFAULT));

  checkerr(dbconnid,
	   OCIDefineByPos(dbconnid->stmthp, &dbconnid->defn1p,
			  dbconnid->errhp, 1,
			  (dvoid *) dbconnid->table, TABLEN, SQLT_STR,
			  (dvoid *) NULL,
			  (ub2 *) 0, (ub2 *) 0, OCI_DEFAULT));


  /* Lancio l'estrazione */
  if ((status = OCIStmtExecute(dbconnid->svchp, dbconnid->stmthp, dbconnid->errhp,
			       (ub4) 0, (ub4) 0,
			       (CONST OCISnapshot *) NULL, (OCISnapshot *) NULL,
 			       OCI_STMT_SCROLLABLE_READONLY)) != OCI_SUCCESS) {
    if (status != OCI_NO_DATA) {
      checkerr(dbconnid, status);
      return -1;
    }
  }
  /* Prendo la prima riga di dati */
  if ((status = OCIStmtFetch2(dbconnid->stmthp, dbconnid->errhp, (ub4) 1,
			      (ub2) OCI_FETCH_NEXT, (sb4) 0,
			      (ub4) OCI_DEFAULT)) != OCI_SUCCESS) {
    if (status == OCI_NO_DATA) {
      return -1;
    } else {
      checkerr(dbconnid, status);
      return -1;
    }
  }
  return 0;
}
Ejemplo n.º 8
0
int DataBase::_DB_ExecuteSQL()
{
	//绑定变量
	OCIBind *bindHandle[50];    // 最多支持50个参数
	char fieldName[10];

	for(int i = 0; i < tmpParam.size; i++)
	{
		sprintf(fieldName, ":v%d", i+1);
		if( _DB_CheckErr(OCIBindByName(DBSession->selectp,
			&bindHandle[i], DBSession->errhp, (text *) fieldName,
			-1, (dvoid *)(tmpParam.vParam[i]),
			(sword) DB_MAX_FIELD_LEN, SQLT_STR, (dvoid *) 0,
			(ub2 *) 0, (ub2) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT)) < 0 )
		{
			cout<<"[ "<<__FILE__<<" ] [ "<<__LINE__<<" ] errStr = "<<errStr<<endl;
			return DB_FAILURE;
		}
	}

	cout<<"[ "<<__FILE__<<" ] [ "<<__LINE__<<" ] strSql = "<<strSql<<endl;
	//执行SQL
	if( _DB_CheckErr(OCIStmtExecute( DBSession->svchp, DBSession->selectp,
		DBSession->errhp, (ub4) 0, (ub4) 0, (CONST OCISnapshot *)NULL,
		(OCISnapshot *)NULL, OCI_DEFAULT) ) < 0 )
	{
		cout<<"[ "<<__FILE__<<" ] [ "<<__LINE__<<" ] errStr = "<<errStr<<endl;
		return DB_FAILURE;
	}

	//取字段个数
	int colNum = _DB_RecordSetCol();

	//结构数据绑定
	OCIDefine *defnp[100];
	// memset(tmpRec, 0, (sizeof(DB_RECORD) * colNum) + 1);
	tmpRec = new char*[50];
	for(i = 0; i < colNum; i++)
	{
		defnp[i] = (OCIDefine *) 0;
		tmpRec[i] = new char[DB_MAX_FIELD_LEN];
		//  memset(tmpRec[i], 0, sizeof(char)*DB_MAX_FIELD_LEN);
		if( _DB_CheckErr(OCIDefineByPos( DBSession->selectp,
			&defnp[i], DBSession->errhp,  i+1, (dvoid *) tmpRec[i],
			colNum*sizeof(DB_RECORD), SQLT_STR, (dvoid *)0, (ub2 *)0, (ub2 *)0, OCI_DEFAULT) ) < 0 )
		{
			cout<<"[ "<<__FILE__<<" ] [ "<<__LINE__<<" ] errStr = "<<errStr<<endl;
			return DB_FAILURE;
		}
	}
	// delete[] tmpRec;

	return DB_SUCCESS;
}
Ejemplo n.º 9
0
int FC_FUNC_(oraclesim_getnet, ORACLESIM_GETNET)
     (OracleDbConnection **fdbconnid, const char *netdesc) {
  OracleDbConnection *dbconnid = *fdbconnid;
  sword status;
  int onetid;

  /* Preparo l'estrazione per ottenere il numero della rete dal nome */
  checkerr(dbconnid,
	   OCIStmtPrepare(dbconnid->stmthp, dbconnid->errhp,
			  (text *) netquery,
			  (ub4) strlen(netquery),
			  (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT));

  checkerr(dbconnid,
	   OCIBindByName(dbconnid->stmthp, &dbconnid->bnd1p,
			 dbconnid->errhp, (text *) ":netdesc",
			 -1, (dvoid *) netdesc,
			 (sword) strlen(netdesc)+1, SQLT_STR, (dvoid *) NULL,
			 (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0,
			 OCI_DEFAULT));

  checkerr(dbconnid,
	   OCIDefineByPos(dbconnid->stmthp, &dbconnid->defn1p,
			  dbconnid->errhp, 1,
			  (dvoid *) &onetid, sizeof(onetid), SQLT_INT,
			  (dvoid *) 0,
			  (ub2 *) 0, (ub2 *) 0, OCI_DEFAULT));


  /* Lancio l'estrazione */
  if ((status = OCIStmtExecute(dbconnid->svchp, dbconnid->stmthp, dbconnid->errhp,
			       (ub4) 0, (ub4) 0,
			       (CONST OCISnapshot *) NULL, (OCISnapshot *) NULL,
 			       OCI_STMT_SCROLLABLE_READONLY)) != OCI_SUCCESS) {
    if (status != OCI_NO_DATA) {
      checkerr(dbconnid, status);
      return -1;
    }
  }
  /* Prendo la prima riga di dati */
  if ((status = OCIStmtFetch2(dbconnid->stmthp, dbconnid->errhp, (ub4) 1,
			      (ub2) OCI_FETCH_NEXT, (sb4) 0,
			      (ub4) OCI_DEFAULT)) != OCI_SUCCESS) {
    if (status == OCI_NO_DATA) {
      return 0;
    } else {
      checkerr(dbconnid, status);
      return -1;
    }
  }
  return onetid;
}
Ejemplo n.º 10
0
JP_INTERNAL(void) _BindByNameArray(TJQuery &qry, const text* name, int bindNo, void *data, int dataLen, ub2 dataType)
{
  qry.conn.result = OCIBindByName(qry.ociStmt,
                            &qry.ociBinds[bindNo],
                            qry.conn.ociError,
                    TJ_CAST name,
                            -1,
                            data,
                            dataLen,
                            dataType,
                            &qry.indicators[bindNo*qry.noRows],
                            0, 0, 0, 0, OCI_DEFAULT);
}
Ejemplo n.º 11
0
/*
=begin
--- OCIStmt#bindByName(name, type [, length [, mode]])
     define the datatype of the bind variable by name.

     :name
        the name of the bind variable including colon.
     :type
        the type of the bind variable.
        ((|String|)), ((|Fixnum|)), ((|Integer|)), ((|Float|)), ((|Time|)),
        ((<OraDate>)), ((<OraNumber>)), or ((|OCI_TYPECODE_RAW|))
     :length
        When the 2nd argument is 
        * ((|String|)) or ((|OCI_TYPECODE_RAW|)),
          the max length of fetched data.
        * otherwise,
          its value is ignored.
     :mode
        ((|OCI_DEFAULT|)), or ((|OCI_DATA_AT_EXEC|)). But now available value is 
        ((|OCI_DEFAULT|)) only. Default value is ((|OCI_DEFAULT|))
     :return value
        newly created ((<bind handle|OCIBind>))

     for example
       stmt = env.alloc(OCIStmt)
       stmt.prepare("SELECT * FROM EMP
                      WHERE ename = :ENAME
                        AND sal > :SAL
                        AND hiredate >= :HIREDATE")
       b_ename = stmt.bindByName(":ENAME", String, 10)
       b_sal = stmt.bindByName(":SAL", Fixnum)
       b_hiredate = stmt.bindByName(":HIREDATE", OraDate)

     correspond native OCI function: ((|OCIBindByName|))
=end
 */
static VALUE oci8_bind_by_name(int argc, VALUE *argv, VALUE self)
{
  VALUE vplaceholder;
  VALUE vtype;
  VALUE vlength;
  VALUE vmode;
  oci8_handle_t *h;
  oci8_string_t placeholder;
  oci8_bind_handle_t *bh;
  ub2 dty;
  ub4 mode;
  dvoid *indp;
  ub2 *rlenp;
  dvoid *valuep;
  OCIBind *bindhp = NULL;
  sword status;
  VALUE hash;
  VALUE obj;

  rb_scan_args(argc, argv, "22", &vplaceholder, &vtype, &vlength, &vmode);
  Get_Handle(self, h); /* 0 */
  Get_String(vplaceholder, placeholder); /* 1 */
  check_bind_type(OCI_HTYPE_BIND, h, vtype, vlength, &bh, &dty); /* 2, 3 */
  Get_Int_With_Default(argc, 4, vmode, mode, OCI_DEFAULT); /* 4 */

  if (mode & OCI_DATA_AT_EXEC) {
    indp = NULL;
    rlenp = NULL;
  } else {
    indp = &(bh->ind);
    rlenp = (bh->bind_type == BIND_STRING) ? NULL : &bh->rlen;
  }
  valuep = &bh->value;
  status = OCIBindByName(h->hp, &bindhp, h->errhp, placeholder.ptr, placeholder.len, valuep, bh->value_sz, dty, indp, rlenp, 0, 0, 0, mode);
  if (status != OCI_SUCCESS) {
    oci8_unlink((oci8_handle_t *)bh);
    bh->type = 0;
    oci8_raise(h->errhp, status, h->hp);
  }
  bh->type = OCI_HTYPE_BIND;
  bh->hp = bindhp;
  bh->errhp = h->errhp;
  obj = bh->self;
  hash = rb_ivar_get(self, oci8_id_bind_hash);
  if (hash == Qnil) {
    hash = rb_hash_new();
    rb_ivar_set(self, oci8_id_bind_hash, hash);
  }
  rb_hash_aset(hash, vplaceholder, obj);
  return obj;
}
Ejemplo n.º 12
0
JP_INTERNAL(void) _BindByName(TJQuery &qry, const text* name, int bindNo, void *data, int dataLen, ub2 dataType, sb2 isNull)
{
  qry.indicators[bindNo] = isNull == JP_NOT_NULL ? JP_NOT_NULL : JP_NULL;
  qry.conn.result = OCIBindByName(qry.ociStmt,
                            &qry.ociBinds[bindNo],
                            qry.conn.ociError,
                    TJ_CAST name,
                            -1,
                            data,
                            dataLen,
                            dataType,
                            &qry.indicators[bindNo],
                            0, 0, 0, 0, OCI_DEFAULT);
}
Ejemplo n.º 13
0
/*
  Bind variables from the global array.
*/
int
bindTheVariables( OCIStmt *p_statement, const char *sql ) {
    int myBindVarCount;
    int stat;
    int i;

    for ( i = 0; i < MAX_BIND_VARS; i++ ) {
        p_bind[i] = NULL;
    }
    if ( bindName[0] == '\0' ) {
        /* I believe we need a static array of these bind names so
           initialize them if they haven't been already.
        */
        for ( i = 0; i < MAX_BIND_VARS; i++ ) {
            snprintf( &bindName[i * 5], 5, ":%d", i + 1 );
        }
    }

    myBindVarCount = cllBindVarCount;
    cllBindVarCountPrev = cllBindVarCount; /* save in case we need to log error */
    cllBindVarCount = 0; /* reset for next call */

    if ( myBindVarCount > 0 ) {
        if ( myBindVarCount > MAX_BIND_VARS ) {
            return CAT_INVALID_ARGUMENT;
        }
        for ( i = 0; i < myBindVarCount; i++ ) {
            int len, len2;
            len = strlen( ( char* )&bindName[i * 5] );
            len2 = strlen( cllBindVars[i] ) + 1;
            stat =  OCIBindByName( p_statement, &p_bind[i], p_err,
                                   ( OraText * )&bindName[i * 5],
                                   len,
                                   ( dvoid * )cllBindVars[i],
                                   len2,
                                   SQLT_STR,
                                   0, 0, 0, 0, 0,
                                   OCI_DEFAULT );

            if ( stat != OCI_SUCCESS ) {
                rodsLog( LOG_ERROR, "cllExecNoResult: OCIBindByName failed: %d",
                         stat );
                rodsLog( LOG_ERROR, "sql:%s", sql );
                logOraError( LOG_ERROR, p_err, stat );
                return CAT_OCI_ERROR;
            }
        }
    }
    return 0;
}
Ejemplo n.º 14
0
CPLErr OGROCIStatement::BindScalar( const char *pszPlaceName, 
                                    void *pData, int nDataLen,
                                    int nSQLType, sb2 *paeInd )

{
    OCIBind *hBindOrd = NULL;

    if( poSession->Failed( 
            OCIBindByName( hStatement, &hBindOrd, poSession->hError,
                           (text *) pszPlaceName, (sb4) strlen(pszPlaceName), 
                           (dvoid *) pData, (sb4) nDataLen, 
                           (ub2) nSQLType, (dvoid *)paeInd, (ub2 *)0, 
                           (ub2 *)0, (ub4)0, (ub4 *)0, 
                           (ub4)OCI_DEFAULT),
            "OCIBindByName()") )
        return CE_Failure;
    else
        return CE_None;
}
Ejemplo n.º 15
0
                    myemp where empno > :EMPNO order by empno";

void multirow_fetch(OCISvcCtx *svchp, OCIError *errhp, thdata *pthdata)
{
  OCIStmt *stmthp;
  OCIBind *bndp;

  if (verbose_flag)
    printf ("demonstrating array fetching\n");

  /* get a prepared statement handle */
  checkerr(errhp, OCIStmtPrepare2 (svchp, &stmthp, errhp,
				    (const OraText *) MY_SELECT2,
                                   strlen((char *) MY_SELECT2),
                                   (OraText*) NULL, 0,
                                   OCI_NTV_SYNTAX, OCI_DEFAULT));

  /* bind input parameters */
  checkerr(errhp, OCIBindByName(stmthp, &bndp, errhp, (text *) ":EMPNO",
                                -1, (void *) &(pthdata->multirow_fetch_id),
                                sizeof(int), SQLT_INT, (void *) NULL,
                                (ub2 *) NULL, (ub2 *) NULL, 0, (ub4 *) NULL,
                                OCI_DEFAULT));

  /* Execute the query */
  checkerr(errhp, OCIStmtExecute (svchp, stmthp, errhp, 0, 0,
                                  (OCISnapshot *) NULL, (OCISnapshot *) NULL,
                                  OCI_DEFAULT));             
  

  /* separating fetching rows into this method to help understand stage6 ref cursors */
  multirow_fetch_from_emp(svchp, stmthp, errhp, pthdata);

  if (verbose_flag)
    printf ("array fetch successful\n");

  /* release the statement handle */
  checkerr(errhp, OCIStmtRelease(stmthp, errhp,
                                 (OraText *) NULL, 0, OCI_DEFAULT));  

}
Ejemplo n.º 16
0
void OWStatement::BindName( const char* pszName, char* pszData, int nSize )
{
    OCIBind* hBind = NULL;

    CheckError( OCIBindByName(
        (OCIStmt*) hStmt,
        (OCIBind**) &hBind,
        (OCIError*) hError,
        (text*) pszName,
        (sb4) -1,
        (dvoid*) pszData,
        (sb4) nSize,
        (ub2) SQLT_STR,
        (dvoid*) NULL,
        (ub2*) NULL,
        (ub2*) NULL,
        (ub4) 0,
        (ub4*) NULL,
        (ub4) OCI_DEFAULT ),
        hError );
}
Ejemplo n.º 17
0
void OWStatement::BindName( const char* pszName, double* pnData )
{
    OCIBind* hBind = NULL;

    CheckError( OCIBindByName(
        (OCIStmt*) hStmt,
        (OCIBind**) &hBind,
        (OCIError*) hError,
        (text*) pszName,
        (sb4) -1,
        (dvoid*) pnData,
        (sb4) sizeof(double),
        (ub2) SQLT_BDOUBLE,
        (dvoid*) NULL,
        (ub2*) NULL,
        (ub2*) NULL,
        (ub4) 0,
        (ub4*) NULL,
        (ub4) OCI_DEFAULT ),
        hError );
}
Ejemplo n.º 18
0
std::string OraSession::getPasswordForUser(const std::string& user) {
	char password[4096];
	OCIBind *bnd1p = 0;

	std::string stmt = "begin select password into :password from sys.dba_users where username = upper('" + user + "'); end;";

	checkerr(&ociHandles, OCIStmtPrepare(ociHandles.stmthp, ociHandles.errhp, (text*)stmt.c_str(),
		(ub4)strlen(stmt.c_str()), (ub4)OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT));

	password[0] = 0;

	checkerr(&ociHandles, OCIBindByName(ociHandles.stmthp, (OCIBind **)&bnd1p, ociHandles.errhp,
		(text *)":password", (sb4)strlen(":password"),
		(dvoid *)password, (sb4)4096,  SQLT_STR, (dvoid *)0,
		(ub2 *)0, (ub2 *)0, (ub4)0, (ub4 *)0,(ub4)OCI_DEFAULT));            

	checkerr(&ociHandles, OCIStmtExecute(ociHandles.svchp, ociHandles.stmthp, ociHandles.errhp, (ub4)1, (ub4)0, (OCISnapshot *)NULL,
		(OCISnapshot *)NULL, (ub4)OCI_DEFAULT));


	return password;
	
}
Ejemplo n.º 19
0
int main(int argc, char *argv[])
{

  ub1 *LobReadBuf=NULL;
  ub4 *KeysValueBuf=NULL;
  OCIStmt *stmtsellochp = 0;
  OCIBind *bndv1 = 0;
  OCIDefine *defv1 = 0;
  OCILobLocator *lobloc=0;
  static text *stmt_sellocstr = (text *)"SELECT DOCUMENT FROM FOO WHERE PKEY = :MYPKEY";

  int i, j, q;                  /* loop variables */
  sword orc;                    /* Return value */
  ub4 LobSize = 0;              /* Size of Lob to be selected */
  ub4 Iter=1;                   /* How many times to repeat before exiting */
  ub4 NumRows=0;                /* Num of Rows to select in each iteration */
  ub4 trace_flag=0;             /* 0 is default, means no sql_trace */
  int UserNum=1;                /* used in multiuser tests */

  ub4 KeyStartValue=0;          /* primary key generator, derived from USERKEYRANGE * UserNum */
  ub4 KeyMaxValue=0;            /* derived from StartValue + NumRows*Iter */
  sb8 KeyValue=0;               /* random number between StartValue and MaxValue */
  int LobType;                  /* to check Lobtype = BASICFILE or SECUREFILE */
  int ReqTime;                  /* argument to GetDbTime function ReqTime=1 elasped, ReqTime=0 cpu time */

  ub4 StartTimeTot;
  ub4 StartTime;
  ub4 StartCpu;

  ub4 EndTimeTot;
  ub4 EndTime;
  ub4 EndCpu;

  ub4 ElapsedTimeTot;
  ub4 ElapsedTime;
  ub4 ElapsedCpu;

  ub4 AvgElapsed;
  ub4 AvgCpu;
  float AvgRate;



  if (argc <= 5) {
    printf("Usage: %s <uid> <pwd> <LobSize(bytes)> <NumRows> <Iteration> <UserNum> trace_flag(1|0>\n\r", argv[0]);
    exit(-1);
  }

  /* process command line args */
  LobSize=atoi(argv[3]);
  NumRows=atoi(argv[4]);
  Iter=atoi(argv[5]);

  if (argc > 6 )
    UserNum=atoi(argv[6]);                  /* Used in multiuser run, to make unique pkeys */

  if (argc > 7 )
    trace_flag=atoi(argv[7]);

  /* Allocate OCI handles */
  if (AllocateHandles(0)) {
    printf("AllocateHandles failed \n");
    exit(-1);
  }

  /* Login using argv[1] and argv[2] */
  if ( (ConnectToDb(argv[1], argv[2])) != OCI_SUCCESS ) { 
    printf("ConnectToDb failed \n");
    CheckErr(errhp, orc);
    exit(-1);
  }

  srand48(LobSize);

  printf("Using LobSize=%d bytes, NumRows=%d, calculated total memorysize=%d bytes\r\n", LobSize, NumRows, LobSize*NumRows);

  if((LobSize==0)||(NumRows<1))
  {
   printf("Parameter error\r\n");
   exit(-1);
  }

  /* Memory allocation section */
  if ( (LobReadBuf=(ub1 *)malloc(LobSize)) == NULL ) {
    printf("Error allocating memory for LobReadBuf\r\n");
    exit(-1);
  }

  /* Initialize allocated memory and setup Read buffer as 0000000 */
  memset(LobReadBuf,0,LobSize);                 /* setup Lob read buffer as 0 */

  KeyStartValue=UserNum*USERKEYRANGE;           /* Value is set as per UserNum */
  KeyMaxValue = KeyStartValue + (NumRows*Iter);


  /* SQL_TRACE section */
  if (trace_flag == 1) { 
    printf("Begin tracing...\n");
    TurnOnSqlTrace();
  }  
 
  printf("Trying to Select %d Rows with Lob size of %d Bytes)\r\n", NumRows, LobSize);
  printf("Selecting data.....please wait\r\n");

  /* allocate a statement handle for SELECT OF LOB LOCATOR  and prepare it */
  CheckErr(errhp, OCIHandleAlloc(envhp, (dvoid **) &stmtsellochp, OCI_HTYPE_STMT,
                                     (size_t) 0, (dvoid **) 0));
 
  CheckErr(errhp, OCIStmtPrepare(stmtsellochp, errhp, (CONST text *) stmt_sellocstr,
                                     strlen((char *) stmt_sellocstr), OCI_NTV_SYNTAX, OCI_DEFAULT));
 
  /* Allocate Lob Locator descriptor */ 
  CheckErr(errhp, OCIDescriptorAlloc(envhp, (dvoid **)&lobloc, (ub4) OCI_DTYPE_LOB, (size_t) 0, (dvoid **) 0)) ;
  
  CheckErr(errhp, OCIBindByName(stmtsellochp, (OCIBind **) &bndv1, errhp,
                  (text *)":MYPKEY", (sb4) 7, &KeyValue, (sb4) sizeof(ub4), SQLT_INT,
                  (dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT));

  CheckErr(errhp, OCIDefineByPos (stmtsellochp, (OCIDefine **) &defv1, errhp,
                  1, &lobloc, 0 , SQLT_BLOB,
                  (dvoid *)0, (ub2 *)0, (ub2 *)0, OCI_DEFAULT));

  /* Allocate and Prepare statement to get cpu and elapsed time using dbms_utility */
  PrepareDbTime();

  for (q = 0 ; q < Iter ; q ++ ) { 
     
     StartTime = GetDbTime(1);

     if ( q == 1)  {                       /* Discard q=0 as warm up */
       StartTimeTot = StartTime;
       StartCpu = GetDbTime(0);
     }

     for (i=0; i < NumRows; i++) {

         KeyValue=(lrand48 () % (KeyMaxValue-KeyStartValue)) + KeyStartValue ;

         CheckErr(errhp, OCIStmtExecute(svchp, stmtsellochp, errhp, (ub4) 1, (ub4) 0,
                         (CONST OCISnapshot *) 0, (OCISnapshot *) 0, OCI_DEFAULT));

         /*
         CheckErr(errhp, OCILobGetLength(svchp, errhp, lobloc, &LobReadLen));
         printf ("Length of the lob to read %d \n", LobReadLen);
         */

         /* Got the Locator, now start Reading data using it */
         CheckErr(errhp, OCILobRead(svchp, errhp, lobloc, &LobSize, 
                         1, &LobReadBuf[0], (ub4) LobSize, 
                         (dvoid *)0, NULL, (ub2) 0, (ub1) SQLCS_IMPLICIT));

     }

     EndTime = GetDbTime(1);

     ElapsedTime = (EndTime - StartTime)*10 ;

     printf("Elapsed time for Iter %d Select (%d rows) in msecs: %ld\n", q+1, NumRows, ElapsedTime);

  }    /* end of Iteration 'for' loop */

  EndTimeTot = EndTime;
  ElapsedTimeTot = (EndTimeTot-StartTimeTot)*10;
  
  EndCpu = GetDbTime(0);
  /* cpu time is centisecond, x10 to report in msec, not accurate, doing it for consistency */
  ElapsedCpu = (EndCpu - StartCpu) * 10;

  printf ("--------------------------------------------------------------------------- \n");
  printf("Total Elapsed time for select (%d rows) in msecs (excluding Iter 1) : %ld\n", (NumRows*(Iter-1)), ElapsedTimeTot);

  if (Iter > 1) {
    AvgElapsed=ElapsedTimeTot/(Iter-1);
    AvgCpu=ElapsedCpu/(Iter-1);
    printf("Avg Elapsed time for a Iteration (%d rows) in msecs (excluding Iter 1) : %ld\n", NumRows, AvgElapsed );
    printf("Avg CPU time for a Iteration  (%d rows) in msecs (excluding Iter 1) : %ld\n", NumRows, AvgCpu );

    /* x1000 to report in seconds from mseconds */
    AvgRate=((float)LobSize*(float)NumRows*1000)/((float)AvgElapsed*1024*1024);
    printf("Avg Read Rate for (%d rows) (excluding Iter 1) : %0.2f (Mb/sec)\n", NumRows,  AvgRate);
  }

  LobType=CheckLobType();

  if (LobType == 1)
    printf ("SECUREFILE Lob Read Test Finished (Using OCILobRead API)\n");
  else
    printf ("BASICFILE Lob Read Test Finished (Using OCILobRead API)\n");
 
  printf("Selected LobSize=%d bytes, NumRows=%d, Iter=%d \r\n", LobSize, NumRows, Iter );
  printf ("--------------------------------------------------------------------------- \n");
 
  return(0);
  
}  /* end of Main */
Ejemplo n.º 20
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);
}
Ejemplo n.º 21
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);
}
Ejemplo n.º 22
0
/*
 * Add a new status change to the database
 * Params:
 *  session	- user session name
 *  uid		- uid of person changing status
 *  status	- type of new status (away|back|...)
 *  descr	- new description
 *  change_time - time of status change (no. of seconds since 1st Jan 1970)
 *  quiet	- print error messages or not
 * Returns 0 on success.
 */
int oralog_db_new_status(char *session, char *uid, char *status, char *descr, time_t change_time, int quiet)
{
	OCIStmt	  *hp_stmt = NULL;     /* SQL statement handle */
	OCIBind	  *bind[5] = { NULL }; /* Needed for C-var to SQL-var binding */	
	sword	  retstat  = 0;        /* Return value of function */
	int	  errors   = 0;        /* Error counter */
	uword	  invalid  = 0;        /* for DateCheck() */
	OCIDate   oci_date;	       /* for 'change_time' - oracle internal representation */
	struct tm *tm_chtime = NULL;   /* for 'change_time' - standard C representation */
	
	int	  print_errors = (quiet) ? 0 : 1; /* if nonzero then print errors into status window */
	OCIError  *hp_error   = NULL;		  /* oci error handle */
	
	/* SQL statement to execute */
	text	*sqlstmt = (text *) "INSERT INTO status_changes VALUES( status_changes_seq.nextval, :session_uid, :changes_uid, :status, :descr, :change_time)";


	pthread_mutex_lock(&oralog_oper_lock);

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


	check_string_len(session);
	check_string_len(uid);
	check_string_len(status);
	check_string_len(descr);


	/* Create local handles (OCIBind's are created automaticly) */
	OCIHandleAlloc( (dvoid *)hp_env, (dvoid **)&hp_stmt, OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0);
	OCIHandleAlloc( (dvoid *)hp_env, (dvoid **)&hp_error, OCI_HTYPE_ERROR, 0, (dvoid **) 0);

	/* Create DATE */
	tm_chtime = localtime(&change_time);
	
	memset(&oci_date, 0, sizeof(OCIDate));
	OCIDateSetTime( &oci_date, (ub1)tm_chtime->tm_hour, (ub1)tm_chtime->tm_min, (ub1)tm_chtime->tm_sec ); 
	OCIDateSetDate( &oci_date, (sb2)tm_chtime->tm_year+1900, (ub1)tm_chtime->tm_mon+1, (ub1)tm_chtime->tm_mday );


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

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


	/* bind variables */
	debug("[logsoracle] binding..\n");

	retstat = OCIBindByName(hp_stmt, &bind[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, &bind[1], hp_error, (text *) ":changes_uid",
				-1, (dvoid *) uid,
				ora_strlen(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, &bind[2], hp_error, (text *) ":status",
				-1, (dvoid *) status,
				ora_strlen(status)+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, &bind[3], hp_error, (text *) ":descr",
				-1, (dvoid *) descr,
				ora_strlen(descr)+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++;


	/* Oracle type DATE can be easily bind by using OCIDate struct and SQLT_ODT datatype */					   
	retstat = OCIBindByName(hp_stmt, &bind[4], hp_error, (text *) ":change_time",
				-1, (dvoid *) &oci_date,
				(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++;
						


	/* Statement ready - execute */
	debug("[logsoracle] executing\n");
	retstat = OCIStmtExecute(hp_service, hp_stmt, 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)
	    OCIHandleFree(hp_stmt, OCI_HTYPE_STMT);	
	if(hp_error)
	    OCIHandleFree(hp_error, OCI_HTYPE_ERROR);
	
	pthread_mutex_unlock(&oralog_oper_lock);
	return 0;
}
Ejemplo n.º 23
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;
}
Ejemplo n.º 24
0
GSQLCursorState 
oracle_cursor_open_bind_by_name (GSQLCursor *cursor, GList *args)
{
	GSQL_TRACE_FUNC;

	GSQLEOracleCursor	*spec_cursor;
	GSQLEOracleSession	*spec_session;
	GSQLEOracleVariable *spec_var;
	GSQLVariable		*var;
	GList *vlist = args;
	GList *vlist_value;
	GType vtype;
	guint  n, var_count=0;
	sword ret;
	OCIParam *param;
	static OCIBind *bindhp = 0;
	unsigned char op[2000];
	gint i;
	gchar *holder;
	gchar buffer[GSQL_MESSAGE_LEN];
    
	g_return_val_if_fail (GSQL_IS_CURSOR (cursor), GSQL_CURSOR_STATE_ERROR);
	
	spec_session = (GSQLEOracleSession *) cursor->session->spec;
	spec_cursor = g_malloc0 (sizeof (GSQLEOracleCursor));	
	cursor->spec = spec_cursor;
	
	ret = OCIHandleAlloc ((dvoid *)(spec_session->envhp), 
					   (dvoid **)&(spec_cursor->errhp),
						OCI_HTYPE_ERROR, 0, (dvoid **) 0);
	
	if (ret == OCI_ERROR)
	{

		GSQL_DEBUG("oracle_cursor_open: OCIHandleAlloc (allocate an error handle)... failed");
		cursor->spec = NULL;
		g_free (spec_cursor);
		return GSQL_CURSOR_STATE_ERROR;
	}

	if (!oracle_sql_prepare (cursor, cursor->sql))
	{
		
		OCIHandleFree ((dvoid *)spec_cursor->errhp, OCI_HTYPE_ERROR);
		cursor->spec = NULL;
		g_free (spec_cursor);
		return GSQL_CURSOR_STATE_ERROR;
	}
	
	n = 0;
	
	while (vlist)
	{
		vtype = (GType) vlist->data;
		
		/* bind by name means first item are name of bind point - it is always are string (gchar *) */
		if (vtype != G_TYPE_STRING)
		{
			GSQL_DEBUG ("Wrong GSQL_CURSOR_BIND_BY_NAME usage");
			return GSQL_CURSOR_STATE_ERROR;
		}
		
		vlist = g_list_next (vlist);
		holder = g_strdup ( (gchar *) vlist->data);
		
		vlist = g_list_next (vlist);
		vtype = (GType) vlist->data;
		vlist = g_list_next (vlist);
		
		switch (vtype)
		{
			case G_TYPE_STRING:
			case G_TYPE_POINTER:
			
				ret = OCIBindByName (spec_cursor->statement, &bindhp, spec_cursor->errhp,
							(CONST text *) holder,-1,
							(dvoid *) vlist->data, (sb4)strlen(vlist->data)+1, (ub2) SQLT_STR,
							(dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0,
							(ub4) OCI_DEFAULT);
				GSQL_DEBUG ("Bind by name: [\'%s\' = %s] [ret = %d]", holder, vlist->data, ret);
				if (oracle_check_error (cursor, ret))
				{
					GSQL_DEBUG ("bind error");
				}
				
				break;
			
			case G_TYPE_INT:
			case G_TYPE_UINT:
				GSQL_FIXME;
				
				break;
			
			case G_TYPE_UINT64:
			case G_TYPE_INT64:
				GSQL_FIXME;
			
				break;
			
			case G_TYPE_DOUBLE:
				GSQL_FIXME;
				
				break;
				
		}
		
		g_free (holder);
		
		vlist = g_list_next (vlist);
		n++;
	}

	
	if (!oracle_sql_exec (cursor))
	{
		
		OCIHandleFree ((dvoid *)spec_cursor->errhp, OCI_HTYPE_ERROR);
		cursor->spec = NULL;
		g_free (spec_cursor);
		
		return GSQL_CURSOR_STATE_ERROR;
	}
	
	ret = OCIAttrGet (spec_cursor->statement, OCI_HTYPE_STMT, (dvoid*) &(var_count), 0,
						OCI_ATTR_PARAM_COUNT, spec_cursor->errhp);
	
	if (oracle_check_error (cursor, ret))
	{
		
		OCIHandleFree ((dvoid *)spec_cursor->errhp, OCI_HTYPE_ERROR);
		cursor->spec = NULL;
		g_free (spec_cursor);
		return GSQL_CURSOR_STATE_ERROR;
	}
			
	for (i = 0; i < var_count; i++)
	{

		ret = OCIParamGet (spec_cursor->statement, OCI_HTYPE_STMT,
						spec_cursor->errhp, (void**) &param, i+1);
                
 		if (oracle_check_error (cursor, ret))
		{
			 g_free (spec_cursor);
			 return GSQL_CURSOR_STATE_ERROR;
		};

		var = gsql_variable_new ();
		oracle_variable_init (cursor, var, param, i+1);
		cursor->var_list = g_list_append (cursor->var_list, var);
		OCIDescriptorFree (param, OCI_DTYPE_PARAM);

	}
		
	return GSQL_CURSOR_STATE_OPEN;

}
Ejemplo n.º 25
0
int FC_FUNC_(oraclesim_getdatahead, ORACLESIM_GETDATAHEAD)
     (OracleDbConnection **fdbconnid, char *ti, char *tf,
      int *net, int *var, int *nvar) {
  OracleDbConnection *dbconnid = *fdbconnid;
  int i;
  char *query;

  /* valori validi =1, mancanti =-1,  inutilizzati per ora, ci pensa la query */
  /*   sb2 otab_ind, ovalp_ind, ovala_ind, oflag_ind; */
  char odate[DATELEN], ovalc[CVALLEN], oflag[FLAGLEN];
  int ostatid, ovarid;
  float ovalp, ovala;

  /* Eseguo l'estrazione per ottenere il nome della tabella,
     complicazione per colpa di CAELAMI */
  if ((i = gettab(dbconnid, var, *nvar, net)) != 0) return i;

  /* Ricostruisco la richiesta dati con il nome della tabella ottenuto */
  query = alloca(strlen(query1)+strlen(dbconnid->table)+strlen(query2)+
		 10*(*nvar+1)+strlen(query3)+1);
  strcpy(query, query1);
  strcat(query, dbconnid->table);
  strcat(query, query2);
  if (*nvar > 1) {
    strcat(query, " IN (");
    for (i=0; i < (*nvar); i++) {
      snprintf(query+strlen(query), 10, "%d", var[i]);
      if (i < (*nvar)-1) strcat(query, ",");
    }
    strcat(query, ")");
  } else {
    strcat(query, " = ");
    snprintf(query+strlen(query), 10, "%d", *var);
  }
  strcat(query, query3);

  /* Preparo l'estrazione dati */
  checkerr(dbconnid, OCIStmtPrepare(dbconnid->stmthp, dbconnid->errhp,
				    (text *) query,
				    (ub4) strlen(query),
				    (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT));


  checkerr(dbconnid, OCIBindByName(dbconnid->stmthp, &dbconnid->bnd1p,
				   dbconnid->errhp, (text *) ":ti",
				   -1, (dvoid *) ti,
				   DATELEN, SQLT_STR, (dvoid *) NULL,
				   (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0,
				   OCI_DEFAULT));

  checkerr(dbconnid, OCIBindByName(dbconnid->stmthp, &dbconnid->bnd2p,
				   dbconnid->errhp, (text *) ":tf",
				   -1, (dvoid *) tf,
				   DATELEN, SQLT_STR, (dvoid *) NULL,
				   (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0,
				   OCI_DEFAULT));

  checkerr(dbconnid, OCIBindByName(dbconnid->stmthp, &dbconnid->bnd3p,
				   dbconnid->errhp, (text *) ":net",
				   -1, (dvoid *) net,
				   (sword) sizeof(*net), SQLT_INT, (dvoid *) NULL,
				   (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0,
				   OCI_DEFAULT));

  /* definisco l'uscita */
  datadefine(dbconnid, odate, DATELEN, &ostatid, &ovarid, &ovalp, &ovala, ovalc, oflag, CVALLEN, FLAGLEN);
  return countrows(dbconnid);
}
Ejemplo n.º 26
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.º 27
0
// Вызывается перед первым эхеком...
int ora_check_bind(database *db) {
  int typ,len,i;
  db_col *c; void *val;
  t_ora *o = db->h;
  if(db->in.count==0) return 1; // Нету переменных, OK.
  for(i=0,c=db->in.cols; i<db->in.count; i++,c++)   {
    val=(void*)c->value; c->dbvalue = c->value; // by default -)))
    switch (c->type)
    {
      case dbInt:     typ=INT_TYPE;    len=sizeof(int); break;
      case dbDouble:  typ=SQLT_FLT;  len=sizeof(double); break;
      case dbChar:    typ=STRING_TYPE; len=c->len+1; break;
      case dbDate:    typ=DATE_TYPE; // Придется декодировать...
                      len=7; val=c->dbvalue; //c->value=(void*)c->dbtype;
                      break;
      case dbBlob:    val = c->name[0]!=':'?&o->blob_read:&o->blob;
                      if (1) { int code; ub4 lobEmpty = 0;
//                             if (o->blob) { OCIDescriptorFree(o->blob, (ub4) OCI_DTYPE_LOB); o->blob=0;}
                             if (o->blob) { OCIDescriptorFree(o->blob, (ub4) OCI_DTYPE_LOB); o->blob=0;}
                      OCIDescriptorAlloc((dvoid *) o->envhp, (dvoid **) &o->blob,
                           (ub4) OCI_DTYPE_LOB, (size_t) 0, (dvoid **) 0);
                      OCILobCreateTemporary(o->svchp,o->errhp,o->blob,
                        OCI_DEFAULT,OCI_DEFAULT,OCI_TEMP_BLOB,FALSE,OCI_DURATION_SESSION);
                            //if( code=OCILobCreateTemporary(o->svchp, o->errhp, o->blob,
                           //(ub2)0, SQLCS_IMPLICIT,
                           //OCI_TEMP_BLOB, OCI_ATTR_NOCACHE,
                           //OCI_DURATION_SESSION) )
  //{
    // (void) printf("FAILED: CreateTemporary() code=%d \n",code);
    // return 0;
  //}
                           //   code=OCIDescriptorAlloc((dvoid *) o->envhp, (dvoid **) &o->blob,
                                    //     (ub4) OCI_DTYPE_LOB, (size_t) 0, (dvoid **) 0);
                            //  printf("Created with code=%d\n",code);
                             // code=OCIAttrSet((dvoid *) o->blob, (ub4) OCI_DTYPE_LOB,
                              //    &lobEmpty, sizeof(lobEmpty),
                               //  (ub4) OCI_ATTR_LOBEMPTY, o->errhp);
                              //if (o->blob)
                              len = 0; typ = SQLT_BLOB;
                              //printf("init oblob=%d code=%d\n",o->blob,code);
                              code = OCILobTrim(o->svchp, o->errhp, o->blob,0);
  //printf("LobTrimmed %d  code=%d!\n",o->blob,code);

                      }
                       len = 0; typ = SQLT_BLOB;
                      break;
      default:        sprintf(db->error,"VORA-bind: unknown type %d pos=%d",c->type,i);
                      return 0;
    }
  //rintf("Start bind var %s\n",c->name);
  if (!ora_ok(db->err_code = OCIBindByName(o->stmt,&o->defs[db->out.count+i],
         o->errhp, (text *) c->name, -1,
              val, len, typ,  (short*)&c->null,
             (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT)))
  {
	  ora_error(db);
	  strcat(db->error," on bind ");
	  strcat(db->error,c->name);
	  return 0;
   }
  //rintf("End bind %s\n",c->name);
  }
  return 1;
}