📄 bj_datarecovery.cpp
字号:
cerr << "m_RecordsNum is error! " << endl; return -1; } try { assert(!CORBA::is_nil(bjDR)); //一次取数据过程 for (exeCount=0; exeCount<exeTimes; exeCount++) { rc = bjDR->nGetNextData(m_values); if (rc != -1 ) //返回值有-1、IS_EOF、NOT_FINISH_GETING_RESULT、FINISH_GETING_RESULT四种 { //将数据写入文件 //由于Records类型为sequence类型,我们只重载了iostream,而没有重载fstream //所以,如果想直接用fstream把m_values写进文件,要么重载fstream,要么将Records类型 //转换为char*,也就是用“.in()”方法,只能一个字段一个字段值的输出 nFieldCount = m_values[0].length(); for (i=0; i<m_values->length(); i++) { for (j=0; j<nFieldCount; j++) { //if (m_DXX_TABLE[j]!=1 && strlen(m_values[i][j].in()) < (m_DXX_TABLE[j]-1)) //对于字符串来说m_DXX_TABLE[j]中的值是算入了字符串结束符,需要减去1 if (strlen(m_values[i][j].in()) < (m_DXX_TABLE[j]-1)) //但是对于number类型来说,m_DXX_TABLE[j]的大小就是字符长度,所以,如果 //要维护一致性,需要将m_DXX_TABLE[j]中对应的number字符长度加上1,长度为1的char类型也不例外。 { for (k=0; k<(m_DXX_TABLE[j]-1-strlen(m_values[i][j].in())); k++) m_outfile << " "; m_outfile << m_values[i][j].in(); } //else if (m_DXX_TABLE[j]==1 && strlen(m_values[i][j].in())==0 ) // m_outfile << " "; else m_outfile << m_values[i][j].in(); } m_outfile<< endl; } } else if (m_outfile != NULL) m_outfile.close(); } //代表一次取数据结束了 if (rc == FINISH_GETING_RESULT || rc == IS_EOF) m_outfile.close(); } catch(CORBA::Exception& ex) { if (m_outfile != NULL) m_outfile.close(); Exception602 exx("",-1); throw exx; } break; case 3: fstream tmpR_Data; char pathName[100]; try { assert(!CORBA::is_nil(bjDR)); if (m_nCurrentExpdTimes <= m_nExpdTimes) { rc = bjDR->nGetNextDataTJ(m_nCurrentExpdTimes, m_TableName); if (rc == SUCCESS) { DataRecovery::RECOVERED_DATA R_Data; //R_Data.length(1); //tmpR_Data.open(m_strPathName); CORBA::Long i,length; try { assert(!CORBA::is_nil(bjDR)); sprintf(pathName, "/home/oracle/pdb/DataRecovery/BJ_DataRecovery/tab%d.dmp", m_nCurrentExpdTimes); tmpR_Data.open(pathName, std::ios::out); rc = bjDR->transfer(R_Data); for (i=0; i<R_Data.length(); i++) tmpR_Data << R_Data[i]; } catch(CORBA::Exception& ex) { //最常用的截获异常再抛一个异常的方式 Exception602 exx("",-1); tmpR_Data.close(); throw exx; } tmpR_Data.close(); if (m_nCurrentExpdTimes == m_nExpdTimes) rc = FINISH_GETING_RESULT; else rc = NOT_FINISH_GETING_RESULT; } m_nCurrentExpdTimes ++ ; } else { cerr << "ExpdTimes Error" << endl; rc = -1; } } catch(CORBA::Exception& ex) { if (tmpR_Data != NULL) tmpR_Data.close(); Exception602 exx("",-1); throw exx; } } return rc;} // 返回值:int 0:成功,<0:失败,>0:警告int BJ_DataRecovery::nCancel() throw(Exception602){ int rc; if (m_outfile != NULL) m_outfile.close(); try { assert(!CORBA::is_nil(bjDR)); rc = bjDR->nCancel(); } catch(CORBA::Exception& ex) { Exception602 exx("",-1); throw exx; } return rc;}// 获取出错信息,用户使用const char* BJ_DataRecovery::strErrorMessage(int nErrorId) throw(Exception602){ //UpdateTime(); //NONIDLMETHODENTER("strErrorMessage()",nErrorId,1) CORBA::String_var str; char tmpStr[1000]; switch (nErrorId) { case NOT_ENOUGH_ROOM_FOR_RECOVERYFILE: sprintf(tmpStr,"error:the spaces for recovery file is not enough\nyou need at least %d bytes for recovery!",m_nRealFileSize); str = CORBA::string_dup(tmpStr); break; case ERR_SQSERVER_COMMON: str = CORBA::string_dup("common error:can not know which type error."); break; case ERR_SQSERVER_GET_CONNPOOL: str = CORBA::string_dup("constructor the connectionpool error:parameter error or not enough memory."); break; case ERR_SQSERVER_GET_DIC: str = CORBA::string_dup("constructor the dictionary error:not enough memory."); break; //case ERR_SQSERVER_OPEN_DB: // str = CORBA::string_dup("constructor the dictionary error or constructor the connectionpool error"); // break; case ERR_SQSERVER_NOTSUPPORTED_FUNCTION: str = CORBA::string_dup("the function is not supported now."); break; case ERR_SQSERVER_OPENFILEINDATAQUERY: str = CORBA::string_dup("cannot open file in DataQurey module."); break; case ERR_SQSERVER_GETRESULTLIST : str = CORBA::string_dup("can not get result list from timeoutthread: narrow() error"); break; case ERR_SQSERVER_GET_CONN_FROM_POOL: str = CORBA::string_dup("can not get connection from connectionpool:input parameter error or connection is full"); break; case ERR_SQSERVER_NEW_DQS: str = CORBA::string_dup("can not initialize the DataQuery object:not enough memory"); break; case ERR_SQSERVER_NEW_THREAD: str = CORBA::string_dup("can not initialize thread"); break; case ERR_SQSERVER_MTL_Exception: str = CORBA::string_dup("MTL thread exception"); break; case ERR_SQSERVER_GET_DOMAIN: str = CORBA::string_dup("get domain from dictionary error"); break; case ERR_SQSERVER_DOMAIN_INFO: str = CORBA::string_dup("get domain from dictionary error"); break; case ERR_SQSERVER_GET_DISNODE: str = CORBA::string_dup("get distribute node from dictionary error"); break; case ERR_SQSERVER_GET_DIS_TYPE: str = CORBA::string_dup("get distribute type from dictionary error"); break; case ERR_SQSERVER_LOAD_DIC_TABLE: str = CORBA::string_dup("read dictionary table from db error"); break; case ERR_SQSERVER_DOMAIN_DISMATCH: str = CORBA::string_dup("two or more table in a statement that is not belong to the same domain"); break; case ERR_SQSERVER_NOT_ENOUGH_MEMORY: str = CORBA::string_dup("not enough memory"); break; case ERR_SQSERVER_NO_AVAILABLE_DB: str = CORBA::string_dup("not available connection to Database"); break; case ERR_SQSERVER_OCI: str = CORBA::string_dup("OCI common error"); break; case NODATA: str = CORBA::string_dup("can not get more data from DB"); break; case IS_EOF: str = CORBA::string_dup("the cursor is at the end of record list"); break; case IS_BOF: str = CORBA::string_dup("the cursor is at the top of record list"); break; case ERR_SQSERVER_OCIHandleAlloc: str = CORBA::string_dup("OCIHandleAlloc statement execute error"); break; case ERR_SQSERVER_OCIStmtPrepare: str = CORBA::string_dup("OCIStmtPrepare statement execute error"); break; case ERR_SQSERVER_OCIStmtExecute: //str = CORBA::string_dup(m_OCIErrMsg); str = CORBA::string_dup("OCIStmtExecute statement execute error"); break; case ERR_SQSERVER_SYNTAX: str = CORBA::string_dup("query statement\'s syntax error"); break; case ERR_SQSERVER_DDL: str = CORBA::string_dup("DDL statement\'s syntax error"); break; case ERR_SQSERVER_CORBA: str = CORBA::string_dup("CORBA error"); break; case ERR_SQSERVER_NOT_SUPPORT_SQL: str = CORBA::string_dup("This is a not support statement"); break; case ERR_SQSERVER_MIN_MAX: str = CORBA::string_dup("Error in min and max function,could not comare value"); break; case ERR_SQSERVER_GET_VALUE_BY_INDEX: str = CORBA::string_dup("can not get value by the index which is user given"); break; case ERR_SQSERVER_CONFLICT: str = CORBA::string_dup("this SQL has some field conflict !"); break; case ERR_SQSERVER_FIELD_NAME: str = CORBA::string_dup("no field in the table !"); break; case ERR_SQSERVER_INVALID_RESULT: str = CORBA::string_dup("The IResult object is invalid"); break; case ERR_SQSERVER_TABLE_NOT_EXIST: str = CORBA::string_dup("this table dose not exist"); break; case ERR_SQSERVER_FIELD_NUM: str = CORBA::string_dup("the field index beyond range"); break; case ERR_SQSERVER_PARAM: str = CORBA::string_dup("dictionary initialized error in table name or field name or error db connect param."); break; case ERR_SQSERVER_NOT_EXIST: str = CORBA::string_dup("domain or table does not exist in data dictionary"); break; default: str = CORBA::string_dup("no such error code"); break; } //NONIDLMETHODLEAVE("strErrorMessage()") return CORBA::string_dup(str);}int BJ_DataRecovery::transfer() throw(Exception602){ DataRecovery::RECOVERED_DATA R_Data; //R_Data.length(1); int rc; fstream tmpR_Data; //tmpR_Data.open(m_strPathName); CORBA::Long i,length; try { assert(!CORBA::is_nil(bjDR)); tmpR_Data.open("/root/pdb/BJ_DataRecovery/tab.dmp", std::ios::out); //while () //{ rc = bjDR->transfer(R_Data); for (i=0; i<R_Data.length(); i++) tmpR_Data << R_Data[i]; //} } catch(CORBA::Exception& ex) { //最常用的截获异常再抛一个异常的方式 Exception602 exx("",-1); tmpR_Data.close(); throw exx; } tmpR_Data.close(); return rc;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -