Пример #1
0
// Заполняет текст последней ошибки в db->error
int ora_error(database *db)
{
t_ora *o = db->h;
int len, i , ecode;
unsigned char *err;
debugf("ORA_ERROR on database... try extract text");
//return 0;
//printf("ORA ERROR!!"); getch();
if (!o)  sprintf(db->error,"vora - no oracle connection");
 else OCIErrorGet((dvoid *)o->errhp, (ub4) 1, (text *) NULL, &db->err_code,
         db->error, (ub4) sizeof(db->error), OCI_HTYPE_ERROR );
//printf("ORA ERROR CODE=%d!!",db->err_code); getch();
if (db->err_code == 3113 || db->err_code == 12560 || db->err_code==12571 || db->err_code==3114) { // Clear connection flags
  db->connected = 0;
  }
err = db->error; len = strlen(err); err+=len;
//printf("Ora error length=%d\n",len);
for ( i=2; i<5 ; i++) { // Не работает - ничего кроме первого не вытаскивается !!!
	     int l;
	     OCIErrorGet((dvoid *)o->errhp, (ub4) i, (text *) NULL, &db->err_code,
	     err, (ub4) (sizeof(db->error) - len-1), OCI_HTYPE_ERROR );
             l = strlen(err);
	     //printf("Ora error length=%d\n",l);
	     len+= l; err+=l;
             }
*err=0; // Terminate it !!!
//printf("ORA ERROR TEXT=%s!!",db->error); getch();
return 0;
}
Пример #2
0
static void statement_fetch_metadata(lua_State *L, statement_t *statement) {
    bindparams_t *bind;
    int i;

    char errbuf[100];
    int errcode;
    int rc;

    if (statement->metadata)
	return;

    statement->bind = (bindparams_t *)malloc(sizeof(bindparams_t) * statement->num_columns);
    memset(statement->bind, 0, sizeof(bindparams_t) * statement->num_columns);
    bind = statement->bind;

    for (i = 0; i < statement->num_columns; i++) {
	rc = OCIParamGet(statement->stmt, OCI_HTYPE_STMT, statement->conn->err, (dvoid **)&bind[i].param, i+1);
	if (rc) {
	    OCIErrorGet((dvoid *)statement->conn->err, (ub4) 1, (text *) NULL, &errcode, errbuf, (ub4) sizeof(errbuf), OCI_HTYPE_ERROR);
	    luaL_error(L, "param get %s", errbuf);
	}

	rc = OCIAttrGet(bind[i].param, OCI_DTYPE_PARAM, (dvoid *)&(bind[i].name), (ub4 *)&(bind[i].name_len), OCI_ATTR_NAME, statement->conn->err);
	if (rc) {
	    OCIErrorGet((dvoid *)statement->conn->err, (ub4) 1, (text *) NULL, &errcode, errbuf, (ub4) sizeof(errbuf), OCI_HTYPE_ERROR);
	    luaL_error(L, "name get %s", errbuf);
	}

	rc = OCIAttrGet(bind[i].param, OCI_DTYPE_PARAM, (dvoid *)&(bind[i].data_type), (ub4 *)0, OCI_ATTR_DATA_TYPE, statement->conn->err);
	if (rc) {
	    OCIErrorGet((dvoid *)statement->conn->err, (ub4) 1, (text *) NULL, &errcode, errbuf, (ub4) sizeof(errbuf), OCI_HTYPE_ERROR);
	    luaL_error(L, "datatype get %s", errbuf);
	}

	rc = OCIAttrGet(bind[i].param, OCI_DTYPE_PARAM, (dvoid *)&(bind[i].max_len), 0, OCI_ATTR_DATA_SIZE, statement->conn->err);
	if (rc) {
	    OCIErrorGet((dvoid *)statement->conn->err, (ub4) 1, (text *) NULL, &errcode, errbuf, (ub4) sizeof(errbuf), OCI_HTYPE_ERROR);
	    luaL_error(L, "datasize get %s", errbuf);
	}

	bind[i].data = calloc(bind[i].max_len+1, sizeof(char));
	rc = OCIDefineByPos(statement->stmt, &bind[i].define, statement->conn->err, (ub4)i+1, bind[i].data, bind[i].max_len, SQLT_STR, (dvoid *)&(bind[i].null), (ub2 *)0, (ub2 *)0, (ub4)OCI_DEFAULT);
	if (rc) {
	    OCIErrorGet((dvoid *)statement->conn->err, (ub4) 1, (text *) NULL, &errcode, errbuf, (ub4)sizeof(errbuf), OCI_HTYPE_ERROR);
	    luaL_error(L, "define by pos %s", errbuf);
	}
    }

    statement->metadata = 1;
}
Пример #3
0
oraub8	SqlLob::length()
{
	if(!is_not_null())
		return 0;

	bool done = false;
	oraub8 len;
	while(!done)
	{
		sword res = OCICALL(OCILobGetLength2(_conn._svc_ctx, _conn._env._errh, _loc, &len));

		if( res != OCI_SUCCESS )
		{
			sb4 errorcode;
			sword res2 = OCICALL(OCIErrorGet(_conn._env._errh, 1, NULL, &errorcode, NULL, 0, OCI_HTYPE_ERROR));
			assert(res2 == OCI_SUCCESS);

			if(errorcode == 3127) // ORA-03127: no new operations allowed until the active operation ends
			{
				std::cerr << "ORA-03127: no new operations allowed until the active operation ends" << std::endl;
				MSLEEP(100);
			}
			else
			{
				oci_check_error(__TROTL_HERE__, _conn._env._errh, res);
			}
		}
		else
		{
			done = true;
		}
	}

	return len;
};
Пример #4
0
/*---------------------------------------------------------------------
 * ocierror - Print error status and exit program
 *---------------------------------------------------------------------*/
static void ocierror(oci_t * ocip, char * msg, boolean stop_on_error)
{
  sb4 errcode=0;
  text bufp[4096];
  time_t  tm;
  time(&tm);

  if (ocip->errp)
  {
    OCIErrorGet((dvoid *) ocip->errp, (ub4) 1, (text *) NULL, &errcode,
                bufp, (ub4) 4096, (ub4) OCI_HTYPE_ERROR);
    printf("%s\n%s", msg, bufp);
  }
  else
    puts(msg);

  printf ("\n=== Current time = %s", ctime(&tm));
  printf ("\n");
  if (stop_on_error)
  {
    printf("\n ocierror>> stop_on_error set, exiting...");
    if (ocip->attached)
      detach_session(ocip, TRUE);
    exit(1);
  }
}
Пример #5
0
SqlOpenLob::~SqlOpenLob()
{
	bool done = false;
	while(!done)
	{
		sword res = OCICALL(OCILobClose(
		                            _lob._conn._svc_ctx,
		                            _lob._conn._env._errh,
		                            _lob._loc
		                    ));

		if( res != OCI_SUCCESS )
		{
			sb4 errorcode;
			sword res2 = OCICALL(OCIErrorGet(_lob._conn._env._errh, 1, NULL, &errorcode, NULL, 0, OCI_HTYPE_ERROR));
			assert(res2 == OCI_SUCCESS);

			if(errorcode == 3127) // ORA-03127: no new operations allowed until the active operation ends
			{
				std::cerr << "ORA-03127: no new operations allowed until the active operation ends" << std::endl;
				MSLEEP(100);
			}
			else
			{
				oci_check_error(__TROTL_HERE__, _lob._conn._env._errh, res);
			}
		}
		else
		{
			done = true;
		}
	}
};
Пример #6
0
static int yada_oracle_rollback(yada_t *_yada, int flags)
{
  char errbuf[1024];
  sb4 errcode;


  /* check database connection */
  if(!_yada->_mod->env)
    {
    _yada_set_err(_yada, 0, "database unavailable");
    return(-1);
    }

  if(OCITransRollback(_yada->_mod->ctx, _yada->_mod->err, OCI_DEFAULT)
    != OCI_SUCCESS)
    {
    OCIErrorGet(_yada->_mod->err, 1, NULL, &errcode, errbuf, sizeof(errbuf),
     OCI_HTYPE_ERROR);
    _yada_set_err(_yada, errcode, errbuf);
    _yada->disconnect(_yada);
    return(-1);
    }

  if(_yada->_mod->flags & ORAF_INTRX)
    _yada->_mod->flags ^= ORAF_INTRX;
  return(0);
}
Пример #7
0
/* Handle oci error */
void checkerr(OCIError *errhp, sword status)
{
	text errbuf[512];
	sb4 errcode = 0;

	switch (status)
	{
		case OCI_SUCCESS:
			break;
		case OCI_SUCCESS_WITH_INFO:
			printf("Error - OCI_SUCCESS_WITH_INFO\n");
			break;
		case OCI_NEED_DATA:
			printf("Error - OCI_NEED_DATA\n");
			break;
		case OCI_NO_DATA:
			printf("Error - OCI_NODATA\n");
			break;
		case OCI_ERROR:
			OCIErrorGet((dvoid *)errhp, (ub4) 1, (text *) NULL, &errcode, errbuf, (ub4) sizeof(errbuf), OCI_HTYPE_ERROR);
			printf("Error - %.*s\n", 512, errbuf);
		break;
		case OCI_INVALID_HANDLE:
			printf("Error - OCI_INVALID_HANDLE\n");
			break;
		case OCI_STILL_EXECUTING:
			printf("Error - OCI_STILL_EXECUTE\n");
			break;
		case OCI_CONTINUE:
			printf("Error - OCI_CONTINUE\n");
			break;
		default:
			break;
	}
}
Пример #8
0
char *ltDbError(ltDbConn *pConn){
    ub4 errcode;
    static char msgBuf[512];
    OCIErrorGet(pConn->pErr, (ub4) 1, (text *) NULL, &errcode,
                    msgBuf, (ub4) sizeof(msgBuf), OCI_HTYPE_ERROR);
    return msgBuf;
}
Пример #9
0
/*错误处理*/
unsigned int  ltDbErrorCode(ltDbConn *pConn){
    ub4 errcode;
    text msgBuf[512];
    OCIErrorGet(pConn->pErr, (ub4) 1, (text *) NULL, &errcode,
                    msgBuf, (ub4) sizeof(msgBuf), OCI_HTYPE_ERROR);
    return errcode;
}
Пример #10
0
static void
raise_oracle_error(plruby_context_t *ctx, int is_err, sword status, const char *file, long line)
{
    text errmsg[OCI_ERROR_MAXMSG_SIZE];
    sb4 errcode;

    switch (status) {
    case OCI_ERROR:
    case OCI_SUCCESS_WITH_INFO:
    case OCI_NO_DATA:
        OCIErrorGet(is_err ? ctx->errhp : ctx->envhp, 1, NULL, &errcode, errmsg, sizeof(errmsg),
                    is_err ? OCI_HTYPE_ERROR : OCI_HTYPE_ENV);
        rb_raise(rb_eRuntimeError, "OCI Error(%s:%ld): %s", file, line, errmsg);
        break;
    case OCI_INVALID_HANDLE:
        rb_raise(rb_eRuntimeError, "OCI Error(%s:%ld): Invalid Handle", file, line);
        break;
    case OCI_NEED_DATA:
        rb_raise(rb_eRuntimeError, "OCI Error(%s:%ld): Need Data", file, line);
        break;
    case OCI_STILL_EXECUTING:
        rb_raise(rb_eRuntimeError, "OCI Error(%s:%ld): Still Executing", file, line);
        break;
    case OCI_CONTINUE:
        rb_raise(rb_eRuntimeError, "OCI Error(%s:%ld): Continue", file, line);
        break;
    default:
        rb_raise(rb_eRuntimeError, "OCI error(%s:%ld): Unknown code %d", file, line, status);
    }
}
Пример #11
0
void OCI_ExceptionOCI
(
    OCIError       *p_err,
    OCI_Connection *con,
    OCI_Statement  *stmt,
    boolean         warning
)
{
    OCI_Error *err = OCI_ExceptionGetError();

    if (err)
    {
        int     dbsize = (int) (osizeof(err->str) - (size_t) 1);
        dbtext *dbstr  =  OCI_StringGetOracleString(err->str, &dbsize);

        err->type = (warning ? OCI_ERR_WARNING : OCI_ERR_ORACLE);
        err->con  = con;
        err->stmt = stmt;

        /* get oracle description */

        OCIErrorGet((dvoid *) p_err, (ub4) 1, (OraText *) NULL, &err->sqlcode,
                    (OraText *) dbstr, (ub4) dbsize, (ub4) OCI_HTYPE_ERROR);

        OCI_StringCopyOracleStringToNativeString(dbstr, err->str, dbcharcount(dbsize));
        OCI_StringReleaseOracleString(dbstr);
    }

    OCI_ExceptionRaise(err);
}
Пример #12
0
const char *OracleConnection_getLastError(T C) {
        sb4 errcode;
        switch (C->lastError)
        {
                case OCI_SUCCESS:
                        return "";
                case OCI_SUCCESS_WITH_INFO:
                        return "Error - OCI_SUCCESS_WITH_INFO";
                        break;
                case OCI_NEED_DATA:
                        return "Error - OCI_NEED_DATA";
                        break;
                case OCI_NO_DATA:
                        return "Error - OCI_NODATA";
                        break;
                case OCI_ERROR:
                        (void) OCIErrorGet(C->err, 1, NULL, &errcode, C->erb, (ub4)ERB_SIZE, OCI_HTYPE_ERROR);
                        return C->erb;
                        break;
                case OCI_INVALID_HANDLE:
                        return "Error - OCI_INVALID_HANDLE";
                        break;
                case OCI_STILL_EXECUTING:
                        return "Error - OCI_STILL_EXECUTE";
                        break;
                case OCI_CONTINUE:
                        return "Error - OCI_CONTINUE";
                        break;
                default:
                        break;
        }
        return C->erb;
}
Пример #13
0
/*---------------------------------------------------------------------------
                          PRIVATE FUNCTIONS
  ---------------------------------------------------------------------------*/
static int qxiqtce(
OCIExtProcContext *ctx,
OCIError *errhp,
sword status)
{
  text errbuf[512];
  sb4 errcode = 0;
  int errnum = 29400;                     /* choose some oracle error number */
  int rc = 0;

  switch (status)
  {
  case OCI_SUCCESS:
    rc = 0;
    break;
  case OCI_ERROR:
    (void) OCIErrorGet((dvoid *)errhp, (ub4)1, (text *)NULL, &errcode,
                       errbuf, (ub4)sizeof(errbuf), OCI_HTYPE_ERROR);
    OCIExtProcRaiseExcpWithMsg(ctx, errnum, errbuf, strlen((char *)errbuf));
    rc = 1;
    break;
  default:
    (void) sprintf((char *)errbuf, "Warning - some error\n");
    OCIExtProcRaiseExcpWithMsg(ctx, errnum, errbuf, strlen((char *)errbuf));
    rc = 1;
    break;
  }
  return (rc);
}
Пример #14
0
/*
  call SQLError to get error information and log it
*/
int
logOraError( int level, OCIError *errhp, sword status ) {
    sb4 errcode;
    int errorVal = -1;
    if ( status == OCI_SUCCESS ) {
        return 0;
    }
    switch ( status )  {
    case OCI_SUCCESS_WITH_INFO:
        rodsLog( level, "OCI_SUCCESS_WITH_INFO" );
        OCIErrorGet( ( dvoid * ) errhp, ( ub4 ) 1, ( text * ) NULL, &errcode,
                     oraErrorMsg, ( ub4 ) sizeof( oraErrorMsg ),
                     ( ub4 ) OCI_HTYPE_ERROR );
        rodsLog( level, "Error - %s\n", oraErrorMsg );
        errorVal = 0;
        break;
    case OCI_NEED_DATA:
        rodsLog( level, "OCI_NEED_DATA" );
        break;
    case OCI_NO_DATA:
        rodsLog( level, "OCI_NO_DATA" );
        errorVal = 0;
        break;
    case OCI_ERROR:
        OCIErrorGet( ( dvoid * ) errhp, ( ub4 ) 1, ( text * ) NULL, &errcode,
                     oraErrorMsg, ( ub4 ) sizeof( oraErrorMsg ),
                     ( ub4 ) OCI_HTYPE_ERROR );
        rodsLog( level, "OCI_Error: %s", oraErrorMsg );
        if ( strstr( ( char * )oraErrorMsg, "unique constraint" ) != 0 ) {
            errorVal =  CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME;
        }
        break;
    case OCI_INVALID_HANDLE:
        rodsLog( level, "OCI_INVALID_HANDLE\n" );
        break;
    case OCI_STILL_EXECUTING:
        rodsLog( level, "OCI_STILL_EXECUTING\n" );
        break;
    case OCI_CONTINUE:
        rodsLog( level, "OCI_CONTINUE\n" );
        break;
    default:
        rodsLog( level, "Unknown OCI status - %d", status );
        break;
    }
    return errorVal;
}
Пример #15
0
void CheckErr(OCIError *errhp, int ret) {
	char errbuf[512];
	if (ret == OCI_ERROR) {
		OCIErrorGet((dvoid*)errhp, (ub4)1, (text*)NULL, (sb4*)&ret, (text*)errbuf,
			(ub4)sizeof(errbuf), (ub4)OCI_HTYPE_ERROR);
		errbuf[strlen(errbuf)-1] = 0;
		Log("ERROR: %s", errbuf);
	}
}
Пример #16
0
/** Generic function for handling errors from OCI.

    It will be called only inside CHECKERR and CHECKENV macros.

    Arguments: handle The error or environment handle to check.
    htype: OCI_HTYPE_* constant, usually OCI_HTYPE_ERROR or
    OCI_HTYPE_ENV
    status: status code to check, usually the return value of an OCI
    function.

    Returns OCI_SUCCESS on success, OCI_ERROR otherwise.
*/
static int oci_errors(void* handle, ub4 htype, sword status)
{
	sb4 errcode;
	unsigned char buf[MAX_BUFSIZE];
	
	switch (status) {
	case OCI_SUCCESS:
		return OCI_SUCCESS;
		break;
	case OCI_SUCCESS_WITH_INFO:
		OCIErrorGet(handle, 1, NULL, &errcode, buf, sizeof buf, htype);
		errmsg.LogError(0, NO_ERRCODE, "OCI SUCCESS - With info: %s",
				buf);
                return OCI_SUCCESS_WITH_INFO;
	case OCI_NEED_DATA:
		errmsg.LogError(0, NO_ERRCODE, "OCI NEEDS MORE DATA\n");
		break;
	case OCI_ERROR:
		dbgprintf ("OCI GENERAL ERROR\n");
		if (handle) {
			OCIErrorGet(handle, 1, NULL, &errcode, buf,
				    sizeof buf, htype);
			errmsg.LogError(0, NO_ERRCODE, "Error message: %s", buf);
		} else
			errmsg.LogError(0, NO_ERRCODE, "NULL handle\n"
					 "Unable to extract further "
					 "information");
		break;
	case OCI_INVALID_HANDLE:
		errmsg.LogError(0, NO_ERRCODE, "OCI INVALID HANDLE\n");
		/* In this case we may have to trigger a call to
		 * tryResume(). */
		return RS_RET_SUSPENDED;
		break;
	case OCI_STILL_EXECUTING:
		errmsg.LogError(0, NO_ERRCODE, "Still executing...\n");
		break;
	case OCI_CONTINUE:
		errmsg.LogError(0, NO_ERRCODE, "OCI CONTINUE\n");
		break;
	}
	return OCI_ERROR;
}
Пример #17
0
static void show_error(dvoid *errhp, sword status) {
	if  (status == OCI_ERROR) {
		text buf[256];
		sb4 err = 0;
		(void) OCIErrorGet(errhp, (ub4) 1, (text *) NULL, &err, buf, (ub4) sizeof(buf), OCI_HTYPE_ERROR);
		btlogger_warn( "TxLog OCI error %d: %s", (int) err, buf);
	} else {
		btlogger_warn( "TxLog OCI error: %d", (int) status);
	}
}
Пример #18
0
	void throw_error()
	{
		char errbuf[512];
		sb4 errcode;

		OCIErrorGet(error, 1, 0, &errcode, (text*) errbuf, sizeof(errbuf),
				OCI_HTYPE_ERROR);

		throw std::runtime_error(errbuf);
	}
Пример #19
0
/*
 * Functions
 */
static void o_report_error (const char *where, /* {{{ */
    const char *db_name, const char *query_name,
    const char *what, OCIError *eh)
{
  char buffer[2048];
  sb4 error_code;
  int status;
  unsigned int record_number;

  if (db_name == NULL)
    db_name = "(none)";
  if (query_name == NULL)
    query_name = "(none)";

  /* An operation may cause / return multiple errors. Loop until we have
   * handled all errors available (with a fail-save limit of 16). */
  for (record_number = 1; record_number <= 16; record_number++)
  {
    memset (buffer, 0, sizeof (buffer));
    error_code = -1;

    status = OCIErrorGet (eh, (ub4) record_number,
        /* sqlstate = */ NULL,
        &error_code,
        (text *) &buffer[0],
        (ub4) sizeof (buffer),
        OCI_HTYPE_ERROR);
    buffer[sizeof (buffer) - 1] = 0;

    if (status == OCI_NO_DATA)
      return;

    if (status == OCI_SUCCESS)
    {
      size_t buffer_length;

      buffer_length = strlen (buffer);
      while ((buffer_length > 0) && (buffer[buffer_length - 1] < 32))
      {
        buffer_length--;
        buffer[buffer_length] = 0;
      }

      ERROR ("oracle plugin: %s (db = %s, query = %s): %s failed: %s",
          where, db_name, query_name, what, buffer);
    }
    else
    {
      ERROR ("oracle plugin: %s (db = %s, query = %s): %s failed. "
          "Additionally, OCIErrorGet failed with status %i.",
          where, db_name, query_name, what, status);
      return;
    }
  }
} /* }}} void o_report_error */
Пример #20
0
/* figure out the oracle error code and message corresponding to an Oracle error */
static void get_error(test_req_t *resp, dvoid *errhp, sword status) {
	if  (status == OCI_ERROR) {
		text buf[256];
		sb4 err = 0;
		(void) OCIErrorGet(errhp, (ub4) 1, (text *) NULL, &err, (text *) buf, (ub4) sizeof (buf), OCI_HTYPE_ERROR);

		btlogger_snprintf(resp->data, sizeof (resp->data), "%s", buf);
	} else {
	   	btlogger_snprintf(resp->data, sizeof (resp->data), "OCI error: %d", (int) status);
	}
}
Пример #21
0
OCI_Agent * OCI_API OCI_DequeueListen
(
    OCI_Dequeue *dequeue,
    int          timeout
)
{
    boolean res        = TRUE;
    OCI_Agent *agent   = NULL;
    OCIAQAgent *handle = NULL;

    OCI_CHECK_PTR(OCI_IPC_DEQUEUE, dequeue, NULL);

    /* listen only if OCI_DequeueSetAgentList has been called */

    if (dequeue->agent_list != NULL)
    {
        sword ret;
        sb4 code = OCI_SUCCESS;

        ret =  OCIAQListen(dequeue->typinf->con->cxt, dequeue->typinf->con->err,
                           dequeue->agent_list, (ub4) dequeue->agent_count,
                           (sb4) timeout, &handle, OCI_DEFAULT);

        /* check returned error code */

        if (ret == OCI_ERROR)
        {
            OCIErrorGet((dvoid *) dequeue->typinf->con->err, (ub4) 1,
                        (OraText *) NULL, &code, (OraText *) NULL, (ub4) 0,
                        (ub4) OCI_HTYPE_ERROR);

            /* raise error only if the call has not been timed out */

            if (code != OCI_ERR_AQ_LISTEN_TIMEOUT)
            {
                OCI_ExceptionOCI(dequeue->typinf->con->err, dequeue->typinf->con, NULL, FALSE);

                res = FALSE;
            }
        }

        /* init local agent object */

        if ((res == TRUE) && (ret == OCI_SUCCESS) && (handle != NULL))
        {
            agent = OCI_AgentInit(dequeue->typinf->con, &dequeue->agent, handle, NULL, NULL);
        }
    }

    OCI_RESULT(res);

    return agent;
}
Пример #22
0
/*
 * Reconnect to server (after error)
 */
