设为首页 加入收藏

TOP

OCI : do NOT debug on TWO different wind(四)
2014-11-23 22:25:23 来源: 作者: 【 】 浏览:13
Tags:OCI NOT debug TWO different wind
");
}

OCIAttrSet((void*)conn->_svc, OCI_HTYPE_SVCCTX, (void*)conn->_auth, 0, OCI_ATTR_SESSION, _err);

return conn;
}

void Environment::destroyConnection(ocipp::Connection *conn)
{
if(conn == NULL)
return;

OCISessionEnd(conn->_svc, _err, conn->_auth, OCI_DEFAULT);
OCIServerDetach(conn->_srv, _err, 0);

OCIHandleFree((void*)conn->_auth, OCI_HTYPE_SESSION);
OCIHandleFree((void*)conn->_svc, OCI_HTYPE_SVCCTX);
OCIHandleFree((void*)conn->_srv, OCI_HTYPE_SERVER);

delete conn, conn = NULL;
}

/**/////
Connection::Connection(ocipp::Environment *env)
: _env(env)
, _srv(NULL)
, _svc(NULL)
, _auth(NULL)
{
}

Statement* Connection::makeStatement(const std::string &sql)
{
Statement *stmt = new Statement(this);

int ret = OCIHandleAlloc((const void*)_env->getEnv(), (void**)&(stmt->_stmt), OCI_HTYPE_STMT, 0, NULL);
if(ret != OCI_SUCCESS || stmt->_stmt == NULL)
{
throw Exception(ret, "create Stmt fail.");
}

ret = OCIStmtPrepare(stmt->_stmt, _env->getError(), (const OraText*)sql.c_str(), sql.size(), OCI_NTV_SYNTAX, OCI_DEFAULT);
if(ret != OCI_SUCCESS)
{
throw Exception(ret, _env->getError(), "prepare Stmt failed.");
}

return stmt;
}

void Connection::destroyStatement(ocipp::Statement *stmt)
{
stmt->freeDefVector();
OCIHandleFree(stmt->_stmt, OCI_HTYPE_STMT);
delete stmt, stmt = NULL;
}

/**/////
Statement::Statement(ocipp::Connection *conn)
: _conn(conn)
, _stmt(NULL)
{
}

int Statement::bindString(unsigned int pos, const std::string &val)
{
OCIBind* bd = NULL;
int ret = OCIBindByPos(_stmt, &bd, _conn->getEnvironment()->getError(), pos, (void*)val.c_str(), val.size() + 1/**//* very dangerous */, SQLT_STR, NULL, NULL, NULL, 0, NULL, OCI_DEFAULT);
if(ret != OCI_SUCCESS)
{
throw Exception(ret, _conn->getEnvironment()->getError(), "bind String failed.");
}

return 0;
}

int Statement::defineString(unsigned int pos, std::string& val)
{
TDefData data(val);
OCIDefine* def = NULL;
int ret = OCIDefineByPos(_stmt, &def, _conn->getEnvironment()->getError(), pos, (void*)data.buf, BUF_SIZE, SQLT_STR, NULL, NULL, NULL, OCI_DEFAULT);
if(ret != OCI_SUCCESS)
{
throw Exception(ret, _conn->getEnvironment()->getError(), "define String failed.");
}
_vctDef.push_back(data);

return 0;
}

int Statement::execute()
{
unsigned short type = 0;
int ret = OCIAttrGet((const void*)_stmt, OCI_HTYPE_STMT, (void*)&type, 0, OCI_ATTR_STMT_TYPE, _conn->getEnvironment()->getError());
if(ret != OCI_SUCCESS)
{
throw Exception(ret, _conn->getEnvironment()->getError(), "get Stmt type failed.");
}

ret = OCIStmtExecute(_conn->getSvc(), _stmt, _conn->getEnvironment()->getError(), (type != OCI_STMT_SELECT 1 : 0), 0, NULL, NULL, OCI_COMMIT_ON_SUCCESS/**//*OCI_DEFAULT*/);
if(ret != OCI_SUCCESS)
{
throw Exception(ret, _conn->getEnvironment()->getError(), "execute Stmt failed.");
}

//unsigned int rc = 0;
//ret = OCIAttrGet((const void*)_stmt, OCI_HTYPE_STMT, &rc, (ub4*)sizeof(rc), OCI_ATTR_ROW_COUNT, _conn->getEnvironment()->getError());
// if(ret != OCI_SUCCESS)
// {
// throw Exception(ret, _conn->getEnvironment()->getError(), "get Stmt row_count failed.");
// }
return 0;
}

int Statement::getNex

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

评论

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