bool Test_NetCard::ReadEthinfoTable(std::map<std::string,int>& mapEthBaseInfo) { C_Para *ptrPara = C_Para::GetInstance(); CppMySQL3DB mysql; if(mysql.open(ptrPara->m_strDBServiceIP.c_str(),ptrPara->m_strDBUserName.c_str(), ptrPara->m_strDBPWD.c_str(),ptrPara->m_strDBName.c_str()) == -1) { LOG(0,"mysql open failed!\n"); return false; } // 读取ethinfo ,初始化网卡信息 int nResult; char strSQL[256]; snprintf(strSQL,256,"select * from eth_set where position=%d",ptrPara->IsMain() ? 0:1); CppMySQLQuery query = mysql.querySQL(strSQL,nResult); int nRows = 0 ; if((nRows = query.numRow()) == 0) { LOG(0,"CDataManager Initial failed,ethinfo talbe no rows!\n"); return false; } query.seekRow(0); for(int i = 0 ;i < nRows ; i++) { std::string strName = query.getStringField("eth_name");//"eth" int nType = atoi(query.getStringField("type")); mapEthBaseInfo[strName] = nType; query.nextRow(); } return true; }
int ReadTmsDBData4Int( const std::string& sFieldName , int& retValue ) { int iResult(0); std::string strError; CppMySQL3DB mySql; iResult = mySql.openTMS(); if(iResult != 0) { //strError = "打开数据库错误。"; strError = "Open DataBase Error."; printf( "Error:%s\n" , strError.c_str() ); return iResult; } char tmp[DATALEN]=""; memset(tmp,0,DATALEN); sprintf( tmp , "select * from system_config where conf_item = '%s'" , sFieldName.c_str() ); CppMySQLQuery recordset = mySql.querySQL(tmp,iResult); if(iResult != 0) { mySql.close(); //strError = "查询数据库错误"; strError = "Query DataBase Error."; printf( "Error:%s\n" , strError.c_str() ); return iResult; } recordset.seekRow(0); if(recordset.numRow() != 0) { std::string strVal = recordset.getStringField("conf_val"); if ( strVal.length() == 0 ) { //strError = "查询数据为NULL"; strError = "Query Data Is NULL."; printf( "Error:%s\n" , strError.c_str() ); iResult = -1; } else { retValue = atoi(strVal.c_str()); } } else { //strError = "查询数据不存在"; strError = "Query Data Not Exist."; printf( "Error:%s\n" , strError.c_str() ); mySql.close(); iResult = -1; } return iResult; }
bool Auth::checkPass() { CppMySQL3DB db; String logContent; int iRet = db.open(dbServerIP.c_str(), dbUserName.c_str(), dbUserPass.c_str(), "cloud"); if ( iRet != 0 ) { logContent = "open mysql db failed"; log.write(logContent, Log::ERROR); return false; } CppMySQLQuery query ; String sql = "select id,type from User where user='******'"; sql += " and passwd='" + userPass + "'"; try { query = db.querySQL( sql.c_str() ); } catch(const char* sErr) { logContent = "execute " + sql + " failed:" + sErr; log.write( logContent, Log::ERROR); db.close(); return false; } int rowCnt = query.numRow(); if( rowCnt != 1 ) { char buf[10]; logContent = "execute " + sql + ",the result row count is not 1 " + " ,we desire 1 row."; log.write( logContent, Log::ERROR); db.close(); return false; } userID = query.getStringField("id"); userType = query.getIntField("type"); db.close(); return true; }
bool Dispatch::getVMRamSize() { CppMySQL3DB db; String logContent; int iRet = db.open(dbServerIP.c_str(), dbUserName.c_str(), dbUserPass.c_str(), "cloud"); if ( iRet != 0 ) { logContent = "open mysql db failed"; log.write(logContent, Log::ERROR); return false; } CppMySQLQuery query ; String sql = "select ram from VMDetail where id=" + sVMID; try { query = db.querySQL( sql.c_str() ); } catch(const char* sErr) { logContent = "execute " + sql + " failed:" + sErr; log.write( logContent, Log::ERROR); return false; } int rowCnt = query.numRow(); iRamSize = 0; if( rowCnt != 1 ) { char buf[10]; logContent = "execute " + sql + ",the result row count is not 1 " + " ,we desire 1 row."; log.write( logContent, Log::ERROR); return true; } iRamSize = query.getIntField("ram"); return true; }
bool Dispatch::findFirstCapableNC() { CppMySQL3DB db; String logContent; int iRet = db.open(dbServerIP.c_str(), dbUserName.c_str(), dbUserPass.c_str(), "cloud"); if ( iRet != 0 ) { logContent = "open mysql db failed"; log.write(logContent, Log::ERROR); return false; } CppMySQLQuery query ; String sql = "select ip,ram,cpu from onlineNC"; try { query = db.querySQL( sql.c_str() ); } catch(const char* sErr) { logContent = "execute " + sql + " failed:" + sErr; log.write( logContent, Log::ERROR); return false; } String ip; int iRam; CppMySQLQuery query2 ; int iUsedRam; int iCpu; double dUpTime; while( !query.eof() ) { ip = query.getStringField( "ip" ); iRam = query.getIntField( "ram" ); iCpu = query.getIntField( "cpu" ); sql = "select ram,uptime from PerfData where ip='" + ip + "' order by time desc limit 0,1"; try { query2 = db.querySQL( sql.c_str() ); } catch(const char* sErr) { logContent = "execute " + sql + " failed:" + sErr; log.write( logContent, Log::ERROR); query.nextRow(); continue; } iUsedRam = query2.getIntField( "ram" ); dUpTime = query2.getFloatField("uptime"); if( ( (iRam - iUsedRam) > iRamSize ) && dUpTime < iCpu * 3 ) { capableNCIP = ip; return true; } query.nextRow(); } return true; }
bool Auth::getPermissionData() { CppMySQL3DB db; String logContent; int iRet = db.open(dbServerIP.c_str(), dbUserName.c_str(), dbUserPass.c_str(), "cloud"); if ( iRet != 0 ) { logContent = "open mysql db failed"; log.write(logContent, Log::ERROR); return false; } CppMySQLQuery query ; CppMySQLQuery query2 ; String sql = "select id from VMDetail where userid=" + userID; try { query = db.querySQL( sql.c_str() ); } catch(const char* sErr) { logContent = "execute " + sql + " failed:" + sErr; log.write( logContent, Log::ERROR); return false; } permissionData = ""; String tmp; String vmID; String diskName; while( !query.eof() ) { vmID = query.getStringField( "id" ); permissionData += vmID + "|0&"; sql = "select DiskName from VDiskDetail where vmid=" + vmID; try { query2 = db.querySQL( sql.c_str() ); } catch(const char* sErr) { logContent = "execute " + sql + " failed:" + sErr; log.write( logContent, Log::ERROR); query.nextRow(); continue; } while( !query2.eof() ) { diskName = query2.getStringField( "DiskName" ); permissionData += diskName + "|1&"; query2.nextRow(); } query.nextRow(); } int iSize = permissionData.size(); if( iSize > 0 ) permissionData[iSize-1]='\0'; return true; }