设为首页 加入收藏

TOP

OCI : do NOT debug on TWO different wind(二)
2014-11-23 22:25:23 来源: 作者: 【 】 浏览:10
Tags:OCI NOT debug TWO different wind
reak;
case OCI_ERROR:
_msg = "(OCI_ERROR) - " + _msg;
break;
case OCI_INVALID_HANDLE:
_msg = "(OCI_INVALID_HANDLE) - " + _msg;
break;
case OCI_STILL_EXECUTING:
_msg = "(OCI_STILL_EXECUTE) - " + _msg;
break;
case OCI_CONTINUE:
_msg = "(OCI_CONTINUE) - " + _msg;
break;
default:
_msg = "(UNKNOWN) - " + _msg;
}
}

void Exception::getError(int code, OCIError *err)
{
getError(code);
//if(code == OCI_ERROR)
{
char buf[512];
OCIErrorGet((void*)err, 1, NULL, &code, (OraText*)buf, sizeof(buf), OCI_HTYPE_ERROR);
_msg += "::";
_msg += buf;
}
}

void Exception::show(std::ostream &os) const
{
os << "[" << _code << "]" << _msg;
}

/**/////

Environment::Environment(unsigned int mode)
: _env(NULL)
, _err(NULL)
{
makeEnvironment(mode);
}

Environment::~Environment()
{
if(_err != NULL)
{
OCIHandleFree((void*)_err, OCI_HTYPE_ERROR);
_err = NULL;
}
if(_env != NULL)
{
OCIHandleFree((void*)_env, OCI_HTYPE_ENV);
_env = NULL;
}
}

void Environment::makeEnvironment(unsigned int mode)
{
int ret = OCIEnvCreate(&_env, mode, NULL, NULL, NULL, NULL, 0, NULL);
if(ret != OCI_SUCCESS || _env == NULL)
{
throw Exception(ret, "create Environment failed.");
}

ret = OCIHandleAlloc((const void*)_env, (void**)&_err, OCI_HTYPE_ERROR, 0, NULL);
if(ret != OCI_SUCCESS || _env == NULL)
{
throw Exception(ret, _err, "create Error failed.");
}
}

Connection* Environment::makeConnection(const std::string &user, const std::string &passwd, const std::string &server)
{
Connection *conn = new Connection(this);

int ret = OCIHandleAlloc((const void*)_env, (void**)&(conn->_srv), OCI_HTYPE_SERVER, 0, NULL);
if((ret != OCI_SUCCESS && ret != OCI_SUCCESS_WITH_INFO) || conn->_srv == NULL)
{
throw Exception(ret, "create Server failed.");
}

ret = OCIHandleAlloc((const void*)_env, (void**)&(conn->_svc), OCI_HTYPE_SVCCTX, 0, NULL);
if(ret != OCI_SUCCESS || conn->_svc == NULL)
{
throw Exception(ret, "create ScvCtx failed.");
}

ret = OCIServerAttach(conn->_srv, _err, (const OraText*)server.c_str(), server.size(), 0);
if(ret != OCI_SUCCESS)
{
throw Exception(ret, _err, "attach Server failed.");
}

ret = OCIAttrSet((void*)conn->_svc, OCI_HTYPE_SVCCTX, (void*)conn->_srv, 0, OCI_ATTR_SERVER, _err);
if(ret != OCI_SUCCESS)
{
throw Exception(ret, _err, "set SVCCTX attrib failed.");
}

ret = OCIHandleAlloc((const void*)_env, (void**)&conn->_auth, OCI_HTYPE_SESSION, 0, NULL);
if(ret != OCI_SUCCESS || conn->_auth == NULL)
{
throw Exception(ret, "create Auth Session failed.");
}

ret = OCIAttrSet((void*)conn->_auth, OCI_HTYPE_SESSION, (void*)user.c_str(), user.size(), OCI_ATTR_USERNAME, _err);
if(ret != OCI_SUCCESS)
{
throw Exception(ret, _err, "set Username attrib failed.");
}

ret = OCIAttrSet((void*)conn->_auth, OCI_HTYPE_SESSION, (void*)passwd.c_str(), passwd.size(), OCI_ATTR_PASSWORD, _err);
if(ret != OCI_SUCCESS)
{
throw Exception(ret, _err, "set Password attrib failed.");
}

ret = OCISessionBegin(conn->_svc, _err, conn->_auth, OCI_CRED_RDBMS, OCI_DEFAULT);
if(ret != OCI_SUCCESS)
{
throw Exception(ret, _err, "Start session failed.

首页 上一页 1 2 3 4 下一页 尾页 2/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇介绍python下wmi模块之二:得到本.. 下一篇判断一个点是否在指定三角形内(1..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: