OciDBI.cpp
来源:互联网 发布:sql delete select 编辑:程序博客网 时间:2024/06/04 23:22
#include "OciDBI.h"using namespace ocidbi;//test#include <iostream>#include <stdio.h>using namespace std;ocidbi::COciDBI::COciDBI(void){m_struser="";m_strpw="";m_strsid="";m_env = NULL;m_conn = NULL;m_pStm = NULL;}ocidbi::COciDBI::~COciDBI(void){if(m_conn)m_env->terminateConnection(m_conn);if(m_env)Environment::terminateEnvironment(m_env);}////////////////////////////////////////////////////////登录数据???//////////////////////////////////////////////////////bool ocidbi::COciDBI::LoginDB(const char *user,const char *pw,const char *sid){if(user == NULL || sid == NULL){m_strerr = "输入的用户、SID为空,请确认再链接!\n";return false;}try{m_env = Environment::createEnvironment();if (!m_env){m_strerr = "createEnvironment 初始化失???\n";return false;}m_conn =m_env->createConnection(user, pw , sid);if(!m_conn){if(m_env){Environment::terminateEnvironment(m_env);m_env = NULL;}m_strerr = "连接oracle服务端失???\n";return false;}}catch(SQLException ex){char chError[1024]={0};sprintf(chError,"Error Code:%d,Error Msg:%s",ex.getErrorCode(),ex.what());m_strerr = chError;if(m_conn){m_env->terminateConnection(m_conn);m_conn= NULL;}if(m_env){Environment::terminateEnvironment(m_env);m_env = NULL;}return false;}//记录用户、密码和SIDm_struser = user;m_strpw=pw;m_strsid=sid;return true;}///////////////////////////////////////////////////////////////执行有返回结果的查询//////////////////////////////////////////////////////////ResultSet *ocidbi::COciDBI::OpenQuery(const char *msql){if(msql==NULL){m_strerr="SQL语句为空!\n";return NULL;}try{m_pStm = m_conn->createStatement();//m_pStm->setPrefetchRowCount(1000);//m_pStm->setPrefetchMemorySize(1000000);//ResultSet *pRsTask = m_pStm->execute(msql);ResultSet *pRsTask = m_pStm->executeQuery(msql);return pRsTask;}catch(SQLException ex) {char chError[1024]={0};sprintf(chError,"Error Code:%d,Error Msg:%s",ex.getErrorCode(),ex.what());m_strerr = chError;}return NULL;}int64_t ocidbi::COciDBI::GetQueryNumber( const char *msql ){int64_t nSeq = -1;Statement * pstm = m_conn->createStatement(); ResultSet *pRsTask = (pstm)->executeQuery(msql);if(pRsTask->next()){nSeq = pRsTask->getInt(1);}pstm->closeResultSet(pRsTask);m_conn->terminateStatement(pstm);return nSeq;}ResultSet *ocidbi::COciDBI::OpenQuery2(Statement** pstm, const char *msql){ if(msql==NULL){ m_strerr="SQL语?<8f>?为空!\n"; return NULL; } try{ *pstm = m_conn->createStatement(); ResultSet *pRsTask = (*pstm)->executeQuery(msql); return pRsTask; } catch(SQLException ex) { char chError[1024]={0}; sprintf(chError,"Error Code:%d,Error Msg:%s",ex.getErrorCode(),ex.what()); m_strerr = chError; } return NULL;}///////////////////////////////////////////////////////////关闭有返回结果的ResultSet指针///////////////////////////////////////////////////////bool ocidbi::COciDBI::CloseRecordSet(ResultSet *pRsTask){try{m_pStm->closeResultSet(pRsTask);m_conn->terminateStatement(m_pStm);}catch(SQLException ex) {char chError[1024]={0};sprintf(chError,"Error Code:%d,Error Msg:%s",ex.getErrorCode(),ex.what());m_strerr = chError;return false;}return true;}////////////////////////////////////////////////////////////////执行无返回结果的操作///////////////////////////////////////////////////////////bool ocidbi::COciDBI::Excute(const char *msql){try{Statement *pStResultTable = m_conn->createStatement();pStResultTable->execute(msql);m_conn->terminateStatement(pStResultTable);m_conn->commit();}catch(SQLException ex) {char chError[1024]={0};sprintf(chError,"Error Code:%d,Error Msg:%s",ex.getErrorCode(),ex.what());m_strerr = chError;return false;}return true;}string ocidbi::COciDBI::fn_GetErrMsg(){return m_strerr;}///////////////////////////////////////////////////关闭数据库连接,释放资源///////////////////////////////////////////////bool ocidbi::COciDBI::DisConnectDB(){try{m_env->terminateConnection(m_conn);m_conn = NULL;Environment::terminateEnvironment(m_env);m_env = NULL;}catch(SQLException ex) {char chError[1024]={0};sprintf(chError,"Error Code:%d,Error Msg:%s",ex.getErrorCode(),ex.what());m_strerr = chError;return false;}return true;}bool ocidbi::COciBTDBI::AddBtUserVersion(ClientVersion & version){bool nRet = true;try{char szsql[512]={0};sprintf(szsql,"insert into test(id,version) values(%d,'%s')",version.VersionID,version.strVersion.c_str());Excute(szsql);}catch(SQLException ex){char chError[1024]={0};sprintf(chError,"Error Code:%d,Error Msg:%s",ex.getErrorCode(),ex.what());m_strerr = chError;nRet = false;}return nRet;}//bool ocidbi::COciBTDBI::InitBtUserVersion(){//int blRet = true;//try{//string sqlQuery = "SELECT VersionID ,Description from DicVersion";//Statement *stmt = m_conn->createStatement (sqlQuery);//ResultSet *rset = stmt->executeQuery ();//while (rset->next ()){// uint32 VersionID = rset->getInt(1);// string strVersion = rset->getString(2);// printf("%d %s \n",VersionID,strVersion.c_str());//}// stmt->closeResultSet (rset);// m_conn->terminateStatement (stmt);//}//catch(SQLException ex){//char chError[1024]={0};//sprintf(chError,"Error Code:%d,Error Msg:%s",ex.getErrorCode(),ex.what());//m_strerr = chError;//blRet =false;//}//return blRet;//}bool ocidbi::COciBTDBI::InitBtUserVersion(){int blRet = true;try{string sqlQuery = "SELECT id1 from testaaa";Statement *stmt = m_conn->createStatement (sqlQuery);ResultSet *rset = stmt->executeQuery ();while (rset->next ()){uint64 number1 = rset->getInt(1);/*uint32 VersionID = rset->getInt(1);string strVersion = rset->getString(2);*/printf("%llu\n",number1);}stmt->closeResultSet (rset);m_conn->terminateStatement (stmt);}catch(SQLException ex){char chError[1024]={0};sprintf(chError,"Error Code:%d,Error Msg:%s",ex.getErrorCode(),ex.what());m_strerr = chError;blRet =false;}return blRet;}bool ocidbi::COciBTDBI::AddBtUserVersion(string strnumber){bool nRet = true;try{char szsql[512]={0};sprintf(szsql,"insert into testaaa(id1) values('%s')",strnumber.c_str());Excute(szsql);}catch(SQLException ex){char chError[1024]={0};sprintf(chError,"Error Code:%d,Error Msg:%s",ex.getErrorCode(),ex.what());m_strerr = chError;nRet = false;}return nRet;}
0 0
- OciDBI.cpp
- cpp
- CPP
- CPP
- cpp
- cpp
- CPP
- CPP
- ClientSockThread.cpp&&ClientUrlThread.cpp
- cpp调用其他cpp
- ex34a.cpp&&ex34aDoc.cpp&&ex34aView.cpp
- MainFrm.cpp&&ServerThread.cpp&&SheetConfig.cpp
- CPP thread
- cpp->html
- CFaderWnd.cpp
- PasswordReminder.cpp
- object.cpp
- CmdTarget.cpp
- 黑马程序-常见异常对象
- 苹果产品判断
- Intent中的四个重要属性——Action、Data、Category、Extras
- 全志A20[android教程]-红外遥控器调试
- samba的安装(tar.gz方式)
- OciDBI.cpp
- ISO9000年检记录_2014年
- Depth Extraction from Video Using Non-parametric Sampling 简介
- 我的android(第十三天)
- win7 x64环境下 python3.2 nltk3.0及相关工具包的安装
- 1071. Speech Patterns
- 队列的入列和出列
- Activity的四种launchMode
- HDU 1506 Largest Rectangle in a Histogram(dp)