sword db_oracle_reconnect(ora_con_t* con)
{
	sword status;

	if (con->connected)
		db_oracle_disconnect(con);

	/* timelimited operation, but OCI tcp-network does not support it :( */
	status = OCIServerAttach(con->srvhp, con->errhp, (OraText*)con->uri,
		con->uri_len, 0);
	if (status == OCI_SUCCESS) {
		++con->connected;
		/*
		 * timelimited operation, but OCI has BUG in asynch
		 * implementation of OCISessionBegin :(.
		 *
		 * Next code is 'empiric hack' that work (tested) in v10/v11.
		 */
		status = begin_timelimit(con, 1);
		if (status != OCI_SUCCESS) goto done;
		status = OCISessionBegin(con->svchp, con->errhp, con->authp,
			OCI_CRED_RDBMS, OCI_DEFAULT);
		while (wait_timelimit(con, status)) {
			sword code;

			status = OCIServerVersion(con->svchp, con->errhp, NULL,
				0, OCI_HTYPE_SVCCTX);

			if (   status != OCI_ERROR
			    || OCIErrorGet(con->errhp, 1, NULL, &code, NULL, 0,
				     OCI_HTYPE_ERROR) != OCI_SUCCESS) break;
			switch (code) {
			case 24909:	/* other call in progress */
				status = OCI_STILL_EXECUTING;
				continue;

			case 3127:	/* no new operation until active ends */
				status = OCISessionBegin(con->svchp, con->errhp,
					con->authp, OCI_CRED_RDBMS, OCI_DEFAULT);
			default:
				break;
			}
			break;
		}
		if (done_timelimit(con, status)) goto done;

		if (status == OCI_SUCCESS)
			++con->connected;
	}
done:
	return status;
}
Пример #23
0
static sword remap_status(ora_con_t* con, sword status)
{
    sword code;

    if (   status == OCI_ERROR
            && OCIErrorGet(con->errhp, 1, NULL, &code,
                           NULL, 0, OCI_HTYPE_ERROR) == OCI_SUCCESS
            && (code == 3123 /*|| code == 3127*/))
    {
        status = OCI_STILL_EXECUTING;
    }
    return status;
}
Пример #24
0
void CheckErr(OCIError *errhp, sword status)
{
    sb4 errcode = 0;
    text errbuf[512];

    (void) OCIErrorGet((dvoid *)errhp, (ub4) 1, (text *) NULL, &errcode,
                       errbuf, (ub4) sizeof(errbuf), OCI_HTYPE_ERROR);
    switch (status)
    {
    case OCI_SUCCESS:
        break;
    case OCI_SUCCESS_WITH_INFO:
        (void) printf("Error - OCI_SUCCESS_WITH_INFO\n");
        break;
    case OCI_NEED_DATA:
        (void) printf("Error - OCI_NEED_DATA\n");
        break;
    case OCI_NO_DATA:
        (void) printf("Error - OCI_NODATA\n");
        (void) printf("Make sure you have run the insert statement with the same options as select..\n");
        break;
    case OCI_ERROR:
        (void) OCIErrorGet((dvoid *)errhp, (ub4) 1, (text *) NULL, &errcode,
                           errbuf, (ub4) sizeof(errbuf), OCI_HTYPE_ERROR);
        (void) printf("Error - %.*s\n", 512, errbuf);
        break;
    case OCI_INVALID_HANDLE:
        (void) printf("Error - OCI_INVALID_HANDLE\n");
        break;
    case OCI_STILL_EXECUTING:
        (void) printf("Error - OCI_STILL_EXECUTE\n");
        break;
    case OCI_CONTINUE:
        (void) printf("Error - OCI_CONTINUE\n");
        break;
    default:
        break;
    }
}
Пример #25
0
/*
=begin
--- OCIStmt#execute(svc [, iters [, mode]])
     execute statement at the ((<service context handle|OCISvcCtx>)).

     :svc
        ((<service context handle|OCISvcCtx>))
     :iters
        the number of iterations to execute.

        For select statement, if there are columns which is not defined
        by ((<OCIStmt#defineByPos>)) and this value is positive, it 
        raises exception. If zero, no exception. In any case you must define
        all columns before you call ((<OCIStmt#fetch>)).

        For non-select statement, use positive value.

        Default value is 0 for select statement, 1 for non-select statement.

        note: Current implemantation doesn't support array fetch and batch mode, so
        valid value is 0 or 1.
     :mode
        ((|OCI_DEFAULT|)), ((|OCI_BATCH_ERRORS|)), ((|OCI_COMMIT_ON_SUCCESS|)),
        ((|OCI_DESCRIBE_ONLY|)), ((|OCI_EXACT_FETCH|)), ((|OCI_PARSE_ONLY|)), 
        any combinations of previous values, or ((|OCI_STMT_SCROLLABLE_READONLY|)).
        Default value is ((|OCI_DEFAULT|)).

        ((|OCI_BATCH_ERRORS|)) and ((|OCI_STMT_SCROLLABLE_READONLY|)) are not
        supported by current implementation.

     correspond native OCI function: ((|OCIStmtExecute|))
=end
*/
static VALUE oci8_stmt_execute(int argc, VALUE *argv, VALUE self)
{
  VALUE vsvc;
  VALUE viters;
  VALUE vmode;
  oci8_handle_t *h;
  oci8_handle_t *svch;
  ub4 mode;
  ub4 iters;
  ub2 stmt_type;
  sword rv;

  rb_scan_args(argc, argv, "12", &vsvc, &viters, &vmode);
  Get_Handle(self, h); /* 0 */
  Check_Handle(vsvc, OCISvcCtx, svch); /* 1 */
  if (argc >= 2) {
    iters = NUM2UINT(viters); /* 2 */
  } else {
    rv = OCIAttrGet(h->hp, OCI_HTYPE_STMT, &stmt_type, 0, OCI_ATTR_STMT_TYPE, h->errhp);
    if (rv != OCI_SUCCESS) {
      oci8_raise(h->errhp, rv, h->hp);
    }
    if (stmt_type == OCI_STMT_SELECT) {
      /* for select statement, default value 0. */
      iters = 0;
    } else {
      /* for non-select statement, default value 0. */
      iters = 1;
    }
  }
  Get_Int_With_Default(argc, 3, vmode, mode, OCI_DEFAULT); /* 3 */

  if (iters > 1) {
    rb_raise(rb_eArgError, "current implementation doesn't support array fatch or batch mode");
  }

  rv = OCIStmtExecute(svch->hp, h->hp, h->errhp, iters, 0, NULL, NULL, mode);
  if (rv == OCI_ERROR) {
    sb4 errcode;
    OCIErrorGet(h->errhp, 1, NULL, &errcode, NULL, 0, OCI_HTYPE_ERROR);
    if (errcode == 1000) {
      /* run GC to close unreferred cursors when ORA-01000 (maximum open cursors exceeded). */
      rb_gc();
      rv = OCIStmtExecute(svch->hp, h->hp, h->errhp, iters, 0, NULL, NULL, mode);
    }
  }
  if (IS_OCI_ERROR(rv)) {
    oci8_raise(h->errhp, rv, h->hp);
  }
  return self;
}
Пример #26
0
static void checkerr(sword status,OCIError *myerrhp)
{
    text errbuf[512];
    sb4 errcode;

    switch(status)
    {
    case OCI_SUCCESS:
        break;
    case OCI_SUCCESS_WITH_INFO:
        OCIErrorGet((dvoid *)myerrhp, (ub4)1, (text *)NULL, &errcode,
                    errbuf, (ub4)sizeof(errbuf), (ub4)OCI_HTYPE_ERROR);
        ERROR("Error - OCI_SUCCESS_WITH_INFO\n%s\n", errbuf);
        break;
    case OCI_NEED_DATA:
        ERROR("Error - OCI_NEED_DATA\n");
        break;
    case OCI_NO_DATA:
        ERROR("Error - OCI_NO_DATA\n");
        break;
    case OCI_ERROR:
        OCIErrorGet((dvoid *)myerrhp, (ub4)1, (text *)NULL, &errcode,
                    errbuf, (ub4)sizeof(errbuf), (ub4)OCI_HTYPE_ERROR);
        ERROR("Error - OCI_ERROR\n%s\n",errbuf);
        break;
    case OCI_INVALID_HANDLE:
        ERROR("Error - OCI_INVALID_HANDLE\n");
        break;
    case OCI_STILL_EXECUTING:
        ERROR("Error - OCI_STILL_EXECUTING\n");
        break;
    case OCI_CONTINUE:
        ERROR("Error - OCI_CONTINUE\n");
        break;
    default:
        break;
    }
}
Пример #27
0
static const char	*zbx_oci_error(sword status)
{
	static char	errbuf[512];
	sb4		errcode = 0;

	errbuf[0] = '\0';

	switch (status)
	{
		case OCI_SUCCESS_WITH_INFO:
			OCIErrorGet((dvoid *)oracle.errhp, (ub4)1, (text *)NULL, &errcode,
					(text *)errbuf, (ub4)sizeof(errbuf), OCI_HTYPE_ERROR);
			break;
		case OCI_NEED_DATA:
			zbx_snprintf(errbuf, sizeof(errbuf), "%s", "OCI_NEED_DATA");
			break;
		case OCI_NO_DATA:
			zbx_snprintf(errbuf, sizeof(errbuf), "%s", "OCI_NODATA");
			break;
		case OCI_ERROR:
			OCIErrorGet((dvoid *)oracle.errhp, (ub4)1, (text *)NULL, &errcode,
					(text *)errbuf, (ub4)sizeof(errbuf), OCI_HTYPE_ERROR);
			break;
		case OCI_INVALID_HANDLE:
			zbx_snprintf(errbuf, sizeof(errbuf), "%s", "OCI_INVALID_HANDLE");
			break;
		case OCI_STILL_EXECUTING:
			zbx_snprintf(errbuf, sizeof(errbuf), "%s", "OCI_STILL_EXECUTING");
			break;
		case OCI_CONTINUE:
			zbx_snprintf(errbuf, sizeof(errbuf), "%s", "OCI_CONTINUE");
			break;
	}

	zbx_rtrim(errbuf, ZBX_WHITESPACE);

	return errbuf;
}
Пример #28
0
int OGROCISession::Failed( sword nStatus, const char *pszFunction )

{
    if( pszFunction == NULL )
        pszFunction = "<unnamed>";
    if( nStatus == OCI_ERROR )
    {
        sb4  nErrCode = 0;
        char szErrorMsg[10000];

        szErrorMsg[0] = '\0';
        if( hError != NULL )
        {
            OCIErrorGet( (dvoid *) hError, (ub4) 1, NULL, &nErrCode, 
                         (text *) szErrorMsg, (ub4) sizeof(szErrorMsg), 
                         OCI_HTYPE_ERROR );
        }
        szErrorMsg[sizeof(szErrorMsg)-1] = '\0';

        CPLError( CE_Failure, CPLE_AppDefined, 
                  "%s in %s", szErrorMsg, pszFunction );
        return TRUE;
    }
    else if( nStatus == OCI_NEED_DATA )
    {
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "OCI_NEED_DATA" );
        return TRUE;
    }
    else if( nStatus == OCI_INVALID_HANDLE )
    {
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "OCI_INVALID_HANDLE in %s", pszFunction );
        return TRUE;
    }
    else if( nStatus == OCI_STILL_EXECUTING )
    {
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "OCI_STILL_EXECUTING in %s", pszFunction );
        return TRUE;
    }
    else if( nStatus == OCI_CONTINUE )
    {
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "OCI_CONTINUE in %s", pszFunction );
        return TRUE;
    }
    else
        return FALSE;
}
Пример #29
0
/*
 * checkerr0: This function prints a detail error report.
 *			  Used to "warp" invocation of OCI calls.
 * Parameters:
 *	handle (IN)	- can be either an environment handle or an error handle.
 *				  for OCI calls that take in an OCIError Handle:
 *				  pass in an OCIError Handle
 *
 *				  for OCI calls that don't take an OCIError Handle,
 *                pass in an OCIEnv Handle
 *
 * htype (IN)   - type of handle: OCI_HTYPE_ENV or OCI_HTYPE_ERROR
 *
 * status (IN)  - the status code returned from the OCI call
 *
 * Notes:
 *				  Note that this "exits" on the first
 *                OCI_ERROR/OCI_INVALID_HANDLE.
 *				  CUSTOMIZE ACCORDING TO YOUR ERROR HANDLING REQUIREMNTS
 */
void checkerr0(void *handle, ub4 htype, sword status, const char * function_name, int line_no)
{
    /* a buffer to hold the error message */
    text errbuf[2048];
    gerrcode = 0;
    function_success = SUCCESS;

    switch (status) {
    case OCI_SUCCESS:
#ifdef TRACE
        (void) sprintf_s(gerrbuf, sizeof(gerrbuf), "[%s:%d] Ok - OCI_SUCCESS\n", function_name, line_no);
#endif
        break;
    case OCI_SUCCESS_WITH_INFO:
        (void) sprintf_s(gerrbuf, sizeof(gerrbuf), "[%s:%d] Error - OCI_SUCCESS_WITH_INFO\n", function_name, line_no);
        break;
    case OCI_NEED_DATA:
        (void) sprintf_s(gerrbuf, sizeof(gerrbuf), "[%s:%d] Error - OCI_NEED_DATA\n", function_name, line_no);
        break;
    case OCI_NO_DATA:
        (void) sprintf_s(gerrbuf, sizeof(gerrbuf), "[%s:%d] Error - OCI_NO_DATA\n", function_name, line_no);
        break;
    case OCI_ERROR:
        (void) sprintf_s(gerrbuf, sizeof(gerrbuf), "[%s:%d] Error - OCI_ERROR\n", function_name, line_no);
        if (handle) {
            (void) OCIErrorGet(handle, 1, (text *) NULL, &gerrcode,
                               errbuf, (ub4)sizeof(errbuf), htype);
            (void) sprintf_s(gerrbuf, sizeof(gerrbuf), " - %.*s\n", sizeof(errbuf), errbuf);
	        function_success = CONTINUE_WITH_ERROR;
        } else {
            (void) sprintf_s(gerrbuf, sizeof(gerrbuf), "[%s:%d] NULL Handle\n", function_name, line_no);
            (void) sprintf_s(gerrbuf, sizeof(gerrbuf), "[%s:%d] Unable to extract detailed diagnostic information\n", function_name, line_no);
	        function_success = FAILURE;
        }
        break;
    case OCI_INVALID_HANDLE:
        (void) sprintf_s(gerrbuf, sizeof(gerrbuf), "[%s:%d] Error - OCI_INVALID_HANDLE\n", function_name, line_no);
        break;
    case OCI_STILL_EXECUTING:
        (void) sprintf_s(gerrbuf, sizeof(gerrbuf), "[%s:%d] Error - OCI_STILL_EXECUTING\n", function_name, line_no);
        break;
    case OCI_CONTINUE:
        (void) sprintf_s(gerrbuf, sizeof(gerrbuf), "[%s:%d] Error - OCI_CONTINUE\n", function_name, line_no);
        break;
    default:
        (void) sprintf_s(gerrbuf, sizeof(gerrbuf), "[%s:%d] Unknown - %d\n", function_name, line_no, status);
        break;
    }
}
Пример #30
0
/*
 *  call-seq:
 *     onum.to_char(fmt = nil, nls_params = nil)  -> string
 *
 *  Returns a string containing a representation of self.
 *  <i>fmt</i> and <i>nls_params</i> are same meanings with
 *  <code>TO_CHAR</code> of Oracle function.
 */
static VALUE onum_to_char(int argc, VALUE *argv, VALUE self)
{
    OCIError *errhp = oci8_errhp;
    VALUE fmt;
    VALUE nls_params;
    char buf[512];
    ub4 buf_size = sizeof(buf);
    oratext *fmt_ptr;
    oratext *nls_params_ptr;
    ub4 fmt_len;
    ub4 nls_params_len;
    sword rv;

    rb_scan_args(argc, argv, "02", &fmt /* nil */, &nls_params /* nil */);
    if (NIL_P(fmt)) {
        rv = oranumber_to_str(_NUMBER(self), buf, sizeof(buf));
        if (rv > 0) {
            return rb_usascii_str_new(buf, rv);
        }
        oranumber_dump(_NUMBER(self), buf);
        rb_raise(eOCIException, "Invalid internal number format: %s", buf);
    }
    StringValue(fmt);
    fmt_ptr = RSTRING_ORATEXT(fmt);
    fmt_len = RSTRING_LEN(fmt);
    if (NIL_P(nls_params)) {
        nls_params_ptr = NULL;
        nls_params_len = 0;
    } else {
        StringValue(nls_params);
        nls_params_ptr = RSTRING_ORATEXT(nls_params);
        nls_params_len = RSTRING_LEN(nls_params);
    }
    rv = OCINumberToText(errhp, _NUMBER(self),
                         fmt_ptr, fmt_len, nls_params_ptr, nls_params_len,
                         &buf_size, TO_ORATEXT(buf));
    if (rv == OCI_ERROR) {
        sb4 errcode;
        OCIErrorGet(errhp, 1, NULL, &errcode, NULL, 0, OCI_HTYPE_ERROR);
        if (errcode == 22065) {
            /* OCI-22065: number to text translation for the given format causes overflow */
            if (NIL_P(fmt)) /* implicit conversion */
                return rb_usascii_str_new_cstr("overflow");
        }
        chkerr(rv);
    }
    return rb_usascii_str_new(buf, buf_size);
}